-
Notifications
You must be signed in to change notification settings - Fork 0
309 lines (297 loc) · 9.84 KB
/
ci.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: CI Full Run
on:
pull_request:
branches:
- main
- grok/*/*
push:
branches:
- main
tags:
- "v*"
jobs:
# Tests command-line tool using tests scaffolding.
ci-storage-tool-test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- run: |
exec 2>&1; set -ex
tests/all.sh
# Tests action itself.
ci-storage-action-test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Disable default ci-storage remote host (store locally)
run: |
echo -n "" > ~/ci-storage-host
- name: Create dummy files
run: |
echo "dummy" > dummy.txt
mkdir -p dir/subdir
echo "layer" > dir/subdir/layer.txt
mkdir -p /tmp/dir
echo "local-dir" > /tmp/dir/local-dir.txt
- name: Test store
uses: ./
with:
action: store
storage-dir: ~/storage-dir
sudo: false
hint: |
aaa
@dummy.txt
bbb
run-before: |
set -ex
echo "run-before" > run-before.txt
- name: Test store (layer)
uses: ./
with:
action: store
storage-dir: ~/storage-dir
layer-name: my-layer
layer-include: layer.txt
- name: Test store (custom local-dir)
uses: ./
with:
action: store
storage-dir: ~/storage-dir
local-dir: /tmp/dir
- name: Remove dummy.txt and run-before.txt
run: rm dummy.txt run-before.txt
- name: Test load
uses: ./
with:
action: load
storage-dir: ~/storage-dir
hint: aaa
- name: Check that dummy.txt and run-before.txt were restored
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat dummy.txt)" == "dummy" ]] || { echo "dummy.txt must be restored"; exit 1; }
[[ "$(cat run-before.txt)" == "run-before" ]] || { echo "run-before.txt must be restored"; exit 1; }
- name: Remove dir/subdir/layer.txt
run: rm -rf dir
- name: Test load (layer)
uses: ./
with:
action: load
storage-dir: ~/storage-dir
layer-name: my-layer
- name: Check that dir/subdir/layer.txt was restored, and dummy.txt still exists
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat dummy.txt)" == "dummy" ]] || { echo "dummy.txt must be kept"; exit 1; }
[[ "$(cat dir/subdir/layer.txt)" == "layer" ]] || { echo "layer.txt must be restored"; exit 1; }
- name: Remove /tmp/dir/local-dir.txt
run: rm -rf /tmp/dir/*
- name: Test load (custom local-dir)
uses: ./
with:
action: load
storage-dir: ~/storage-dir
local-dir: /tmp/dir
- name: Check that /tmp/dir/local-dir.txt was restored
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat /tmp/dir/local-dir.txt)" == "local-dir" ]] || { echo "/tmp/dir/local-dir.txt must be restored"; exit 1; }
# Tests ci-scaler logic.
ci-scaler-test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- run: |
exec 2>&1; set -ex
docker/ci-scaler/guest/scaler/tests/all.sh
env:
GH_TOKEN: ${{ secrets.CI_PAT }}
# Builds and boots a ci-runner container inside GitHub's infra. Once it's
# settled, there is a running container with one self-hosted runner waiting
# for jobs with ci-storage-test tag to pick up (based on Dockerfile image).
build-and-boot-containers:
runs-on: ubuntu-latest
needs:
- ci-storage-tool-test
- ci-storage-action-test
- ci-scaler-test
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Start test Docker containers
run: |
exec 2>&1; set -ex
cd docker
# Build all containers.
docker compose build --parallel
# Boot ci-storage container in background.
docker compose up ci-storage -d
# Boot ci-runner container. It connects to ci-storage container and
# load a test (non-existent) ci-storage slot from there, then register
# a GitHub self-hosted runner and remain waiting for jobs.
docker compose up ci-runner
env:
GH_TOKEN: ${{ secrets.CI_PAT }}
GH_REPOSITORY: ${{ github.repository }}
GH_LABELS: ${{ format('ci-storage-test-{0}-{1}', github.run_id, github.run_attempt) }}
TZ: America/Los_Angeles
FORWARD_HOST: host.docker.internal
# Test the job with ci-storage-test tag which is initially queued, but then is
# picked up by the ci-runner container booted in the previous job. In the end,
# the test job sends SIGINT to the container entrypoint.sh PID, so the
# container (based on Dockerfile image) shuts down gracefully.
spawn-job-test:
runs-on:
- self-hosted
- ${{ format('ci-storage-test-{0}-{1}', github.run_id, github.run_attempt) }}
needs:
- ci-storage-tool-test
- ci-storage-action-test
- ci-scaler-test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Run test job inside the self-hosted runner
run: echo "Hello, world!"
- name: Test store using GitHub Action
uses: ./
with:
action: "store"
- name: Kill ci-runner container
run: kill -SIGINT $(cat ~guest/.entrypoint.pid)
# Publishes ci-scaler image.
push-ci-scaler:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs:
- ci-storage-tool-test
- ci-storage-action-test
- ci-scaler-test
- build-and-boot-containers
- spawn-job-test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: |
dimikot/ci-scaler
ghcr.io/${{ github.repository_owner }}/ci-scaler
- uses: docker/login-action@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: docker/ci-scaler
platforms: linux/amd64,linux/arm64,linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: peter-evans/dockerhub-description@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
readme-filepath: docker/ci-scaler/README.md
repository: dimikot/ci-scaler
# Publishes ci-storage image.
push-ci-storage:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs:
- ci-storage-tool-test
- ci-storage-action-test
- ci-scaler-test
- build-and-boot-containers
- spawn-job-test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: |
dimikot/ci-storage
ghcr.io/${{ github.repository_owner }}/ci-storage
- uses: docker/login-action@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: docker/ci-storage
platforms: linux/amd64,linux/arm64,linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: peter-evans/dockerhub-description@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
readme-filepath: docker/ci-storage/README.md
repository: dimikot/ci-storage
# Publishes ci-runner image.
push-ci-runner:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs:
- ci-storage-tool-test
- ci-storage-action-test
- ci-scaler-test
- build-and-boot-containers
- spawn-job-test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: |
dimikot/ci-runner
ghcr.io/${{ github.repository_owner }}/ci-runner
- uses: docker/login-action@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: docker/ci-runner
platforms: linux/amd64,linux/arm64,linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: peter-evans/dockerhub-description@v3
with:
username: dimikot
password: ${{ secrets.DOCKERHUB_PAT }}
readme-filepath: docker/ci-runner/README.md
repository: dimikot/ci-runner