-
Notifications
You must be signed in to change notification settings - Fork 2
198 lines (175 loc) · 6 KB
/
image-update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: image-update
#on:
# schedule:
# - cron: '0 0 * * *'
on:
push:
branches:
- master
- feature/gha
jobs:
base-image-digest:
strategy:
matrix:
image:
- command: helm
base: alpine
repo: "https://github.com/helm/helm.git"
semverRange: ">=3.12.0"
- command: istioctl
base: alpine
repo: "https://github.com/istio/istio.git"
semverRange: ">=1.21.0"
- command: kubectl
base: alpine
repo: "https://github.com/kubernetes/kubernetes.git"
semverRange: ">=1.28.0"
- command: lego
base: alpine
repo: "https://github.com/go-acme/lego.git"
semverRange: ">=4.15.0"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install semver
uses: borales/actions-yarn@v4
with:
cmd: global add semver
- name: Install regctl
uses: iarekylew00t/regctl-installer@v3
- name: Inspect latest alpine image
id: baseImage
run: |
# calculate digest
digest=$(regctl manifest digest ${{ matrix.image.base }}:latest)
echo "digest=${{ matrix.image.base }}@${digest}" >> $GITHUB_OUTPUT
# calculate checksum
checksum=$(envsubst '${repo_digest}' < ./cicd/checksum/Dockerfile | sha256sum | cut -d' ' -f1)
echo "checksum=${checksum}" >> $GITHUB_OUTPUT
# calculate versions
versions=($(git ls-remote --tags "${{matrix.image.repo}}" \
| sed -r -n 's|.*refs/tags/v?(.*)$|\1|p' \
| xargs semver -r "${{ matrix.image.semverRange}}"))
IFS=$'\n'
size=${#versions[@]}
echo $size
jsonVersions="["
for i in "${!versions[@]}"; do
jsonVersions="${jsonVersions}'${versions[$i]}'"
if (( $i < ($size-1) )); then
jsonVersions="${jsonVersions},"
fi
done
jsonVersions="${jsonVersions}]"
echo ${jsonVersions}
echo "versions=${jsonVersions}" >> $GITHUB_OUTPUT
echo "latest=${versions[$((size-1))]"
# use GoCodeAlone fork - until cloudposse fixes
# https://github.com/cloudposse/github-action-matrix-outputs-read/issues/29
- uses: GoCodeAlone/github-action-matrix-outputs-write@v1
id: out
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.image.command }}
outputs: |-
digest: ${{ steps.baseImage.outputs.digest }}
checksum: ${{ steps.baseImage.outputs.checksum }}
versions: ${{ steps.baseImage.outputs.versions }}
latest: ${{ steps.baseImage.outputs.latest }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: ./cicd/checksum
push: true
build-args: |
CHECKSUM=${{ steps.baseImage.outputs.checksum }}
REPO_DIGEST=${{ steps.baseImage.outputs.digest }}
tags: |
ghcr.io/boxboat/${{ matrix.image.command }}:checksum
# boxboat/${{ matrix.image }}:checksum
read:
runs-on: ubuntu-latest
needs: [base-image-digest]
steps:
# use GoCodeAlone fork - until cloudposse fixes
# https://github.com/cloudposse/github-action-matrix-outputs-read/issues/29
- uses: GoCodeAlone/github-action-matrix-outputs-read@v1
id: read
with:
matrix-step-name: base-image-digest
outputs:
result: "${{ steps.read.outputs.result }}"
helm:
strategy:
matrix:
version: ${{ fromJson(needs.read.outputs.result).versions.helm }}
runs-on: ubuntu-latest
needs: [read]
steps:
- uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: ./helm
platforms: linux/amd64,linux/arm64
push: true
build-args: |
CHECKSUM=${{ fromJson(needs.read.outputs.result).checksum.helm }}
REPO_DIGEST=${{ fromJson(needs.read.outputs.result).digest.helm }}
VERSION=${{ matrix.version }}
tags: |
ghcr.io/boxboat/helm:${{ matrix.version }}
- name: Install regctl
if: ${{ fromJson(needs.read.outputs.result).latest.helm == matrix.version }}
uses: iarekylew00t/regctl-installer@v3
- name: Tag latest
if: ${{ fromJson(needs.read.outputs.result).latest.helm == matrix.version }}
run: |
regctl image copy ghcr.io/boxboat/helm:${{ matrix.version }} ghcr.io/boxboat/helm:latest
# checksum-image:
# strategy:
# matrix:
# image:
# - command: helm
# base: alpine
# - command: istioctl
# base: alpine
# - command: kubectl
# base: alpine
# - command: lego
# base: alpine
#
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
#