One of the pain points in all the development projects that I have worked on has been setting up/getting an infrastructure for automation. This has typically meant getting access to an instance of Jenkins. I have great respect for Jenkins as a tool, but each deployment of Jenkins tends to become a Snowflake over time with the different set of underlying plugins, version of software, variation of pipeline script etc.
This is exactly the niche that a tool like Cloud Build solves for, deployment is managed by Google Cloud platform, and the build steps are entirely user driven based on the image used for each step of the pipeline.
In the first post I went over the basics of creating a Cloud Build configuration and in the second post went over a fairly comprehensive pipeline for a Java based project.
This post will conclude the series by showing an approach to caching in the pipeline - this is far from original, I am borrowing generously from a few sample configurations that I have found. So let me start by describing the issue being solved for.
Problem
- The tool itself is not a binary, but a wrapper which knows to download the right version of the tools binary.
- The projects dependencies specified in tool specific DSL's are then downloaded from repositories.
Caching across Runs of a Build
- Cache the downloaded dependencies into Cloud Storage at the end of the build
- And then use it to rehydrate the dependencies at the beginning of the build, if available
volumes: - name: caching.home path: /cachinghome
dir: /cachinghome entrypoint: bash args: - -c - | ( gsutil cp gs://${_GCS_CACHE_BUCKET}/gradle-cache.tar.gz /tmp/gradle-cache.tar.gz && tar -xzf /tmp/gradle-cache.tar.gz ) || echo 'Cache not found' volumes: - name: caching.home path: /cachinghome
- name: openjdk:11 id: test entrypoint: "/bin/bash" args: - '-c' - |- export CACHING_HOME="/cachinghome" USER_HOME="/root" GRADLE_HOME="$${USER_HOME}/.gradle" GRADLE_CACHE="$${CACHING_HOME}/gradle" mkdir -p $${GRADLE_CACHE} [[ -d "$${GRADLE_CACHE}" && ! -d "$${GRADLE_HOME}" ]] && ln -s "$${GRADLE_CACHE}" "$${GRADLE_HOME}" ./gradlew check volumes: - name: caching.home path: /cachinghome
No comments:
Post a Comment