Repository navigation
82 lines (74 loc) · 2.75 KB
/
Copy pathdocker.yml
File metadata and controls
82 lines (74 loc) · 2.75 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
# 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' }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- if: env.PUSH == 'true'
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- if: env.PUSH == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
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
- uses: docker/build-push-action@v6
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=${{ github.ref_type == 'tag' && github.ref_name || 'dev' }}
provenance: false # 避免部分平台(如 RouterOS)解析 manifest 时遇到 attestation 条目
cache-from: type=gha
cache-to: type=gha,mode=max
# 冒烟测试:amd64 单架构 load 到本地,起容器打 /api/version
- name: smoke test (amd64)
run: |
docker buildx build --load --platform linux/amd64 -t fogping:smoke --cache-from type=gha .
docker run -d --name fp -p 8518:8518 \
-e FOGPING_EDIT=1 -e FOGPING_USER=admin -e FOGPING_PASSWD=pw \
fogping:smoke
for i in $(seq 1 20); do
curl -fsS http://127.0.0.1:8518/api/version && break
sleep 1
done
curl -fsS http://127.0.0.1:8518/api/version | grep -q '"editable":true'
test "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8518/api/targets)" = 401
docker logs fp