-
Notifications
You must be signed in to change notification settings - Fork 81
160 lines (145 loc) · 5.33 KB
/
mdcx-builtin-webtop-base.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Image mdcx-builtin-webtop-base CI
on:
push:
branches:
- none
workflow_run:
workflows: [Image build-mdcx CI]
types: [completed]
branches: [main]
workflow_dispatch:
inputs:
stage:
description: Stage
type: choice
default: dev
options:
- dev
- prod
baseImage:
description: Tag of base image `webtop-base`
type: choice
default: 'latest'
options:
- 'ubuntu-kde-22.04'
- 'latest'
binTag:
description: Tag of app bin image
default: 'latest'
env:
IMAGE_BASE: webtop-base
IMAGE_KEY: mdcx-builtin-webtop-base
APT_SOURCE_HOST: ''
ENABLE_TG_NOTIFICATION: ${{ secrets.ENABLE_TG_NOTIFICATION }}
jobs:
build:
runs-on: ubuntu-latest
# 如果是workflow_run(即Image build-mdcx CI)触发的,只有当上游workflow成功时才运行
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Prepare build info
id: buildInfo
run: |
STAGE=${{ github.event.inputs.stage }}
STAGE=${STAGE:-dev}
BIN_TAG=${{ github.event.inputs.binTag }}
BIN_TAG=${BIN_TAG:-latest}
BASE_IMAGE_TAG=${{ github.event.inputs.baseImage }}
BASE_IMAGE_TAG=${BASE_IMAGE_TAG:-latest}
if [[ "${{ github.event_name }}" == "workflow_run" && "${{ github.ref_name }}" == "main" ]]; then
STAGE=prod
BIN_TAG=latest
BASE_IMAGE_TAG=latest
fi
echo "STAGE=$STAGE" >> $GITHUB_OUTPUT
echo "BIN_TAG=$BIN_TAG" >> $GITHUB_OUTPUT
echo "BASE_IMAGE_TAG=$BASE_IMAGE_TAG" >> $GITHUB_OUTPUT
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
sleep 10
fi
-
name: Prepare App info
id: appInfo
run: |
APP_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/build-mdcx:${{ steps.buildInfo.outputs.BIN_TAG }}"
APP_VERSION=$(docker run --rm $APP_IMAGE cat /app-version)
if [[ -z "$APP_VERSION" ]]; then
echo "❌ Failed to get app version from app bin image!"
exit 1
fi
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_OUTPUT
-
name: Prepare Version Values
uses: cardinalby/export-env-action@v2
id: versions
with:
envFile: '.env.versions'
export: 'false'
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Produce docker image tags and other information
id: imageInfo
run: |
if [[ "${{ steps.buildInfo.outputs.STAGE }}" == "dev" ]]; then
echo "latest=latest-dev" >> $GITHUB_OUTPUT
echo "version=${{ steps.appInfo.outputs.APP_VERSION }}-dev" >> $GITHUB_OUTPUT
else
echo "latest=latest" >> $GITHUB_OUTPUT
echo "version=${{ steps.appInfo.outputs.APP_VERSION }}" >> $GITHUB_OUTPUT
fi
-
name: Build and push
id: buildAndPush
uses: docker/build-push-action@v3
with:
context: .
# cache-from: type=gha
# cache-to: type=gha,mode=min
file: ${{ env.IMAGE_BASE }}/Dockerfile.${{ env.IMAGE_KEY }}
build-args: |
APT_SOURCE_HOST=${{ env.APT_SOURCE_HOST }}
BASE_IMAGE_TAG=${{ steps.buildInfo.outputs.BASE_IMAGE_TAG }}
APP_VERSION=${{ steps.appInfo.outputs.APP_VERSION }}
MDCX_BIN_IMAGE_TAG=${{ steps.buildInfo.outputs.BIN_TAG }}
platforms: |
linux/amd64
linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_KEY }}:${{ steps.imageInfo.outputs.latest }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_KEY }}:${{ steps.imageInfo.outputs.version }}
-
name: TG Notification
uses: appleboy/telegram-action@master
if: ${{ env.ENABLE_TG_NOTIFICATION == 'true' }}
with:
to: ${{ secrets.TELE_CHAT_ID }}
token: ${{ secrets.TELE_BOT_TOKEN }}
message: |
🎉 Workflow: ${{ github.workflow }} is completed!
🔘 Stage: ${{ github.event.inputs.stage }}
📦 Dockerfile: ${{ env.IMAGE_BASE }}/Dockerfile.${{ env.IMAGE_KEY }}
📦 Build Args:
APT_SOURCE_HOST=${{ env.APT_SOURCE_HOST }}
BASE_IMAGE_TAG=${{ steps.buildInfo.outputs.BASE_IMAGE_TAG }}
APP_VERSION=${{ steps.appInfo.outputs.APP_VERSION }}
MDCX_BIN_IMAGE_TAG=${{ steps.buildInfo.outputs.BIN_TAG }}
📦 Image: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_KEY }}
📦 Tags: ${{ steps.imageInfo.outputs.latest }}, ${{ steps.imageInfo.outputs.version }}
📦 ImageId: ${{ steps.buildAndPush.outputs.imageid }}
📦 Digest: ${{ steps.buildAndPush.outputs.digest }}