Skip to content

Commit

Permalink
[#429] add docker cache to build workflow
Browse files Browse the repository at this point in the history
Saves the docker cache configured in the `cacheTo` and `cacheFrom`
options of the Fabric8 `docker-maven-plugin` to GH caches to speed image
rebuilds.  Also uses the `install-dependencies` custom action to
de-duplicate the required build tool installation logic, and updates the
existing caches to save to a constant name.
  • Loading branch information
ewilkins-csi committed Oct 24, 2024
1 parent 0972a54 commit 3754351
Showing 1 changed file with 24 additions and 39 deletions.
63 changes: 24 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,63 +49,43 @@ jobs:
})
}
console.log("Clear completed")
- name: Login to Docker Hub
uses: docker/login-action@v3
- name: Install dependencies
uses: ./.github/actions/install_dependencies
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Install required packages
run: |
sudo apt-get update
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl \
git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev zip unzip \
libpython3.11
- name: Install Python
uses: gabrielfalcao/pyenv-action@v18
with:
default: 3.11.4
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
docker-token: ${{ secrets.DOCKERHUB_TOKEN }}
#NB: We restore/save cache manually so that we save the cache even if the build fails
- name: Load m2 repository cache # Manually caching .m2 repo as the setup-java caching isn't falling back to older caches
id: cached-m2-repo
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
- name: Load m2 build cache
id: cached-m2-build
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: ~/.m2/build-cache
key: maven-build-cache-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-cache-
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Load docker build cache
id: cached-docker-build
uses: actions/cache/restore@v4
with:
path: ~/.docker/cache
key: docker-cache-${{ hashFiles('**/pom.xml') }}
restore-keys: |
docker-cache-
#NB: Not saving poetry cache on failure in case it's a failure caused by an in-flight python package release
- name: Poetry cache
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ hashFiles('**/pom.xml') }}
restore-keys: |
poetry-
- name: Install Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
- name: Install Helm Unittest Plugin
run: |
echo "Updating helm unittest plugin to latest version..."
helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Create Docker Builder Config File
run: sudo touch /etc/buildkitd.toml
key: poetry-cache
# Generate the settings.xml for ghcr.io, pypi, & dev-pypi server profiles
- name: Create settings.xml
run: |
Expand All @@ -123,8 +103,6 @@ jobs:
- name: Run Archetype Tests
run: |
./mvnw -B clean install -Parchetype-test -pl :foundation-archetype
#NB: The following two explicit cache saves are necessary to ensure caches are saved on build failure,
# until https://github.com/actions/cache/issues/1315 is resolved
- name: Save m2 repository cache
id: save-m2-repo
uses: actions/cache/save@v4
Expand All @@ -139,3 +117,10 @@ jobs:
with:
path: ~/.m2/build-cache
key: maven-build-cache-${{ hashFiles('**/pom.xml') }}
- name: Save docker build cache
id: save-docker-build
uses: actions/cache/save@v4
if: always()
with:
path: ~/.docker/cache
key: docker-cache-${{ hashFiles('**/pom.xml') }}

0 comments on commit 3754351

Please sign in to comment.