forked from 0xFacet/facet-kona
-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (179 loc) · 7 KB
/
docker.yaml
File metadata and controls
204 lines (179 loc) · 7 KB
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
196
197
198
199
200
201
202
203
204
name: Build and Publish Docker Image
on:
workflow_dispatch:
inputs:
target:
type: choice
description: Which image to release
required: true
options:
- kona-node
- kona-host
- asterisc-builder
- cannon-builder
- kona-asterisc-prestate
- kona-cannon-prestate
push:
tags:
# matches tags like `service/v1.0.0`
- '*/v*'
env:
REGISTRY: ghcr.io
REGISTRY_IMAGE: ghcr.io/op-rs/kona
GIT_REF_NAME: ${{ github.ref_name }}
jobs:
prepare:
name: Prepare Bake
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
target: ${{ steps.target-spec.outputs.target }}
bake_target: ${{ steps.target-spec.outputs.bake_target }}
bin_target: ${{ steps.target-spec.outputs.bin_target }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Valid Targets
id: get-targets
run: |
# Extract target names from docker-bake.hcl, excluding docker-metadata-action
TARGETS=$(awk '/^target "[^"]*" {/ { gsub(/"/, "", $2); if ($2 != "docker-metadata-action") print $2 }' docker/docker-bake.hcl | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
echo "Available targets: $TARGETS"
- name: Specify Target
id: target-spec
run: |
export TARGET="${{ inputs.target }}"
if [[ -z $TARGET ]]; then
export TARGET="${GIT_REF_NAME%/*}"
fi
echo "Target: $TARGET"
echo "target=$TARGET" >> $GITHUB_OUTPUT
# Check if target is in valid targets list
if echo "${{ steps.get-targets.outputs.targets }}" | jq -e 'contains(["'"$TARGET"'"])' > /dev/null; then
echo "bake_target=$TARGET" >> $GITHUB_OUTPUT
echo "bin_target=" >> $GITHUB_OUTPUT
echo "Target '$TARGET' is a valid bake target"
else
echo "bake_target=generic" >> $GITHUB_OUTPUT
echo "bin_target=$TARGET" >> $GITHUB_OUTPUT
echo "Target '$TARGET' will use generic build with BIN_TARGET=$TARGET"
fi
- name: Create matrix
id: platforms
run: |
echo "matrix=$(docker buildx bake -f docker/docker-bake.hcl ${{ steps.target-spec.outputs.bake_target }} --print | jq -cr '.target."${{ steps.target-spec.outputs.bake_target }}".platforms')" >> ${GITHUB_OUTPUT}
- name: Show matrix
run: |
echo "Matrix: ${{ steps.platforms.outputs.matrix }}"
echo "Target: ${{ steps.target-spec.outputs.target }}"
echo "Bake Target: ${{ steps.target-spec.outputs.bake_target }}"
echo "Bin Target: ${{ steps.target-spec.outputs.bin_target }}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}/${{ steps.target-spec.outputs.target }}
tags: |
type=ref,event=branch
type=match,pattern=v(.*),group=1,event=tag
type=ref,event=pr
- name: Rename meta bake definition file
run: |
mv "${{ steps.meta.outputs.bake-file }}" "${{ runner.temp }}/bake-meta.json"
- name: Upload meta bake definition
uses: actions/upload-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}/bake-meta.json
if-no-files-found: error
retention-days: 1
build:
name: Build Image (${{ needs.prepare.outputs.target }} - ${{ matrix.platform }})
runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || 'ubuntu-22.04-arm' }}
needs:
- prepare
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}
- name: Authenticate with container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build
id: bake
uses: docker/bake-action@v6
env:
BIN_TARGET: ${{ needs.prepare.outputs.bin_target }}
with:
files: |
./docker/docker-bake.hcl
cwd://${{ runner.temp }}/bake-meta.json
targets: ${{ needs.prepare.outputs.bake_target }}
set: |
*.tags=
*.platform=${{ matrix.platform }}
*.output=type=image,"name=${{ env.REGISTRY_IMAGE }}/${{ needs.prepare.outputs.target }}",push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ fromJSON(steps.bake.outputs.metadata)[needs.prepare.outputs.bake_target]['containerimage.digest'] }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Publish Manifest (${{ needs.prepare.outputs.target }})
runs-on: ubuntu-latest
needs:
- prepare
- build
steps:
- name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Authenticate with container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.REGISTRY_IMAGE }}/${{ needs.prepare.outputs.target }}")) | "-t " + .) | join(" ")' ${{ runner.temp }}/bake-meta.json) \
$(printf '${{ env.REGISTRY_IMAGE }}/${{ needs.prepare.outputs.target }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}/${{ needs.prepare.outputs.target }}:$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' ${{ runner.temp }}/bake-meta.json)