-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 2.41 KB
/
docker-image.yml
File metadata and controls
85 lines (75 loc) · 2.41 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
name: Publish Docker image
on:
push:
branches: ["main", "dev", "oc", "test", "develop"]
tags: ["v*.*.*"]
pull_request:
branches: ["main", "dev", "oc", "test", "develop"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# 阿里云镜像仓库地址
ALIYUN_REGISTRY: ${{ secrets.ALIYUN_REGISTRY }}
ALIYUN_IMAGE: ${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_NAMESPACE }}/local_agent
jobs:
push_to_registry:
name: Push Docker image to GHCR and Aliyun
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
# ✅ 登录 GHCR
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# ✅ 登录阿里云容器镜像服务
- name: Log in to Aliyun Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PASSWORD }}
# ✅ 为 GHCR 提取 metadata
- name: Extract metadata for GHCR
id: meta-ghcr
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag
type=ref,event=branch
# ✅ 为阿里云提取 metadata
- name: Extract metadata for Aliyun
id: meta-aliyun
uses: docker/metadata-action@v5
with:
images: ${{ env.ALIYUN_IMAGE }}
tags: |
type=ref,event=tag
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# ✅ 同时推送到 GHCR 和阿里云
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
# 合并两个仓库的 tags
tags: |
${{ steps.meta-ghcr.outputs.tags }}
${{ steps.meta-aliyun.outputs.tags }}
labels: ${{ steps.meta-ghcr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
shm-size: 2g