forked from tech-shrimp/docker_image_pusher
-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (45 loc) · 1.74 KB
/
docker.yaml
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: Docker
on:
workflow_dispatch:
push:
branches: [ main ]
env:
ALIYUN_REGISTRY: "${{ secrets.ALIYUN_REGISTRY }}"
ALIYUN_NAME_SPACE: "${{ secrets.ALIYUN_NAME_SPACE }}"
ALIYUN_REGISTRY_USER: "${{ secrets.ALIYUN_REGISTRY_USER }}"
ALIYUN_REGISTRY_PASSWORD: "${{ secrets.ALIYUN_REGISTRY_PASSWORD }}"
jobs:
build:
name: Pull
runs-on: ubuntu-latest
steps:
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout Code
uses: actions/checkout@v4
- name: Build and push image Aliyun
run: |
docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY
while IFS= read -r line; do
[[ -z "$line" ]] && continue
echo "docker pull $line"
docker pull $line
platform=$(echo "$line" | awk -F'--platform[ =]' '{if (NF>1) print $2}' | awk '{print $1}')
echo "platform is $platform"
# 如果存在架构信息 将架构信息拼到镜像名称前面
if [ -z "$platform" ]; then
platform_prefix=""
else
platform_prefix="${platform//\//_}_"
fi
echo "platform_prefix is $platform_prefix"
# 获取镜像的完整名称,例如kasmweb/nginx:1.25.3(命名空间/镜像名:版本号)
image=$(echo "$line" | awk '{print $NF}')
# 获取 镜像名:版本号 例如nginx:1.25.3
image_name_tag=$(echo "$image" | awk -F'/' '{print $NF}')
new_image="$ALIYUN_REGISTRY/$ALIYUN_NAME_SPACE/$platform_prefix$image_name_tag"
echo "docker tag $image $new_image"
docker tag $image $new_image
echo "docker push $new_image"
docker push $new_image
done < images.txt