-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (51 loc) · 2.29 KB
/
push_ayl.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
53
54
55
56
57
58
59
60
61
name: Docker pull push
on:
workflow_dispatch:
repository_dispatch:
types:
- webhook-1
push:
branches: [ main ]
paths:
- 'images.txt'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Build the Docker image
run: |
sudo systemctl stop docker
sudo mkdir -p /mnt/lib/docker
echo '{ "exec-opts": ["native.cgroupdriver=cgroupfs"], "cgroup-parent": "/actions_job","data-root": "/mnt/lib/docker"}' | sudo tee /etc/docker/daemon.json > /dev/null
sudo systemctl daemon-reload
sudo systemctl start docker
# 钉钉机器人 Webhook 地址
dd_sign=${{secrets.DD_SIGN}}
dd_token=${{secrets.DD_TOKEN}}
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=$dd_token"
# 登录阿里云镜像仓库
docker login --username=${{secrets.ALIYUNCS_USERNAME}} --password=${{secrets.ALIYUNCS_PASSWORD}} registry.cn-hangzhou.aliyuncs.com
echo "------------------------------------------------------------------------------------------" >> log.txt
# 遍历 images.txt 进行pull push
while IFS= read -r img; do
OLD_IMAGE=$img
NEW_IMAGE_VERSION=$(echo "$OLD_IMAGE" | sed 's/[/:]/-/g')
NEW_IMAGE=registry.cn-hangzhou.aliyuncs.com/jiro-jlzhang/common:$NEW_IMAGE_VERSION
docker pull $OLD_IMAGE
docker tag $OLD_IMAGE $NEW_IMAGE
docker push $NEW_IMAGE
docker rmi $NEW_IMAGE $OLD_IMAGE
# 计算签名
# timestamp=$(date +%s)
# sign=$(echo -n "${timestamp}\n${dd_sign}" | openssl sha256 | awk '{print $2}')
# 消息内容
message=$(printf '{"msgtype": "text", "text": {"content": "github:\n %s \n %s"}}' "$OLD_IMAGE" "$NEW_IMAGE")
# curl -H "Content-Type: application/json" -X POST -d "$message" -H "Timestamp: $timestamp" -H "Sign: $sign" "$webhook_url"
curl -H "Content-Type: application/json" -X POST -d "$message" "$webhook_url"
# log
image_log="${OLD_IMAGE} -> ${NEW_IMAGE}"
echo "$image_log" >> log.txt
done < images.txt
cat log.txt