Skip to content

Commit c39d2bb

Browse files
committed
no-max
1 parent a4aa529 commit c39d2bb

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'Build docker image'
2+
description: 'Build docker image'
3+
4+
inputs:
5+
context:
6+
description: 'Context argument'
7+
required: true
8+
file:
9+
description: 'Docker file'
10+
required: true
11+
cache_key_prefix:
12+
description: 'Cache key prefix'
13+
required: true
14+
15+
runs:
16+
using: composite
17+
steps:
18+
# Attempt to speed up building of docker images for Linux-based binaries by
19+
# using docker's recommended way of building/caching with github actions.
20+
# Notably this caches layers to github actions which enables subsequent
21+
# reuse in future runs. The goal here is to make this step faster while
22+
# additionally reducing network flakiness since the github actions cache
23+
# generally works better than upstream package servers, or at least in
24+
# theory.
25+
#
26+
# The way that this is designed is to build the image with docker-related
27+
# github actions here primarily. This populates the github actions cache
28+
# but also the local docker daemon cache too. Subsequently when the actual
29+
# build script runs it'll attempt to rebuild the image and it should get a
30+
# bunch of cache hits from here. This way we can configure the caching here
31+
# within github actions without impacting the functionality of the script
32+
# itself and continue enabling it to run locally.
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v4
35+
36+
- name: Disable some docker things that are on-by-default
37+
shell: bash
38+
run: |
39+
echo DOCKER_BUILD_CHECKS_ANNOTATIONS=false >> $GITHUB_ENV
40+
echo DOCKER_BUILD_SUMMARY=false >> $GITHUB_ENV
41+
echo DOCKER_BUILD_RECORD_UPLOAD=false >> $GITHUB_ENV
42+
43+
- name: Setup Github Actions cache
44+
uses: actions/cache@v5
45+
with:
46+
path: ${{ runner.tool_cache }}/docker-buildx-cache
47+
key: ${{ inputs.cache_key_prefix }}-${{ hashFiles(inputs.file) }}
48+
49+
- name: Build docker image
50+
uses: docker/build-push-action@v7
51+
with:
52+
context: ${{ inputs.context }}
53+
file: ${{ inputs.file }}
54+
tags: build-image
55+
cache-from: type=local,src=${{ runner.tool_cache }}/docker-buildx-cache
56+
cache-to: type=local,dest=${{ runner.tool_cache }}/docker-buildx-cache
57+
outputs: type=docker

.github/workflows/main.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,12 @@ jobs:
155155
# bunch of cache hits from here. This way we can configure the caching here
156156
# within github actions without impacting the functionality of the script
157157
# itself and continue enabling it to run locally.
158-
- name: Set up Docker Buildx
159-
uses: docker/setup-buildx-action@v4
158+
- uses: ./.github/actions/docker-build-cached
160159
if: ${{ matrix.env.DOCKER_IMAGE }}
161-
- name: Disable some docker things that are on-by-default
162-
run: |
163-
echo DOCKER_BUILD_CHECKS_ANNOTATIONS=false >> $GITHUB_ENV
164-
echo DOCKER_BUILD_SUMMARY=false >> $GITHUB_ENV
165-
echo DOCKER_BUILD_RECORD_UPLOAD=false >> $GITHUB_ENV
166-
if: ${{ matrix.env.DOCKER_IMAGE }}
167-
- name: Build docker image
168-
if: ${{ matrix.env.DOCKER_IMAGE }}
169-
uses: docker/build-push-action@v7
170160
with:
171161
context: ci/docker
172162
file: ${{ matrix.env.DOCKER_IMAGE }}
173-
tags: build-image
174-
cache-from: type=gha
175-
cache-to: type=gha,mode=max
176-
outputs: type=docker
163+
cache_key_prefix: docker-${{ matrix.build }}
177164

178165
- uses: ./.github/actions/install-ninja
179166
if: '${{ !matrix.env.DOCKER_IMAGE }}'

0 commit comments

Comments
 (0)