Repository navigation
117 lines (108 loc) · 4.39 KB
/
Copy pathdocker.yml
File metadata and controls
117 lines (108 loc) · 4.39 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
# Multi-arch image → Docker Hub + GHCR.
# 需要:仓库 Variables 里设 DOCKERHUB_USER;Secrets 里设 DOCKERHUB_TOKEN(Docker Hub Access Token, Read & Write)
# PR 只构建不推送,用来验证 Dockerfile。
name: docker
on:
push:
tags: ["v*"]
pull_request:
paths:
- Dockerfile
- .dockerignore
- docker/**
- go.mod
- go.sum
- .github/workflows/docker.yml
workflow_dispatch:
jobs:
image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # 推 GHCR 用
env:
PUSH: ${{ github.event_name != 'pull_request' }}
VERSION: ${{ github.ref_type == 'tag' && github.ref_name || 'dev' }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: |
docker.io/${{ vars.DOCKERHUB_USER || 'githubflyideas' }}/fogping
ghcr.io/${{ github.repository_owner }}/fogping
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=ref,event=pr
# Smoke amd64 (same VERSION as the later push) before publishing, so a
# broken image is not pushed. The multi-arch push reuses the GHA cache.
- name: Build amd64 image for smoke
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: linux/amd64
load: true
push: false
tags: fogping:smoke
build-args: VERSION=${{ env.VERSION }}
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: smoke test (amd64)
run: |
set -euo pipefail
cleanup() { docker rm -f fp >/dev/null 2>&1 || true; }
trap cleanup EXIT
docker run -d --name fp -p 8518:8518 \
-e FOGPING_EDIT=1 -e FOGPING_USER=admin -e FOGPING_PASSWD=pw \
fogping:smoke
ok=0
for i in $(seq 1 20); do
if curl -fsS http://127.0.0.1:8518/api/version; then
ok=1
break
fi
sleep 1
done
test "$ok" = 1
# Anonymous callers get the version only once a login is configured;
# the instance settings (editable, retention) need a session.
ver=$(curl -fsS http://127.0.0.1:8518/api/version)
echo "$ver"
if echo "$ver" | grep -q '"editable"'; then
echo "::error::anonymous /api/version exposes instance settings"; exit 1
fi
echo "$ver" | grep -F "\"version\":\"${VERSION}\"" >/dev/null || {
echo "::error::version is not ${VERSION}: ${ver}"; exit 1
}
test "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8518/api/targets)" = 401
curl -fsS -c /tmp/fp.cookies -H 'Content-Type: application/json' \
-X POST http://127.0.0.1:8518/api/login \
-d '{"User":"admin","Pass":"pw"}' > /dev/null
curl -fsS -b /tmp/fp.cookies http://127.0.0.1:8518/api/version | grep -q '"editable":true'
docker logs fp
- if: env.PUSH == 'true'
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- if: env.PUSH == 'true'
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ env.PUSH == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ env.VERSION }}
provenance: false # 避免部分平台(如 RouterOS)解析 manifest 时遇到 attestation 条目
cache-from: type=gha
cache-to: type=gha,mode=max