Skip to content

Commit c7cdf7c

Browse files
committed
ci: build + smoke-test the docker image, push to GHCR on tags
1 parent 17315f9 commit c7cdf7c

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

‎.github/workflows/docker.yml‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: docker
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
tags: ["v*"]
7+
pull_request:
8+
workflow_call:
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
jobs:
15+
docker:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: docker/setup-buildx-action@v3
21+
22+
- id: meta
23+
uses: docker/metadata-action@v5
24+
with:
25+
images: ghcr.io/${{ github.repository }}
26+
tags: |
27+
type=sha
28+
type=ref,event=pr
29+
type=semver,pattern={{version}}
30+
type=semver,pattern={{major}}.{{minor}}
31+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
32+
33+
- name: Build (load locally, no push)
34+
uses: docker/build-push-action@v6
35+
with:
36+
context: .
37+
platforms: linux/amd64
38+
load: true
39+
push: false
40+
tags: ${{ steps.meta.outputs.tags }}
41+
labels: ${{ steps.meta.outputs.labels }}
42+
cache-from: type=gha
43+
cache-to: type=gha,mode=max
44+
45+
- name: Smoke test
46+
run: |
47+
IMAGE=$(printf '%s\n' "${{ steps.meta.outputs.tags }}" | head -n1)
48+
echo "Smoke-testing $IMAGE"
49+
docker run -d --name smoke -p 8000:8000 \
50+
-e AGORA_APP_ID=0123456789abcdef0123456789abcdef \
51+
-e AGORA_APP_CERTIFICATE=fedcba9876543210fedcba9876543210 \
52+
"$IMAGE"
53+
set +e
54+
fail=0
55+
for url in http://localhost:8000/get_config; do
56+
ok=""
57+
for i in $(seq 1 40); do
58+
if curl -fsS "$url" -o /dev/null; then ok=1; echo "OK $url"; break; fi
59+
sleep 1
60+
done
61+
if [ -z "$ok" ]; then echo "FAIL $url"; fail=1; fi
62+
done
63+
if [ "$fail" -ne 0 ]; then docker logs smoke; fi
64+
docker rm -f smoke
65+
exit $fail
66+
67+
- name: Log in to GHCR
68+
if: startsWith(github.ref, 'refs/tags/')
69+
uses: docker/login-action@v3
70+
with:
71+
registry: ghcr.io
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Push tags
76+
if: startsWith(github.ref, 'refs/tags/')
77+
run: |
78+
printf '%s\n' "${{ steps.meta.outputs.tags }}" | while read -r tag; do
79+
[ -n "$tag" ] && docker push "$tag"
80+
done

0 commit comments

Comments
 (0)