-
Notifications
You must be signed in to change notification settings - Fork 76
121 lines (108 loc) · 3.72 KB
/
Copy pathbuild-docker.yml
File metadata and controls
121 lines (108 loc) · 3.72 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
# 仅手动触发:选择分支或 tag 后,用 matrix 在 amd64 / arm64 两台机器上并行构建,再合并为多架构镜像
# 公开仓库:GitHub Actions 免费(含 matrix 多 job)
name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
ref:
description: 'Branch 或 Tag(例如 main、v0.1.2)'
required: true
default: 'main'
type: string
env:
REGISTRY: ghcr.io
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
image: ${{ steps.image.outputs.image }}
add_latest: ${{ steps.version.outputs.add_latest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Set version and image
id: version
run: |
REF="${{ inputs.ref }}"
V=$(echo "$REF" | tr -d ' \n\r' | sed 's/[^a-zA-Z0-9_.-]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
echo "version=${V:-dev}" >> $GITHUB_OUTPUT
[ "$REF" = "main" ] || [ "$REF" = "master" ] && echo "add_latest=true" >> $GITHUB_OUTPUT || echo "add_latest=false" >> $GITHUB_OUTPUT
echo "Build ref: $REF -> image tag: ${V:-dev}"
- name: Set image name
id: image
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
echo "image=${{ env.REGISTRY }}/${OWNER}/yt-navigator" >> $GITHUB_OUTPUT
build:
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
suffix: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
suffix: arm64
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push (${{ matrix.suffix }})
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: ${{ needs.prepare.outputs.image }}:${{ needs.prepare.outputs.version }}-${{ matrix.suffix }}
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PYTHON_VERSION=3.13.2
merge:
needs: [prepare, build]
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest (version + latest)
run: |
IMAGE="${{ needs.prepare.outputs.image }}"
V="${{ needs.prepare.outputs.version }}"
docker manifest create "${IMAGE}:${V}" \
"${IMAGE}:${V}-amd64" \
"${IMAGE}:${V}-arm64"
docker manifest push "${IMAGE}:${V}"
echo "Pushed ${IMAGE}:${V}"
if [ "${{ needs.prepare.outputs.add_latest }}" = "true" ]; then
docker manifest create "${IMAGE}:latest" \
"${IMAGE}:${V}-amd64" \
"${IMAGE}:${V}-arm64"
docker manifest push "${IMAGE}:latest"
echo "Pushed ${IMAGE}:latest"
fi