-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (94 loc) · 3.05 KB
/
Copy pathdocker-build.yml
File metadata and controls
108 lines (94 loc) · 3.05 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
name: Docker JobAgent
on:
push:
# branches:
# - "**"
tags:
- "v*"
workflow_dispatch:
env:
# 两个镜像前缀
DOCKERHUB_REPO: aicrosoft/jobagent
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/jobagent
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # ③ 允许写包
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set Version
id: set_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BASE_VERSION="0.0.1-alpha" # alpha version
REF="${GITHUB_REF}"
# Use tag version
if [[ "$REF" == refs/tags/* ]]; then
TAG_NAME="${REF#refs/tags/}"
TAG_VERSION="${TAG_NAME#[vV]}" # 去掉 v/V 前缀
VERSION="$TAG_VERSION"
echo "Detected tag: $TAG_NAME -> VERSION=$VERSION"
else
VERSION="$BASE_VERSION"
echo "No tag detected. Using base version: VERSION=$VERSION"
fi
# set outputs for version
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Docker Tag Version
run: |
echo "Docker Tag: ${{ steps.set_version.outputs.version }} "
- name: set lowercase image name
run: |
echo "GHCR_REPO_LC=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/jobagent" >> $GITHUB_ENV
# 1. 登录 DockerHub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 2. 登录 GitHub Packages
- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# ========== A) 构建 chiseled 瘦镜像 ==========
- name: Build & push chiseled
uses: docker/build-push-action@v4
with:
context: .
file: build/scripts/Dockerfile
target: chiseled
push: true
tags: |
${{ env.DOCKERHUB_REPO }}:latest
${{ env.DOCKERHUB_REPO }}:${{ steps.set_version.outputs.version }}
${{ env.GHCR_REPO_LC }}:latest
${{ env.GHCR_REPO_LC }}:${{ steps.set_version.outputs.version }}
# ========== B) 构建 secure 镜像 ==========
- name: Build & push debug
uses: docker/build-push-action@v4
with:
context: .
file: build/scripts/Dockerfile
target: secure
push: true
tags: |
${{ env.DOCKERHUB_REPO }}:secure
${{ env.GHCR_REPO_LC }}:secure
# ========== B) 构建 debug 镜像 ==========
- name: Build & push debug
uses: docker/build-push-action@v4
with:
context: .
file: build/scripts/Dockerfile
target: debug
push: true
tags: |
${{ env.DOCKERHUB_REPO }}:debug
${{ env.GHCR_REPO_LC }}:debug