-
Notifications
You must be signed in to change notification settings - Fork 2
118 lines (104 loc) · 4.24 KB
/
publish-image-manager.yml
File metadata and controls
118 lines (104 loc) · 4.24 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
# push main/master 或 tag 时:构建并推送 Manager 镜像到 GHCR
name: Publish image (Manager)
on:
push:
branches:
- main
- master
tags:
- 'v*'
workflow_dispatch:
concurrency:
group: publish-manager-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
name: Build and push Manager image
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Verify build context (Dockerfile 所需源码与配置齐全)
id: verify
run: |
set -e
MISSING=""
[ ! -f go.mod ] && MISSING="${MISSING} go.mod"
[ ! -f go.sum ] && MISSING="${MISSING} go.sum"
[ ! -d cmd ] && MISSING="${MISSING} cmd/"
[ ! -d cmd/runner-manager ] && MISSING="${MISSING} cmd/runner-manager/"
[ ! -d internal ] && MISSING="${MISSING} internal/"
[ ! -f config.yaml.example ] && MISSING="${MISSING} config.yaml.example"
[ ! -f scripts/install-runner.sh ] && MISSING="${MISSING} scripts/install-runner.sh"
if [ -z "$MISSING" ]; then
echo "has_go_source=true" >> $GITHUB_OUTPUT
else
echo "has_go_source=false" >> $GITHUB_OUTPUT
echo "::warning::Manager 构建所需文件缺失($MISSING),跳过构建。请在本仓库提交并推送完整源码后再构建。"
fi
- name: Set up QEMU
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute canonical image name (lowercase)
if: steps.verify.outputs.has_go_source == 'true'
id: vars
shell: bash
run: |
set -eu
IMAGE_REF="${IMAGE_NAME:-$GITHUB_REPOSITORY}"
CANONICAL_IMAGE="${REGISTRY}/${IMAGE_REF,,}"
echo "canonical=${CANONICAL_IMAGE}" >> "$GITHUB_OUTPUT"
- name: Get version for build
if: steps.verify.outputs.has_go_source == 'true'
id: version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Extract Docker metadata (tags, labels)
if: steps.verify.outputs.has_go_source == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.vars.outputs.canonical }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short,prefix=sha-
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
# Dockerfile 内已 COPY config.yaml.example 为 config/config.yaml 并 sed,无需在 workflow 中准备
- name: Build and push Manager image
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: ${{ github.workspace }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.version.outputs.version || 'dev' }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max