Skip to content

Commit 8ae4cde

Browse files
committed
[#429] add docker cache to build workflow
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.
1 parent 91857d9 commit 8ae4cde

File tree

1 file changed

+26
-47
lines changed

1 file changed

+26
-47
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,63 +49,37 @@ jobs:
4949
})
5050
}
5151
console.log("Clear completed")
52-
- name: Login to Docker Hub
53-
uses: docker/login-action@v3
52+
- name: Install dependencies
53+
uses: ./.github/actions/install_dependencies
5454
with:
55-
username: ${{ secrets.DOCKERHUB_USERNAME }}
56-
password: ${{ secrets.DOCKERHUB_TOKEN }}
57-
- name: Install required packages
58-
run: |
59-
sudo apt-get update
60-
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl \
61-
git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev zip unzip \
62-
libpython3.11
63-
- name: Install Python
64-
uses: gabrielfalcao/pyenv-action@v18
65-
with:
66-
default: 3.11.4
55+
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
docker-token: ${{ secrets.DOCKERHUB_TOKEN }}
57+
#NB: We restore/save cache manually so that we save the cache even if the build fails
6758
- name: Load m2 repository cache # Manually caching .m2 repo as the setup-java caching isn't falling back to older caches
6859
id: cached-m2-repo
69-
uses: actions/cache@v4
60+
uses: actions/cache/restore@v4
7061
with:
7162
path: ~/.m2/repository
72-
key: maven-${{ hashFiles('**/pom.xml') }}
73-
restore-keys: |
74-
maven-
63+
key: maven
7564
- name: Load m2 build cache
7665
id: cached-m2-build
77-
uses: actions/cache@v4
66+
uses: actions/cache/restore@v4
7867
with:
7968
path: ~/.m2/build-cache
80-
key: maven-build-cache-${{ hashFiles('**/pom.xml') }}
81-
restore-keys: |
82-
maven-build-cache-
83-
- name: Install Poetry
84-
uses: snok/install-poetry@v1
69+
key: maven-build-cache
70+
- name: Load docker build cache
71+
id: cached-docker-build
72+
uses: actions/cache/restore@v4
73+
with:
74+
path: ~/.docker/cache
75+
key: docker-cache
76+
#NB: Not saving poetry cache on failure in case it's a failure caused by an in-flight python package release
8577
- name: Poetry cache
8678
id: cached-poetry
8779
uses: actions/cache@v4
8880
with:
8981
path: ~/.cache/pypoetry
90-
key: poetry-cache-${{ hashFiles('**/pom.xml') }}
91-
restore-keys: |
92-
poetry-
93-
- name: Install Helm
94-
run: |
95-
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
96-
chmod 700 get_helm.sh
97-
./get_helm.sh
98-
- name: Install Helm Unittest Plugin
99-
run: |
100-
echo "Updating helm unittest plugin to latest version..."
101-
helm plugin install https://github.com/helm-unittest/helm-unittest.git
102-
- name: Set up JDK 17
103-
uses: actions/setup-java@v4
104-
with:
105-
java-version: '17'
106-
distribution: 'temurin'
107-
- name: Create Docker Builder Config File
108-
run: sudo touch /etc/buildkitd.toml
82+
key: poetry-cache
10983
# Generate the settings.xml for ghcr.io, pypi, & dev-pypi server profiles
11084
- name: Create settings.xml
11185
run: |
@@ -123,19 +97,24 @@ jobs:
12397
- name: Run Archetype Tests
12498
run: |
12599
./mvnw -B clean install -Parchetype-test -pl :foundation-archetype
126-
#NB: The following two explicit cache saves are necessary to ensure caches are saved on build failure,
127-
# until https://github.com/actions/cache/issues/1315 is resolved
128100
- name: Save m2 repository cache
129101
id: save-m2-repo
130102
uses: actions/cache/save@v4
131103
if: always()
132104
with:
133105
path: ~/.m2/repository
134-
key: maven-${{ hashFiles('**/pom.xml') }}
106+
key: maven
135107
- name: Save m2 build cache
136108
id: save-m2-build
137109
uses: actions/cache/save@v4
138110
if: always()
139111
with:
140112
path: ~/.m2/build-cache
141-
key: maven-build-cache-${{ hashFiles('**/pom.xml') }}
113+
key: maven-build-cache
114+
- name: Save docker build cache
115+
id: save-docker-build
116+
uses: actions/cache/save@v4
117+
if: always()
118+
with:
119+
path: ~/.docker/cache
120+
key: docker-cache

0 commit comments

Comments
 (0)