قالب وردپرس درنا توس
Home / Tips and Tricks / Configure automated container buildings with GCP Cloud Build – CloudSavvy IT

Configure automated container buildings with GCP Cloud Build – CloudSavvy IT



google cloud platform

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.

create cloud source repo

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 “google. “To drive to this branch, all you need to do is fully qualify the remote control and branch name when driving git push, replaces standard origin with google:

git push --all google

Set up cloud building

Switch to Cloud Build Console and set up a new build trigger:

create new 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.

listen to source changes on branch or PR

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.

gcr.io/$PROJECT_ID/imagename:$COMMIT_SHA

Select

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.

successful building

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.

settings for the service account


Source link