Skip to content

Commit 1abced2

Browse files
IrakusdmytroyeCopilot
authored
Use GHA Cache for Docker Builder in CI (#1172)
Co-authored-by: Dmytro Yermolenko <dmytro.yermolenko@intel.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 463498e commit 1abced2

File tree

3 files changed

+84
-22
lines changed

3 files changed

+84
-22
lines changed

.github/workflows/tests-all.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ concurrency:
4343
env:
4444
DOCKER_BUILDKIT: 1
4545
SUPASS: demo
46+
GITHUB_ACTIONS_CACHE: true
47+
CACHE_REGISTRY: ${{ github.repository }}
48+
CACHE_TAG: ${{ github.head_ref || github.ref_name }}
4649

4750
permissions:
4851
contents: read
@@ -72,6 +75,13 @@ jobs:
7275
with:
7376
system-prune: "true"
7477

78+
- name: "Log in to GHCR"
79+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
80+
with:
81+
registry: ghcr.io
82+
username: ${{ github.actor }}
83+
password: ${{ secrets.GITHUB_TOKEN }}
84+
7585
- name: "Run Setup"
7686
uses: ./.github/actions/setup-env
7787

@@ -112,6 +122,13 @@ jobs:
112122
with:
113123
system-prune: "true"
114124

125+
- name: "Log in to GHCR"
126+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
127+
with:
128+
registry: ghcr.io
129+
username: ${{ github.actor }}
130+
password: ${{ secrets.GITHUB_TOKEN }}
131+
115132
- name: "Run Setup"
116133
uses: ./.github/actions/setup-env
117134

@@ -152,6 +169,13 @@ jobs:
152169
with:
153170
system-prune: "true"
154171

172+
- name: "Log in to GHCR"
173+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
174+
with:
175+
registry: ghcr.io
176+
username: ${{ github.actor }}
177+
password: ${{ secrets.GITHUB_TOKEN }}
178+
155179
- name: "Run Setup"
156180
uses: ./.github/actions/setup-env
157181

@@ -192,6 +216,13 @@ jobs:
192216
with:
193217
system-prune: "true"
194218

219+
- name: "Log in to GHCR"
220+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
221+
with:
222+
registry: ghcr.io
223+
username: ${{ github.actor }}
224+
password: ${{ secrets.GITHUB_TOKEN }}
225+
195226
- name: "Run Setup"
196227
uses: ./.github/actions/setup-env
197228

@@ -232,6 +263,13 @@ jobs:
232263
with:
233264
system-prune: "true"
234265

266+
- name: "Log in to GHCR"
267+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
268+
with:
269+
registry: ghcr.io
270+
username: ${{ github.actor }}
271+
password: ${{ secrets.GITHUB_TOKEN }}
272+
235273
- name: "Run Setup"
236274
uses: ./.github/actions/setup-env
237275

.github/workflows/tests-bat.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ concurrency:
4444
env:
4545
DOCKER_BUILDKIT: 1
4646
SUPASS: demo
47+
GITHUB_ACTIONS_CACHE: true
48+
CACHE_REGISTRY: ${{ github.repository }}
49+
CACHE_TAG: ${{ github.head_ref || github.ref_name }}
4750

4851
permissions:
4952
contents: read
@@ -135,6 +138,13 @@ jobs:
135138
with:
136139
system-prune: "true"
137140

141+
- name: "Log in to GHCR"
142+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
143+
with:
144+
registry: ghcr.io
145+
username: ${{ github.actor }}
146+
password: ${{ secrets.GITHUB_TOKEN }}
147+
138148
- name: "Run Basic Acceptance Tests (BAT)"
139149
run: |
140150
make clean-all
@@ -152,6 +162,8 @@ jobs:
152162
chart-deployment-test:
153163
name: "Chart Deployment Test"
154164
runs-on: [bat]
165+
permissions:
166+
packages: write # For using GHCR as cache registry
155167
needs: [filter, check-pr-state]
156168
if: ${{ needs.filter.outputs.code_changed == 'true' && (needs.check-pr-state.outputs.pr_state != 'true' || github.event_name == 'workflow_dispatch') }}
157169
steps:
@@ -168,6 +180,13 @@ jobs:
168180
python-version: "3.x"
169181
check-latest: true
170182

183+
- name: "Log in to GHCR"
184+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
185+
with:
186+
registry: ghcr.io
187+
username: ${{ github.actor }}
188+
password: ${{ secrets.GITHUB_TOKEN }}
189+
171190
- name: Install chart with timeout
172191
run: KUBERNETES=1 DEPLOYMENT_TEST=1 ./deploy.sh
173192

common.mk

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LOG_FILE := $(BUILD_DIR)/$(IMAGE).log
99
HAS_PIP ?= yes
1010
HAS_DPKG ?= yes
1111
USES_SCENE_COMMON ?= no
12+
GITHUB_ACTIONS_CACHE ?= false
1213
# Read the SHA-pinned image from the Dockerfile ARG default — single source of truth
1314
RUNTIME_OS_IMAGE ?= $(shell sed -n 's/^ARG RUNTIME_OS_IMAGE=//p' Dockerfile)
1415

@@ -23,32 +24,36 @@ GREEN := \033[0;32m
2324
YELLOW := \033[0;33m
2425
RESET := \033[0m
2526

27+
2628
.PHONY: build-image
2729
build-image: $(BUILD_DIR) Dockerfile
2830
@echo -e "$(GREEN)------- STARTING BUILD OF IMAGE: $(IMAGE):$(VERSION) -------$(RESET)"
2931
@{ \
30-
set -e; \
31-
set -o pipefail; \
32-
TARGET_ARG=""; \
33-
if [ -n "$(TARGET)" ]; then TARGET_ARG="--target $(TARGET)"; fi; \
34-
if env BUILDKIT_PROGRESS=plain docker build $(REBUILDFLAGS) $$TARGET_ARG \
35-
--build-arg http_proxy=$(http_proxy) \
36-
--build-arg https_proxy=$(https_proxy) \
37-
--build-arg no_proxy=$(no_proxy) \
38-
--build-arg CERTDOMAIN=$(CERTDOMAIN) \
39-
--build-arg FORCE_VAAPI=$(FORCE_VAAPI) \
40-
$(EXTRA_BUILD_ARGS) \
41-
--rm -t $(IMAGE):$(VERSION) \
42-
-f ./Dockerfile .. 2>&1 | tee $(LOG_FILE); \
43-
then \
44-
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest; \
45-
echo -e "$(GREEN)------- BUILD OF IMAGE $(IMAGE):$(VERSION) COMPLETED SUCCESSFULLY -------$(RESET)"; \
46-
echo "Log file created at $(LOG_FILE)"; \
47-
else \
48-
echo -e "$(RED)------- BUILD OF IMAGE $(IMAGE):$(VERSION) FAILED. CHECK $(LOG_FILE) FOR DETAILS. -------$(RESET)"; \
49-
grep --color=auto -i -r "^error" $(LOG_FILE); \
50-
exit 1; \
51-
fi \
32+
set -xe; \
33+
set -o pipefail; \
34+
if [ "$(GITHUB_ACTIONS_CACHE)" = "true" ]; then \
35+
EXTRA_BUILD_ARGS+=" --cache-from type=registry,ref=ghcr.io/${CACHE_REGISTRY}/cache-$(IMAGE):${CACHE_TAG} --cache-from type=registry,ref=ghcr.io/${CACHE_REGISTRY}/cache-$(IMAGE):main --cache-to type=registry,ref=ghcr.io/${CACHE_REGISTRY}/cache-$(IMAGE):${CACHE_TAG},ignore-error=true"; \
36+
fi; \
37+
TARGET_ARG=""; \
38+
if [ -n "$(TARGET)" ]; then TARGET_ARG="--target $(TARGET)"; fi; \
39+
if env BUILDKIT_PROGRESS=plain docker build $(REBUILDFLAGS) $$TARGET_ARG \
40+
--build-arg http_proxy=$(http_proxy) \
41+
--build-arg https_proxy=$(https_proxy) \
42+
--build-arg no_proxy=$(no_proxy) \
43+
--build-arg CERTDOMAIN=$(CERTDOMAIN) \
44+
--build-arg FORCE_VAAPI=$(FORCE_VAAPI) \
45+
$$EXTRA_BUILD_ARGS \
46+
--rm -t $(IMAGE):$(VERSION) \
47+
-f ./Dockerfile .. 2>&1 | tee $(LOG_FILE); \
48+
then \
49+
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest; \
50+
echo -e "$(GREEN)------- BUILD OF IMAGE $(IMAGE):$(VERSION) COMPLETED SUCCESSFULLY -------$(RESET)"; \
51+
echo "Log file created at $(LOG_FILE)"; \
52+
else \
53+
echo -e "$(RED)------- BUILD OF IMAGE $(IMAGE):$(VERSION) FAILED. CHECK $(LOG_FILE) FOR DETAILS. -------$(RESET)"; \
54+
grep --color=auto -i -r "^error" $(LOG_FILE); \
55+
exit 1; \
56+
fi \
5257
}
5358

5459
.PHONY: rebuild

0 commit comments

Comments
 (0)