-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (181 loc) · 6.61 KB
/
build.yml
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
205
206
207
208
209
210
211
212
name: Build Image
on:
push:
branches:
- main
jobs:
build-amd64:
name: amd64 image
runs-on: ubuntu-latest
permissions:
packages: write
actions: write
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
ref: "${{ inputs.ref }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: 'amd64'
- name: Login to registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}
- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
- name: Setup cache save
uses: actions/cache@v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.next_rn }}
save-always: true
- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build Rust licenses
run: |
(cd ./server && cargo install cargo-bundle-licenses && cargo bundle-licenses --format json --output ../ui/static/licenses/server-licenses.json)
ls -lah ./ui/static/licenses
cat ./ui/static/licenses/server-licenses.json | tail -n 50
- name: Build and push
uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 # v6
with:
push: true
provenance: false
context: "{{defaultContext}}"
tags: "ghcr.io/bradenrayhorn/mise:building-block-amd64-${{ github.sha }}"
platforms: linux/amd64
cache-from: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-amd64
cache-to: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-amd64,mode=max
build-arm64:
name: arm64 image
runs-on: ubuntu-latest
permissions:
packages: write
actions: write
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
ref: "${{ inputs.ref }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: 'arm64'
- name: Login to registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}
- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
- name: Setup cache save
uses: actions/cache@v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.next_rn }}
save-always: true
- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build Rust licenses
working-directory: ./server
run: cargo install cargo-bundle-licenses && cargo bundle-licenses --format json --output ../ui/static/licenses/server-licenses.json
- name: Build and push
uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 # v6
with:
push: true
provenance: false
context: "{{defaultContext}}"
tags: "ghcr.io/bradenrayhorn/mise:building-block-arm64-${{ github.sha }}"
platforms: linux/arm64
cache-from: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-arm64
cache-to: type=registry,ref=ghcr.io/bradenrayhorn/mise:buildcache-arm64,mode=max
retag-next:
name: Push multiarch image
runs-on: ubuntu-latest
permissions:
packages: write
needs: [build-arm64, build-amd64]
steps:
- name: Login to registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
- name: Retag
run: |
IMAGE=ghcr.io/bradenrayhorn/mise
docker buildx imagetools create \
--tag $IMAGE:next \
--tag $IMAGE:next-${{ github.sha }} \
$IMAGE:building-block-amd64-${{ github.sha }} \
$IMAGE:building-block-arm64-${{ github.sha }}