The following sections describe the tasks you need to complete to set up a CI/CD process for a Python project with Google Cloud Build, the ActiveState Platform, and GitHub.
Before you begin:
state authcommand, in order to run the command to retrieve the API key, and to access your
private.keyfile if you are using secrets.
The State Tool will use the following environment variables if they are defined:
You can obtain an API key by opening a command prompt and running the following State Tool command:
state export new-api-key APIKeyForCI
Note that this key is not stored by ActiveState. Please store the value for later use as you cannot retrieve it again. XYZjMmMwYTgtZWRkOS00ZGRiLThmXYZtNDM4NjlhNzE0MTI0IkNlUnZpQmlQXYZYXYZ
In this example, you would copy the token value on the second line to use as the ACTIVESTATE_API_KEY environment variable in your CI/CD application.
You can find the private key value at
The configdir varies per platform, but in most cases will be at one of:
The private key environment variable expects the contents of the
private.key file, not the filepath.
You need to ensure that you have the required API services enabled for your Google Cloud account, add billing information for your account if it is currently a free account, and create or choose a Google Cloud project to use for your Google Cloud Build.
You need to enable Secret Manager to store your ActiveState Platform API Key, and private key if you plan to use State Tool secrets.
<project_id>@cloudbuild.gserviceaccount.com, and add the Secret Manager Secret Accessor permission for the account. The required project ID is displayed on the secret details page.
ACTIVESTATE_PRIVATE_KEY. You can either click the Browse button and upload the file, or copy and paste the entire contents of the file into the Secret Value text box.
IMPORTANT: The ACTIVESTATE_API_KEY is used to authenticate the State Tool automatically whenever required by the CI/CD build steps.
You need to enable Cloud Build before you can start using it.
You can use either the Dashboard or the State Tool to create a new project and add the language, platforms, and packages your project requires. Set up your project by:
After you create an ActiveState project, complete the following steps to activate your project and add the configuration file to your code repository, so that the CI/CD has access to it.
state activate <owner/project_name>. For example:
state activate acmetech/python-3-6-6.
activestate.yamlconfiguration file to the root directory of your code repository.
activestate.yamlto add any scripts, variables, or secrets you want CI/CD to run or have access to. For more information on these options, see Getting started.
activestate.yamlto the repository and check in your changes.
You need to deploy the State Cloud Builder in order to make it available to the project. It creates a Docker container configured with the State Tool that is used by Google Cloud Build.
git clone https://github.com/ActiveState/cloud-builders-community.git
gcloud builds submit . --config=cloudbuild.yaml
cloudbuild.yamlin the root directory of your GitHub repository. This file lists the commands for the build steps to run each time the Cloud Build trigger runs.
cloudbuild.yamlfile and then add
cloudbuild.yamlto your repository and push your changes to GitHub.
For example, this configuration file authenticates the State Tool, deploys the State Tool, and runs the pytest tests defined for the project. The first step identifies the ActiveState Platform project to deploy for use by Google Cloud Build. The third and subsequent steps will be specific to your project.
steps: - name: gcr.io/$PROJECT_ID/state args: ['state', 'deploy', 'ActiveState/ActivePython-3.6', '--path', '/workspace/.state'] - name: gcr.io/$PROJECT_ID/state args: ['pytest']
If you have successfully configured your ActiveState Platform project, GitHub repository, and Google Cloud Build, you will see a job start and complete successfully each time new code changes are pushed to the repository.