Skip to content

Commit 7b41ee8

Browse files
authored
CI(pre-merge-checks): build only one build-tools-image (#9718)
## Problem The `pre-merge-checks` workflow relies on the build-tools image. If changes to the `build-tools` image have been merged into the main branch since the last CI run for a PR (with other changes to the `build-tools`), the image will be rebuilt during the merge queue run. Otherwise, cached images are used. Rebuilding the image adds approximately 10 minutes on x86-64 and 20 minutes on arm64 to the process. ## Summary of changes - parametrise `build-build-tools-image` job with arch and Debian version - Run `pre-merge-checks` only on Debian 12 x86-64 image
1 parent 277c33b commit 7b41ee8

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

.github/workflows/build-build-tools-image.yml

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ name: Build build-tools image
22

33
on:
44
workflow_call:
5+
inputs:
6+
archs:
7+
description: "Json array of architectures to build"
8+
# Default values are set in `check-image` job, `set-variables` step
9+
type: string
10+
required: false
11+
debians:
12+
description: "Json array of Debian versions to build"
13+
# Default values are set in `check-image` job, `set-variables` step
14+
type: string
15+
required: false
516
outputs:
617
image-tag:
718
description: "build-tools tag"
@@ -32,43 +43,55 @@ jobs:
3243
check-image:
3344
runs-on: ubuntu-22.04
3445
outputs:
35-
tag: ${{ steps.get-build-tools-tag.outputs.image-tag }}
36-
found: ${{ steps.check-image.outputs.found }}
46+
archs: ${{ steps.set-variables.outputs.archs }}
47+
debians: ${{ steps.set-variables.outputs.debians }}
48+
tag: ${{ steps.set-variables.outputs.image-tag }}
49+
everything: ${{ steps.set-more-variables.outputs.everything }}
50+
found: ${{ steps.set-more-variables.outputs.found }}
3751

3852
steps:
3953
- uses: actions/checkout@v4
4054

41-
- name: Get build-tools image tag for the current commit
42-
id: get-build-tools-tag
55+
- name: Set variables
56+
id: set-variables
4357
env:
58+
ARCHS: ${{ inputs.archs || '["x64","arm64"]' }}
59+
DEBIANS: ${{ inputs.debians || '["bullseye","bookworm"]' }}
4460
IMAGE_TAG: |
4561
${{ hashFiles('build-tools.Dockerfile',
4662
'.github/workflows/build-build-tools-image.yml') }}
4763
run: |
48-
echo "image-tag=${IMAGE_TAG}" | tee -a $GITHUB_OUTPUT
64+
echo "archs=${ARCHS}" | tee -a ${GITHUB_OUTPUT}
65+
echo "debians=${DEBIANS}" | tee -a ${GITHUB_OUTPUT}
66+
echo "image-tag=${IMAGE_TAG}" | tee -a ${GITHUB_OUTPUT}
4967
50-
- name: Check if such tag found in the registry
51-
id: check-image
68+
- name: Set more variables
69+
id: set-more-variables
5270
env:
53-
IMAGE_TAG: ${{ steps.get-build-tools-tag.outputs.image-tag }}
71+
IMAGE_TAG: ${{ steps.set-variables.outputs.image-tag }}
72+
EVERYTHING: |
73+
${{ contains(fromJson(steps.set-variables.outputs.archs), 'x64') &&
74+
contains(fromJson(steps.set-variables.outputs.archs), 'arm64') &&
75+
contains(fromJson(steps.set-variables.outputs.debians), 'bullseye') &&
76+
contains(fromJson(steps.set-variables.outputs.debians), 'bookworm') }}
5477
run: |
5578
if docker manifest inspect neondatabase/build-tools:${IMAGE_TAG}; then
5679
found=true
5780
else
5881
found=false
5982
fi
6083
61-
echo "found=${found}" | tee -a $GITHUB_OUTPUT
62-
84+
echo "everything=${EVERYTHING}" | tee -a ${GITHUB_OUTPUT}
85+
echo "found=${found}" | tee -a ${GITHUB_OUTPUT}
6386
6487
build-image:
6588
needs: [ check-image ]
6689
if: needs.check-image.outputs.found == 'false'
6790

6891
strategy:
6992
matrix:
70-
debian-version: [ bullseye, bookworm ]
71-
arch: [ x64, arm64 ]
93+
arch: ${{ fromJson(needs.check-image.outputs.archs) }}
94+
debian: ${{ fromJson(needs.check-image.outputs.debians) }}
7295

7396
runs-on: ${{ fromJson(format('["self-hosted", "{0}"]', matrix.arch == 'arm64' && 'large-arm64' || 'large')) }}
7497

@@ -99,11 +122,11 @@ jobs:
99122
push: true
100123
pull: true
101124
build-args: |
102-
DEBIAN_VERSION=${{ matrix.debian-version }}
103-
cache-from: type=registry,ref=cache.neon.build/build-tools:cache-${{ matrix.debian-version }}-${{ matrix.arch }}
104-
cache-to: ${{ github.ref_name == 'main' && format('type=registry,ref=cache.neon.build/build-tools:cache-{0}-{1},mode=max', matrix.debian-version, matrix.arch) || '' }}
125+
DEBIAN_VERSION=${{ matrix.debian }}
126+
cache-from: type=registry,ref=cache.neon.build/build-tools:cache-${{ matrix.debian }}-${{ matrix.arch }}
127+
cache-to: ${{ github.ref_name == 'main' && format('type=registry,ref=cache.neon.build/build-tools:cache-{0}-{1},mode=max', matrix.debian, matrix.arch) || '' }}
105128
tags: |
106-
neondatabase/build-tools:${{ needs.check-image.outputs.tag }}-${{ matrix.debian-version }}-${{ matrix.arch }}
129+
neondatabase/build-tools:${{ needs.check-image.outputs.tag }}-${{ matrix.debian }}-${{ matrix.arch }}
107130
108131
merge-images:
109132
needs: [ check-image, build-image ]
@@ -118,15 +141,21 @@ jobs:
118141
- name: Create multi-arch image
119142
env:
120143
DEFAULT_DEBIAN_VERSION: bookworm
144+
ARCHS: ${{ join(fromJson(needs.check-image.outputs.archs), ' ') }}
145+
DEBIANS: ${{ join(fromJson(needs.check-image.outputs.debians), ' ') }}
146+
EVERYTHING: ${{ needs.check-image.outputs.everything }}
121147
IMAGE_TAG: ${{ needs.check-image.outputs.tag }}
122148
run: |
123-
for debian_version in bullseye bookworm; do
124-
tags=("-t" "neondatabase/build-tools:${IMAGE_TAG}-${debian_version}")
125-
if [ "${debian_version}" == "${DEFAULT_DEBIAN_VERSION}" ]; then
149+
for debian in ${DEBIANS}; do
150+
tags=("-t" "neondatabase/build-tools:${IMAGE_TAG}-${debian}")
151+
152+
if [ "${EVERYTHING}" == "true" ] && [ "${debian}" == "${DEFAULT_DEBIAN_VERSION}" ]; then
126153
tags+=("-t" "neondatabase/build-tools:${IMAGE_TAG}")
127154
fi
128155
129-
docker buildx imagetools create "${tags[@]}" \
130-
neondatabase/build-tools:${IMAGE_TAG}-${debian_version}-x64 \
131-
neondatabase/build-tools:${IMAGE_TAG}-${debian_version}-arm64
156+
for arch in ${ARCHS}; do
157+
tags+=("neondatabase/build-tools:${IMAGE_TAG}-${debian}-${arch}")
158+
done
159+
160+
docker buildx imagetools create "${tags[@]}"
132161
done

.github/workflows/pre-merge-checks.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
id: python-src
2424
with:
2525
files: |
26+
.github/workflows/_check-codestyle-python.yml
27+
.github/workflows/build-build-tools-image.yml
2628
.github/workflows/pre-merge-checks.yml
2729
**/**.py
2830
poetry.lock
@@ -38,14 +40,19 @@ jobs:
3840
if: needs.get-changed-files.outputs.python-changed == 'true'
3941
needs: [ get-changed-files ]
4042
uses: ./.github/workflows/build-build-tools-image.yml
43+
with:
44+
# Build only one combination to save time
45+
archs: '["x64"]'
46+
debians: '["bookworm"]'
4147
secrets: inherit
4248

4349
check-codestyle-python:
4450
if: needs.get-changed-files.outputs.python-changed == 'true'
4551
needs: [ get-changed-files, build-build-tools-image ]
4652
uses: ./.github/workflows/_check-codestyle-python.yml
4753
with:
48-
build-tools-image: ${{ needs.build-build-tools-image.outputs.image }}-bookworm
54+
# `-bookworm-x64` suffix should match the combination in `build-build-tools-image`
55+
build-tools-image: ${{ needs.build-build-tools-image.outputs.image }}-bookworm-x64
4956
secrets: inherit
5057

5158
# To get items from the merge queue merged into main we need to satisfy "Status checks that are required".

0 commit comments

Comments
 (0)