This is a short write-up on using Google Cloud Deploy for Continuous Deployment of a Java-based project.
Google Cloud Deploy is a new entrant to the CD space. It facilitates a continuous deployment currently to GKE based targets and in future to other Google Cloud application runtime targets.
Let's start with why such a tool is required, why not an automation tool like Cloud Build or Jenkins. In my mind it comes down to these things:
- State - a dedicated CD tool can keep state of the artifact, to the environments where the artifact is deployed. This way promotion of deployments, rollback to an older version, roll forward is easily done. Such an integration can be built into a CI tool but it will involve a lot of coding effort.
- Integration with the Deployment environment - a CD tools integrates well the target deployment platform without too much custom code needed.
Target Flow
Building an Image
Running the test and building the image is handled with a combination of Cloud Build providing the build automation environment and skaffold providing tooling through Cloud Native Buildpacks. It may be easier to look at the code repository to see how both are wired up - https://github.com/bijukunjummen/hello-skaffold-gke
Deploying the image to GKE
Now that an image has been baked, the next step is to deploy this into a GKE Kubernetes environment. Cloud Deploy has a declarative way of specifying the environments(referred to as Targets) and how to promote the deployment through the environments. A Google Cloud Deploy pipeline looks like this:
The pipeline is fairly easy to read. Target(s) describe the environments to deploy the image to and the pipeline shows how progression of the deployment across the environments is handled.
One thing to notice is that the "prod" target has been marked with a "requires approval" flag which is a way to ensure that the promotion to prod environment happens only with an approval. Cloud Deploy documentation has a good coverage of all these concepts. Also, there is a strong dependence on skaffold to generate the kubernetes manifests and deploying them to the relevant targets.
Given such a deployment pipeline, it can be put in place using:
gcloud beta deploy apply --file=clouddeploy.yaml --region=us-west1
Alright, now that the CD pipeline is in place, a "Release" can be triggered once the testing is completed in a "main" branch, a command which looks like this is integrated with the Cloud Build pipeline to do this, with a file pointing to the build artifacts:
gcloud beta deploy releases create release-01df029 --delivery-pipeline hello-skaffold-gke --region us-west1 --build-artifacts artifacts.jsonThis deploys the generated kubernetes manifests pointing to the right build artifacts to the "dev" environment
Conclusion
- Kubernetes, which is the only application runtime currently supported, expect other runtimes to be supported as the Product evolves.
- skaffold, which is used for building, tagging, generating kubernetes artifacts
- Cloud Build and its yaml configuration
- Google Cloud Deploys yaml configuration