Repository navigation
347 lines (306 loc) · 12.7 KB
/
Copy pathbuild_docker.yml
File metadata and controls
347 lines (306 loc) · 12.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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
name: Build Docker images
on:
push:
branches:
- main
- release
pull_request:
release:
types:
- published
workflow_dispatch:
permissions: {}
jobs:
test-macos:
name: Test on macOS
runs-on: macos-latest
env:
UV_LOCKED: true # Assert that uv.lock is up-to-date
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "stable"
# We don't use `make install` because it requires user input
# Instead, we manually sync and run a subset of commands
- name: Install dependencies
run: uv sync --all-groups
- name: Install workers
run: uv run scripts/ci/workers.sh dev
- name: Install nltk
run: |
uv run python -m nltk.downloader stopwords
uv run python -m nltk.downloader punkt
uv run python -m nltk.downloader popular
uv run python -m nltk.downloader universal_tagset
test-e2e:
name: End-to-end test (Docker)
runs-on: ubuntu-latest
steps:
- name: Remove unnecessary files from the base image
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract project version
id: version
run: |
VERSION=$(python -c "exec(open('metadata.py').read()); print(__version__)")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Using version: $VERSION"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: setup-buildx
- name: Build database container
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/database/Dockerfile
build-args: |
VERSION=${{ steps.version.outputs.version }}
REVISION=${{ github.sha }}
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss-database:test
cache-from: type=gha,scope=container-database
cache-to: type=gha,scope=container-database,mode=min
load: true
- name: Build keyman container
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/keyman/Dockerfile
build-args: |
VERSION=${{ steps.version.outputs.version }}
REVISION=${{ github.sha }}
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss-keyman:test
cache-from: type=gha,scope=container-keyman
cache-to: type=gha,scope=container-keyman,mode=min
load: true
- name: Build backend container
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/backend/Dockerfile
build-args: |
VERSION=${{ steps.version.outputs.version }}
REVISION=${{ github.sha }}
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss:test
cache-from: type=gha,scope=container-backend
cache-to: type=gha,scope=container-backend,mode=min
load: true
- name: Prepare compose file
run: |
yq eval -i '.services.core.image = "ghcr.io/${{ github.repository_owner }}/collectoss:test"' docker-compose.yml
yq eval -i '.services.core.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.core.restart = "no"' docker-compose.yml
yq eval -i '.services.database.image = "ghcr.io/${{ github.repository_owner }}/collectoss-database:test"' docker-compose.yml
yq eval -i '.services.database.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.database.restart = "no"' docker-compose.yml
yq eval -i '.services.keyman.image = "ghcr.io/${{ github.repository_owner }}/collectoss-keyman:test"' docker-compose.yml
yq eval -i '.services.keyman.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.keyman.restart = "no"' docker-compose.yml
- name: Setup Docker Compose
uses: docker/setup-compose-action@v1
with:
version: latest
- name: Set up list of log lines to match
run: |
cat <<EOF > /tmp/regex_matches.txt
Gunicorn webserver started
Starting core worker processes
Starting secondary worker processes
Starting facade worker processes
Retrieved \\d+ github api keys for use
Fetching new repos \\(complete\\)
Inserting \\d+ contributors
Inserting \\d+ issues
Inserting prs of length: \\d+
Querying committers count
Done generating scc data for repo
Sending due task
EOF
- name: Start services & wait for output
# This starts the system and sends the output to "await_all.py" which
# scans for the regex matches from above. Once all matches are seen at
# least once, the `compose down` will run to shut down the system. If
# this all doesn't happen before the timeout, the job will fail.
run: |
docker compose -f docker-compose.yml up --no-build 2>&1 \
| (./scripts/ci/await_all.py /tmp/regex_matches.txt \
&& docker compose -f docker-compose.yml down)
timeout-minutes: 8
env:
COLLECTOSS_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
COLLECTOSS_GITHUB_USERNAME: ${{ github.repository_owner }}
COLLECTOSS_GITLAB_API_KEY: dummy
COLLECTOSS_GITLAB_USERNAME: dummy
- name: Dump logs
# Always run this step to get logs, even if the previous step fails
if: always()
# We use tail so that we can see the name of each file as it's printed
run: "docker run -t --rm -v augur_logs:/logs bash -c 'find /logs -type f | xargs
tail -n +0'"
test-e2e-podman:
name: End-to-end test (Podman)
# ubuntu-latest (26.04) breaks rootless Podman network teardown
runs-on: ubuntu-24.04
steps:
- name: Remove unnecessary files from the base image
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Start Podman socket
run: systemctl --user start podman.socket
- name: Checkout repository
uses: actions/checkout@v4
- name: Build database container
uses: redhat-actions/buildah-build@v2
with:
context: .
containerfiles: |
./docker/database/Dockerfile
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss-database:test
layers: true
- name: Build keyman container
uses: redhat-actions/buildah-build@v2
with:
context: .
containerfiles: |
./docker/keyman/Dockerfile
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss-keyman:test
layers: true
- name: Build backend container
uses: redhat-actions/buildah-build@v2
with:
context: .
containerfiles: |
./docker/backend/Dockerfile
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/collectoss:test
layers: true
- name: Prepare compose file
run: |
yq eval -i '.services.core.image = "ghcr.io/${{ github.repository_owner }}/collectoss:test"' docker-compose.yml
yq eval -i '.services.core.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.core.restart = "no"' docker-compose.yml
yq eval -i '.services.database.image = "ghcr.io/${{ github.repository_owner }}/collectoss-database:test"' docker-compose.yml
yq eval -i '.services.database.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.database.restart = "no"' docker-compose.yml
yq eval -i '.services.keyman.image = "ghcr.io/${{ github.repository_owner }}/collectoss-keyman:test"' docker-compose.yml
yq eval -i '.services.keyman.pull_policy = "never"' docker-compose.yml
yq eval -i '.services.keyman.restart = "no"' docker-compose.yml
- name: Setup Podman Compose
uses: webgtx/setup-podman-compose@v1
- name: Set up list of log lines to match
run: |
cat <<EOF > /tmp/regex_matches.txt
Gunicorn webserver started
Starting core worker processes
Starting secondary worker processes
Starting facade worker processes
Retrieved \\d+ github api keys for use
Fetching new repos \\(complete\\)
Inserting \\d+ contributors
Inserting \\d+ issues
Inserting prs of length: \\d+
Querying committers count
Done generating scc data for repo
Sending due task
EOF
- name: Start services & wait for output
# This starts the system and sends the output to "await_all.py" which
# scans for the regex matches from above. Once all matches are seen at
# least once, the `compose down` will run to shut down the system. If
# this all doesn't happen before the timeout, the job will fail.
run: |
podman compose -f docker-compose.yml up --no-build 2>&1 \
| (./scripts/ci/await_all.py /tmp/regex_matches.txt \
&& podman compose -f docker-compose.yml down)
timeout-minutes: 8
env:
COLLECTOSS_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
COLLECTOSS_GITHUB_USERNAME: ${{ github.repository_owner }}
COLLECTOSS_GITLAB_API_KEY: dummy
COLLECTOSS_GITLAB_USERNAME: dummy
- name: Dump logs
# Always run this step to get logs, even if the previous step fails
if: always()
# We use tail so that we can see the name of each file as it's printed
run:
"podman run -t --rm -v augur_logs:/logs bash -c 'find /logs -type f | xargs
tail -n +0'"
push-image:
name: Push image
needs: test-e2e
# We don't push images on pull requests
if: github.event_name != 'pull_request'
permissions:
contents: read # to fetch code (actions/checkout)
packages: write # to push docker image
strategy:
matrix:
image:
- name: collectoss
folder: backend
- name: collectoss-database
folder: database
- name: collectoss-keyman
folder: keyman
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: setup-buildx
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container metadata
uses: docker/metadata-action@v5
id: meta
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: index,manifest
with:
annotations: |
org.opencontainers.image.title=${{ matrix.image.name }}
labels: |
org.opencontainers.image.title=${{ matrix.image.name }}
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image.name }}
# Pushes to the main branch update the *:devel-latest tag
# Releases update the *:latest tag and the *:<version> tag
tags: |
type=raw,value=devel-latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=raw,value=${{ github.event.release.tag_name }},enable=${{ github.event_name == 'release' }}
- name: Build and push
id: push
uses: docker/build-push-action@v6
with:
annotations: ${{ steps.meta.outputs.annotations }}
context: .
file: ./docker/${{ matrix.image.folder }}/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
# Only push if we've tagged the image in the metadata step
push: ${{ steps.meta.outputs.tags != '' }}
tags: ${{ steps.meta.outputs.tags }}
# Use the same cache as the build step
cache-from: type=gha,scope=container-${{ matrix.image.name }}
cache-to: type=gha,scope=container-${{ matrix.image.name }},mode=min