@@ -2,6 +2,17 @@ name: Build build-tools image
2
2
3
3
on :
4
4
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
5
16
outputs :
6
17
image-tag :
7
18
description : " build-tools tag"
@@ -32,43 +43,55 @@ jobs:
32
43
check-image :
33
44
runs-on : ubuntu-22.04
34
45
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 }}
37
51
38
52
steps :
39
53
- uses : actions/checkout@v4
40
54
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
43
57
env :
58
+ ARCHS : ${{ inputs.archs || '["x64","arm64"]' }}
59
+ DEBIANS : ${{ inputs.debians || '["bullseye","bookworm"]' }}
44
60
IMAGE_TAG : |
45
61
${{ hashFiles('build-tools.Dockerfile',
46
62
'.github/workflows/build-build-tools-image.yml') }}
47
63
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}
49
67
50
- - name : Check if such tag found in the registry
51
- id : check-image
68
+ - name : Set more variables
69
+ id : set-more-variables
52
70
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') }}
54
77
run : |
55
78
if docker manifest inspect neondatabase/build-tools:${IMAGE_TAG}; then
56
79
found=true
57
80
else
58
81
found=false
59
82
fi
60
83
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}
63
86
64
87
build-image :
65
88
needs : [ check-image ]
66
89
if : needs.check-image.outputs.found == 'false'
67
90
68
91
strategy :
69
92
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) }}
72
95
73
96
runs-on : ${{ fromJson(format('["self-hosted", "{0}"]', matrix.arch == 'arm64' && 'large-arm64' || 'large')) }}
74
97
@@ -99,11 +122,11 @@ jobs:
99
122
push : true
100
123
pull : true
101
124
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) || '' }}
105
128
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 }}
107
130
108
131
merge-images :
109
132
needs : [ check-image, build-image ]
@@ -118,15 +141,21 @@ jobs:
118
141
- name : Create multi-arch image
119
142
env :
120
143
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 }}
121
147
IMAGE_TAG : ${{ needs.check-image.outputs.tag }}
122
148
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
126
153
tags+=("-t" "neondatabase/build-tools:${IMAGE_TAG}")
127
154
fi
128
155
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[@]}"
132
161
done
0 commit comments