This post present basic usage of the Google Cloud Build (GCB).
I've previously described using Jenkins on GCP, but I've found the GCP integration with Jenkins is very shallow, and hence decided to move the build to GCB.
GCB manages triggers, which similar to the Jenkins' job. A trigger can be started by a push to a branch on git, and run a docker image that builds the application. Unlike Jenkins' jobs, currently GCB does not manage dependencies between the triggers.
Let start review a simple build.
First let's create a trigger configuration.
trigger.yaml
name: build-app
triggerTemplate:
branchName: .*
projectId: my-gcp-project
repoName: my-repo
build:
steps:
- id: main
name: my-builder-image
entrypoint: bash
timeout: 600s
args:
- /workspace/build.sh
- ${BRANCH_NAME}
- ${COMMIT_SHA}
- ${SHORT_SHA}
timeout: 600s
and import it using:
gcloud beta builds triggers import --source=trigger.yaml
GCB clones the GIT source under /workspace folder in the docker container, hence we can run our build script from this folder. GCB supplies some predefined builders for standard builds, for example, build of image by a docker file, and build of a VM image. Still, for complex builds, we will probably need to create our own builder image.
To create our own builder images, we create a Dockerfile, and then build it using GCB
gcloud builds submit --tag gcr.io/my-gcp-project/my-builder-image
Once we push a change to the GIT, it will trigger a build that will use the builder image to build our code, and in most cases, we will push a new image to the repository.
Final Note
- For dependencies management and parallel running of triggers see this post.
- For printing Git changes history, see this post.
No comments:
Post a Comment