-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (108 loc) · 3.95 KB
/
docker-image.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
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
109
110
111
112
113
114
115
116
name: BetaGo
on:
push:
branches: [master]
paths-ignore:
- "neteaseapi/netease-api-service/*"
- "qqmusicapi/qqmusic-api-service/*"
- "README.md"
pull_request:
branches: [master]
paths-ignore:
- "neteaseapi/netease-api-service/*"
- "qqmusicapi/qqmusic-api-service/*"
- "README.md"
workflow_dispatch:
inputs:
name:
description: "触发用途"
required: true
default: "测试"
env:
IMAGE_NAME: kevinmatt/betago
ROBOT_NAME: BetaGo
TEST_CHAN_ID: "4988093461275944"
ROBOT_ID: "3508390651"
TENCENT_HEADER: ccr.ccs.tencentyun.com
REGISTRY: ghcr.io
jobs:
Build_Push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Log into registry ghcr.io
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log into registry dockerhub
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
username: kevinmatt
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Log into registry tencentcloud
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ccr.ccs.tencentyun.com
username: "100016072032"
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Build image
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
retry_wait_seconds: 15
command: |
zip \
-r \
-9 \
-q betago.zip \
. \
-x ".git/*" \
-x "qqmusicapi/qqmusic-api-service/*" \
-x "neteaseapi/netease-api-service/*"
DOCKER_BUILDKIT=1 docker build \
--build-arg ROBOT_NAME=$ROBOT_NAME \
--build-arg TEST_CHAN_ID=$TEST_CHAN_ID \
--build-arg ROBOT_ID=$ROBOT_ID \
--build-arg GITHUB_SHA=$GITHUB_SHA \
. \
--file scripts/betago/Dockerfile \
--tag $IMAGE_NAME
- name: Push image
if: github.event_name != 'pull_request'
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
retry_wait_seconds: 15
command: |
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
#将current转换为时间戳,精确到毫秒
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
IMAGE_ID=$IMAGE_NAME
# 将所有的大写字母转为小写
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# 从 tag 名字中替换 v 字符
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# 设置镜像 id 和版本号
docker tag $IMAGE_NAME $IMAGE_NAME:latest
# 进行 push
docker push $IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest $IMAGE_NAME:latest-$currentTimeStamp
docker push $IMAGE_NAME:latest-$currentTimeStamp
# docker tag $IMAGE_NAME:latest $TENCENT_HEADER/$IMAGE_NAME:latest
# docker push $TENCENT_HEADER/$IMAGE_NAME:latest
# docker tag $TENCENT_HEADER/$IMAGE_NAME:latest $TENCENT_HEADER/$IMAGE_NAME:latest-$currentTimeStamp
# docker push $TENCENT_HEADER/$IMAGE_NAME:latest-$currentTimeStamp
- name: Gotify Notification
uses: eikendev/gotify-action@master
if: github.event_name != 'pull_request'
with:
gotify_api_base: '${{ secrets.GOTIFY_URL }}'
gotify_app_token: '${{ secrets.GOTIFY_APP_TOKEN }}'
notification_title: '${{ env.ROBOT_NAME }} Build Complete'
notification_message: 'Your build was completed.'