1
1
name : vm-kernel
2
2
3
3
on :
4
- schedule :
5
- - cron : ' 42 4 * * 2' # run once a week
6
4
workflow_dispatch : # adds ability to run this manually
7
5
inputs :
8
- push :
9
- description : ' Push to Docker Hub'
10
- type : boolean
11
- default : false
12
6
tag :
13
7
description : ' Tag to use for Docker image'
14
8
type : string
15
9
required : false
16
- workflow_call :
17
- inputs :
18
- push :
19
- description : ' Push to Docker Hub'
10
+ force-rebuild :
11
+ description : ' Rebuild the kernel image even if it already exists'
20
12
type : boolean
13
+ required : false
21
14
default : false
15
+ workflow_call :
16
+ inputs :
22
17
tag :
23
18
description : ' Tag to use for Docker image'
24
19
type : string
25
20
required : false
26
- kernel -image-tag-override :
27
- description : ' If set, the workflow return the full image name for this tag '
21
+ return -image-for-tag :
22
+ description : ' Make workflow to return image for the passed tag without building or tagging anything '
28
23
type : string
29
24
required : false
30
25
default : ' '
26
+ force-rebuild :
27
+ description : ' Rebuild the kernel image even if it already exists. No-op if `return-image-for-tag` is set'
28
+ type : boolean
29
+ required : false
30
+ default : false
31
31
outputs :
32
32
image :
33
33
description : ' vm-kernel Docker image'
34
- value : ${{ jobs.check- kernel-image-override .outputs.image || jobs.vm-kernel.outputs.image }}
34
+ value : ${{ jobs.setup-build-vm- kernel-image.outputs.image || jobs.build- vm-kernel-image .outputs.image }}
35
35
36
36
env :
37
37
VM_KERNEL_IMAGE : " neondatabase/vm-kernel"
38
38
39
+ defaults :
40
+ run :
41
+ shell : bash -euo pipefail {0}
42
+
39
43
jobs :
40
- check- kernel-image-override :
44
+ setup-build-vm- kernel-image :
41
45
outputs :
42
- image : ${{ steps.check-kernel-image-override.outputs.image }}
46
+ image : ${{ steps.get-kernel-image.outputs.image }}
47
+ last-kernel-sha : ${{ steps.get-last-kernel-commit-sha.outputs.last-kernel-sha }}
43
48
44
49
runs-on : ubuntu-latest
45
50
46
51
steps :
47
- - id : check-kernel-image-override
52
+ - name : get last kernel commit sha
53
+ id : get-last-kernel-commit-sha
54
+ env :
55
+ COMMIT_SHA : ${{ github.event.pull_request.head.sha || github.sha }}
56
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57
+ run : |
58
+ CACHE_TAG=$(
59
+ gh api \
60
+ -H "Accept: application/vnd.github+json" \
61
+ -H "X-GitHub-Api-Version: 2022-11-28" \
62
+ --method GET \
63
+ --field path=neonvm/hack/kernel \
64
+ --field sha=${COMMIT_SHA} \
65
+ --field per_page=1 \
66
+ --jq ".[0].sha" \
67
+ "/repos/${GITHUB_REPOSITORY}/commits"
68
+ )
69
+ echo "last-kernel-sha=${CACHE_TAG}" >> $GITHUB_OUTPUT
70
+
71
+ - name : get kernel image
72
+ id : get-kernel-image
48
73
env :
49
- OVERRIDE_TAG : ${{ inputs.kernel-image-tag-override }}
74
+ FORCED_TAG : ${{ inputs.return-image-for-tag }}
75
+ FORCE_REBUILD : ${{ inputs.force-rebuild }}
76
+ CACHE_TAG : ${{ steps.get-last-kernel-commit-sha.outputs.last-kernel-sha }}
50
77
run : |
51
- if [ -n "${OVERRIDE_TAG}" ]; then
52
- DIGEST=$(docker manifest inspect ${VM_KERNEL_IMAGE}:${OVERRIDE_TAG} -v | jq -r '.Descriptor.digest')
53
- IMAGE="${VM_KERNEL_IMAGE}:${OVERRIDE_TAG}@${DIGEST}"
78
+ if [ -n "${FORCED_TAG}" ]; then
79
+ DIGEST=$(docker manifest inspect ${VM_KERNEL_IMAGE}:${FORCED_TAG} -v | jq -r '.Descriptor.digest')
80
+ IMAGE="${VM_KERNEL_IMAGE}:${FORCED_TAG}@${DIGEST}"
81
+ elif [ "${FORCE_REBUILD}" == "false" ]; then
82
+ CACHE_TAG_DIGEST=$(docker manifest inspect ${VM_KERNEL_IMAGE}:${CACHE_TAG} -v | jq -r '.Descriptor.digest' || true)
83
+ if [ -n "${CACHE_TAG_DIGEST}" ]; then
84
+ IMAGE="${VM_KERNEL_IMAGE}:${CACHE_TAG}@${CACHE_TAG_DIGEST}"
85
+ else
86
+ IMAGE=""
87
+ fi
54
88
else
55
89
IMAGE=""
56
90
fi
91
+
57
92
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
58
93
59
- vm-kernel :
60
- needs : check-kernel-image-override
61
- if : needs.check-kernel-image-override.outputs.image == ''
94
+ - name : check if we need to retag the image
95
+ id : check-if-retag-needed
96
+ env :
97
+ CACHED_IMAGE : ${{ steps.get-kernel-image.outputs.image }}
98
+ FORCE_REBUILD : " ${{ inputs.force-rebuild }}"
99
+ FORCED_TAG : ${{ inputs.return-image-for-tag }}
100
+ NEW_TAG : ${{ inputs.tag }}
101
+ run : |
102
+ if [ -z "${NEW_TAG}" ]; then
103
+ # there's no tag provided to retag the image with
104
+ RETAG_NEEDED=false
105
+ elif [ -z "${CACHED_IMAGE}" ]; then
106
+ # there's no image to retag
107
+ RETAG_NEEDED=false
108
+ elif [ -n "${FORCED_TAG}"]; then
109
+ # we're asked to return image for a specific tag, so no need to retag
110
+ RETAG_NEEDED=false
111
+ elif [ "${FORCE_REBUILD}" == "true" ]; then
112
+ # the image is going to be rebuilt anyway, no need to retag it now
113
+ RETAG_NEEDED=false
114
+ else
115
+ RETAG_NEEDED=true
116
+ fi
117
+
118
+ echo "retag-needed=${RETAG_NEEDED}" >> $GITHUB_OUTPUT
119
+
120
+ - name : login to docker hub
121
+ if : steps.check-if-retag-needed.outputs.retag-needed == 'true'
122
+ uses : docker/login-action@v2
123
+ with :
124
+ username : ${{ secrets.NEON_DOCKERHUB_USERNAME }}
125
+ password : ${{ secrets.NEON_DOCKERHUB_PASSWORD }}
126
+
127
+ - name : tag image with new tag
128
+ if : steps.check-if-retag-needed.outputs.retag-needed == 'true'
129
+ env :
130
+ CACHED_IMAGE : ${{ steps.get-kernel-image.outputs.image }}
131
+ NEW_TAG : ${{ inputs.tag }}
132
+ run : |
133
+ docker pull ${CACHED_IMAGE}
134
+ docker tag ${CACHED_IMAGE} ${VM_KERNEL_IMAGE}:${NEW_TAG}
135
+ docker push ${VM_KERNEL_IMAGE}:${NEW_TAG}
136
+
137
+ build-vm-kernel-image :
138
+ needs : setup-build-vm-kernel-image
139
+ if : needs.setup-build-vm-kernel-image.outputs.image == ''
62
140
outputs :
63
- image : ${{ fromJSON( steps.build-linux-kernel .outputs.metadata)['image.name'] }}@${{ steps.build-linux-kernel.outputs.digest }}
141
+ image : ${{ steps.get-tags .outputs.canonical }}@${{ steps.build-linux-kernel.outputs.digest }}
64
142
65
143
runs-on : [ self-hosted, gen3, large ]
66
144
steps :
@@ -87,25 +165,42 @@ jobs:
87
165
- name : get kernel version
88
166
id : get-kernel-version
89
167
run : |
90
- linux_config=$(ls neonvm/hack/linux-config-*) # returns something like "neonvm/hack/linux-config-6.1.63"
91
- kernel_version=${linux_config##*-} # returns something like "6.1.63"
168
+ linux_config=$(ls neonvm/hack/kernel/ linux-config-*) # returns something like "neonvm/hack/kernel /linux-config-6.1.63"
169
+ kernel_version=${linux_config##*-} # returns something like "6.1.63"
92
170
93
171
echo VM_KERNEL_VERSION=$kernel_version >> $GITHUB_OUTPUT
94
172
173
+ - name : get docker tags
174
+ id : get-tags
175
+ env :
176
+ KERNEL_VERSION_TAG : ${{ inputs.tag || steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
177
+ CACHE_TAG : ${{ needs.setup-build-vm-kernel-image.outputs.last-kernel-sha }}
178
+ run : |
179
+ # A comma-separated list of tags
180
+ TAGS="${VM_KERNEL_IMAGE}:${KERNEL_VERSION_TAG}"
181
+ TAGS="${VM_KERNEL_IMAGE}:${CACHE_TAG},${TAGS}"
182
+ TAGS="${VM_KERNEL_IMAGE}:${GITHUB_RUN_ID},${TAGS}"
183
+
184
+ echo "tags=${TAGS}" >> $GITHUB_OUTPUT
185
+
186
+ # `docker/build-push-action@v3` returns all ${TAGS} in metadata ("image.name" field), so it can't be used a image name right away.
187
+ # Choose one of them as a "canonical" tag and use it to construct the job output (along with a digest provided by `docker/build-push-action@v3`).
188
+ echo "canonical=${VM_KERNEL_IMAGE}:${GITHUB_RUN_ID}" >> $GITHUB_OUTPUT
189
+
95
190
- name : build linux kernel
96
191
id : build-linux-kernel
97
192
uses : docker/build-push-action@v3
98
193
with :
99
194
build-args : KERNEL_VERSION=${{ steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
100
- context : neonvm/hack
195
+ context : neonvm/hack/kernel
101
196
platforms : linux/amd64
102
197
# Push kernel image only for scheduled builds or if workflow_dispatch/workflow_call input is true
103
- push : ${{ github.event_name == 'schedule' && ' true' || ( inputs.push || 'false' ) }}
198
+ push : true
104
199
pull : true
105
200
no-cache : true
106
- file : neonvm/hack/Dockerfile.kernel-builder
107
- # Tag kernel image with workflow_dispatch/workflow_call input or with the kernel version by default
108
- tags : ${{ env.VM_KERNEL_IMAGE }}:${{ inputs.tag || steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
201
+ file : neonvm/hack/kernel/ Dockerfile.kernel-builder
202
+ tags : ${{ steps.get-tags.outputs.tags }}
203
+
109
204
- name : remove custom docker config directory
110
205
if : always()
111
206
run : |
0 commit comments