-
Notifications
You must be signed in to change notification settings - Fork 8
127 lines (108 loc) · 3.43 KB
/
Copy pathdocker.yml
File metadata and controls
127 lines (108 loc) · 3.43 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
name: Docker Images
on:
push:
branches:
- master
workflow_dispatch:
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TEST_IMAGE: keycast-ci-smoke:${{ github.sha }}
jobs:
build:
name: Build and publish Keycast image
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=master,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=sha,prefix=sha-,format=short
- name: Build image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
load: true
tags: |
${{ env.TEST_IMAGE }}
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke test API image
run: |
set -euo pipefail
tmpdir="$(mktemp -d)"
cleanup() {
docker rm -f keycast-api-smoke >/dev/null 2>&1 || true
rm -rf "$tmpdir"
}
trap cleanup EXIT
mkdir -p "$tmpdir/database"
cp -R database/migrations "$tmpdir/database/migrations"
chmod 777 "$tmpdir/database"
chmod -R a+rX "$tmpdir/database/migrations"
openssl rand 32 | base64 > "$tmpdir/master.key"
chmod 644 "$tmpdir/master.key"
docker run -d \
--name keycast-api-smoke \
--read-only \
--tmpfs /tmp:size=64m,mode=1777 \
-e ALLOWED_PUBKEYS=abcdef \
-v "$tmpdir/database:/app/database" \
-v "$tmpdir/master.key:/app/master.key:ro" \
"${TEST_IMAGE}" api
for _ in {1..30}; do
if docker exec keycast-api-smoke /usr/local/bin/healthcheck.sh api; then
exit 0
fi
sleep 1
done
docker logs keycast-api-smoke
exit 1
- name: Smoke test web image
run: |
set -euo pipefail
cleanup() {
docker rm -f keycast-web-smoke >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker run -d \
--name keycast-web-smoke \
--read-only \
--tmpfs /tmp:size=64m,mode=1777 \
-e HOST=0.0.0.0 \
-e PORT=5173 \
"${TEST_IMAGE}" web
for _ in {1..30}; do
if docker exec keycast-web-smoke /usr/local/bin/healthcheck.sh web; then
exit 0
fi
sleep 1
done
docker logs keycast-web-smoke
exit 1
- name: Push image tags
run: |
set -euo pipefail
while IFS= read -r tag; do
[ -z "$tag" ] || docker push "$tag"
done <<< "${{ steps.meta.outputs.tags }}"