-
Notifications
You must be signed in to change notification settings - Fork 4
380 lines (367 loc) · 11.7 KB
/
deploy.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
name: Deploy
on:
push:
branches: [ main ]
concurrency:
group: deploy
cancel-in-progress: true
env:
PIP_DISABLE_PIP_VERSION_CHECK: yes
jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install build frontend
run: pip install "build==1.*"
- name: Build
run: python -m build
- name: Upload as build artifact
uses: actions/upload-artifact@v4
with:
path: dist
test-wheel:
name: Test wheel
runs-on: ubuntu-latest
needs:
- build
permissions: {}
continue-on-error: ${{ matrix.python-version == 3.13 }}
strategy:
fail-fast: false
matrix:
python-version:
- 3.12
- 3.13
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: artifact
- name: Install libcurl4-openssl-dev for compiling PycURL
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
- name: Install wheel
run: pip install *.whl
- name: Test starting
timeout-minutes: 1
run: python -m an_website -c
tests:
name: Run tests
runs-on: ubuntu-latest
permissions:
contents: read
continue-on-error: ${{ matrix.python-version == 3.13 }}
strategy:
fail-fast: false
matrix:
python-version:
- 3.12
- 3.13
license:
- basic
#- trial
redis-image:
- redis/redis-stack-server:6.2.6-v10
#- docker.dragonflydb.io/dragonflydb/dragonfly
services:
redis:
image: ${{ matrix.redis-image }}
ports:
- 6379:6379
steps:
# - name: Configure sysctl limits
# run: |
# sudo swapoff -a
# sudo sysctl -w vm.swappiness=1
# sudo sysctl -w fs.file-max=262144
# sudo sysctl -w vm.max_map_count=262144
# - name: Start Elasticsearch
# uses: elastic/elastic-github-actions/elasticsearch@2c3ec0418fabc996180995c47b86a65b581f1561
# with:
# stack-version: 8.12.0
# security-enabled: false
# nodes: 3
# license: ${{ matrix.license }}
# plugins: |
# analysis-icu
# analysis-phonetic
# mapper-size
# mapper-murmur3
# mapper-annotated-text
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: Pipfile.lock
- name: Install libcurl4-openssl-dev for compiling PycURL
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
- name: Install requirements
run: pip install -r pip-requirements.txt
- name: Install stuff needed for the tests
run: grep "^pytest-" pip-constraints.txt | xargs pip install -c pip-constraints.txt html5lib pytest time-machine
- name: Run pytest
timeout-minutes: 5
run: pytest --durations=0 --verbose --cov --cov-report=term:skip-covered
- name: Upload coverage as artifact
uses: actions/upload-artifact@v4
with:
path: .coverage
name: coverage
sourcemaps:
name: Upload sourcemaps
runs-on: ubuntu-latest
needs:
- test-wheel
- tests
permissions: {}
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: artifact
- name: Install required library
run: pip install "packaging==23.*"
- name: Version
id: version
shell: python
run: |
import os
from pathlib import Path
from subprocess import run
from packaging.utils import parse_sdist_filename
command = "ls an-website-*.tar.gz"
result = run(command, shell=True, capture_output=True)
filename = result.stdout.decode("UTF-8").strip()
name, version = parse_sdist_filename(filename)
path = Path(os.getenv("GITHUB_OUTPUT"))
path.write_text(f"version={version}\n")
- name: Unpack source distribution
run: tar xvf an-website-*.tar.gz
- name: Upload sourcemaps
run: |
cd an-website-*/an_website
find static/js -type f -name "*.js" -exec \
curl -sSfk https://kibana.asozial.org:5601/api/apm/sourcemaps \
-H "Authorization: ApiKey ${{ secrets.SOURCEMAP_API_KEY }}" \
-H "kbn-xsrf: true" \
-F service_name="an-website" \
-F service_version="${{ steps.version.outputs.version }}" \
-F bundle_filepath="/{}" \
-F sourcemap=@{}.map \;
deploy:
name: Deploy website
runs-on: ubuntu-latest
needs:
- test-wheel
- tests
permissions: {}
environment:
name: production
url: https://asozial.org
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: artifact
- name: Deploy website
run: |
curl -sSf -T *.whl https://asozial.org/api/update/ \
-H "Authorization: ${{ secrets.UPDATE_API_SECRET }}"
github-pages:
name: GitHub Pages
runs-on: ubuntu-latest
needs:
- deploy
permissions:
contents: read
id-token: write
pages: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
cache-dependency-path: Pipfile.lock
- name: Download coverage
uses: actions/download-artifact@v4
with:
name: coverage
- name: Make directory
run: mkdir github-pages
- name: Hash files
run: ./scripts/hash_files.py > github-pages/hashes.txt
- name: Install Coverage.py
run: pip install -c pip-constraints.txt coverage
- name: Create coverage files
run: |
coverage html -d github-pages/coverage
coverage json -o github-pages/coverage.json
./generate-badge.sh > github-pages/coverage/badge.svg
rm -f github-pages/coverage/.gitignore
- name: Generate commitment.txt
run: git log "--pretty=%H %ct %s" > github-pages/commitment.txt
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v1
with:
path: github-pages
- name: Deploy GitHub Pages site
id: deployment
uses: actions/deploy-pages@v1
build-oci-image:
name: Build OCI image
runs-on: ubuntu-latest
needs:
- build
permissions:
packages: write
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ~1.20
- name: Upgrade Buildah
run: |
sudo apt-get update
sudo apt-get install -y libapparmor-dev libdevmapper-dev libglib2.0-dev libgpgme-dev libseccomp-dev libselinux1-dev
git clone -b v1.34.0 --depth=1 https://github.com/containers/buildah.git ~/go/src/github.com/containers/buildah
pushd ~/go/src/github.com/containers/buildah
make buildah docs
sudo make install
buildah version
popd
- name: Download youki
run: |
VERSION_U_005F_LL=$(echo $VERSION_U_002E_FS|sed "s/\./_/g")
wget https://github.com/containers/youki/releases/download/v${VERSION_U_002E_FS}/youki_${VERSION_U_005F_LL}_linux.tar.gz
tar xOf youki_${VERSION_U_005F_LL}_linux.tar.gz youki_${VERSION_U_005F_LL}_linux/youki-${VERSION_U_002E_FS}/youki > /opt/youki
rm -f youki_${VERSION_U_005F_LL}_linux.tar.gz
chmod +x /opt/youki
env:
VERSION_U_002E_FS: 0.3.0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install Setuptools
run: pip install "setuptools==69.*"
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: artifact
- name: Extract source distribution
run: |
tar xvf *.tar.gz
rm -f *.tar.gz
- name: Build image
run: |
cd an-website*
sudo ./build-oci-image.sh -t an-website
cd ..
env:
BUILDAH_RUNTIME: /opt/youki
- name: Save image
run: sudo buildah push --all --format=oci --compression-format=zstd:chunked --compression-level=20 an-website oci-archive:oci-archive.tar
- name: Upload as build artifact
uses: actions/upload-artifact@v4
with:
name: oci-image
path: oci-archive.tar
test-running-oci-image:
name: Test running OCI image
runs-on: ubuntu-latest
needs:
- build-oci-image
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: oci-image
- name: Run image
timeout-minutes: 1
run: sudo podman run --network=host -t oci-archive:oci-archive.tar -c
run-tests-in-oci-image:
name: Run tests in OCI image
runs-on: ubuntu-latest
needs:
- build-oci-image
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: oci-image
- name: Run tests
timeout-minutes: 20
run: sudo podman run --network=host -t -v ./pip-constraints.txt:/pip-constraints.txt:z,ro -v ./tests:/tests:z,ro --entrypoint=/bin/sh oci-archive:oci-archive.tar -c "grep -P '^pytest-(?!cov)' /pip-constraints.txt | xargs /venv/bin/pip install --disable-pip-version-check -c /pip-constraints.txt html5lib pytest time-machine && /venv/bin/pytest --verbose /tests"
push-oci-image:
name: Push OCI image
runs-on: ubuntu-latest
needs:
- test-running-oci-image
- run-tests-in-oci-image
permissions:
packages: write
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ~1.20
- name: Upgrade Skopeo
run: |
sudo apt-get update
sudo apt-get install -y libdevmapper-dev libgpgme-dev
git clone -b v1.14.0 --depth=1 https://github.com/containers/skopeo.git ~/go/src/github.com/containers/skopeo
pushd ~/go/src/github.com/containers/skopeo
make bin/skopeo
sudo make install DISABLE_DOCS=1
skopeo --version
popd
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: oci-image
- name: Log in to ghcr.io
uses: redhat-actions/podman-login@v1
with:
username: ${{ github.actor }}
password: ${{ github.token }}
registry: ghcr.io/${{ github.repository }}
- name: Push image to ghcr.io
run: skopeo copy --all --preserve-digests oci-archive:oci-archive.tar docker://ghcr.io/${{ github.repository }}:dev