GitHub Actions 构建镜像且同步到阿里云多个 ACR

GitHub Actions 构建镜像且同步到阿里云多个 ACR

.github/workflows/acr.yml

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
name: Acr

on:
push:
branches:
- main

jobs:
# 构建镜像,然后上传
Build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Run
run: |
cd $GITHUB_WORKSPACE
podman build --no-cache -t $GITHUB_REPOSITORY:$GITHUB_REF_NAME .
podman save $GITHUB_REPOSITORY:$GITHUB_REF_NAME -o image.tar
- uses: actions/upload-artifact@v3
with:
name: image
path: image.tar
retention-days: 1

# 下载镜像,然后同时推送
Push:
runs-on: ubuntu-22.04
needs: [Build]
strategy:
matrix:
name: [hongfs/tools] # 仓库名称
region: [cn-shenzhen, cn-hangzhou] # 仓库地域
steps:
- uses: actions/download-artifact@v3
with:
name: image
- name: Run
run: |
echo "---这里你要替换成登录操作---"

podman load -i image.tar
podman tag $GITHUB_REPOSITORY:$GITHUB_REF_NAME registry.${{ matrix.region }}.aliyuncs.com/${{ matrix.name }}:$GITHUB_REF_NAME
podman push registry.${{ matrix.region }}.aliyuncs.com/${{ matrix.name }}:$GITHUB_REF_NAME

# 删除镜像
Delete:
runs-on: ubuntu-22.04
needs: [Push]
steps:
- uses: geekyeggo/delete-artifact@v2
with:
name: image
往上