Continuous distribution and integration is the process of automatically running tests and building when source changes are pressed. You can set up the Google Cloud Platform (GCP) to run automated Docker buildings when you make updates to your container and deploy to Cloud Run or the Google Kubernetes Engine (GKE).
Overall, the configuration for this is quite simple ̵1; Dockerfiles already handles most of the build configuration, so all that is required of you is to link some services together and configure Cloud Build to distribute updates to Cloud Run or GKE.
Create a cloud source repository
Cloud Build retrieves code from Cloud Source, Google’s own managed Git solution. However, you do not need to switch from your current provider, as you can simply link your GitHub or Bitbucket account or just set it up as a separate remote control.
Switch to the Cloud Source console and create a new repo. Give it a name and log in with your account to select a repository.
If you add it as a separate remote control, you can add repo with the given
git remote add command, making it accessible under the remote name “
git push, replaces standard
git push --all google
Set up cloud building
Switch to Cloud Build Console and set up a new build trigger:
This trigger is run in response to events in the source repository. Give it a name and choose if you want to build in response to commitments to a particular branch, or when new tags are printed or when pull requests are made to GitHub.
Below, select “Dockerfile” as the build configuration rather than Google’s own YAML configuration. This is the advantage of working with containers; you have already handled the build process in the Docker configuration, so you can simply select it here.
If your Docker file is named “Dockerfile” and is placed at the root of the repository, you can leave the first two fields blank. For the image name, it will be sent to GCR, Google’s own container register.
Once you have created, you can click “Run Trigger” to start construction manually. Since Cloud Build only uses your Docker file, as long as it builds locally, you should have no build issues.
If you switch to the GCR console, you should see the newly built image.
Configure automatic distributions for Cloud Run
You can update your distributions manually, but if you want to make automatic updates, you need a little more configuration.
Instead of just selecting Dockerfile, you can choose to use a traditional YAML file, which allows you to run some commands after the build process. In this case run
gcloud run deploy and sends it a ref to the newly created image in GCR.
steps: # build the container image - name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/$PROJECT_ID/[SERVICE-NAME]:$COMMIT_SHA', '.'] # push the container image to Container Registry - name: 'gcr.io/cloud-builders/docker' args: ['push', 'gcr.io/$PROJECT_ID/[SERVICE-NAME]:$COMMIT_SHA'] # Deploy container image to Cloud Run - name: 'gcr.io/cloud-builders/gcloud' args: - 'run' - 'deploy' - '[SERVICE-NAME]' - '--image' - 'gcr.io/$PROJECT_ID/[SERVICE-NAME]:$COMMIT_SHA' - '--region' - '[REGION]' - '--platform' - 'managed' images: - 'gcr.io/$PROJECT_ID/[SERVICE-NAME]:$COMMIT_SHA'
You must also grant Cloud Build permission to access Cloud Run from the service account settings.