-
Notifications
You must be signed in to change notification settings - Fork 82
129 lines (118 loc) · 4.24 KB
/
build-mdcx.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
name: Image build-mdcx CI
on:
push:
branches:
- none
# workflow_run:
# workflows: [Watch MDCx Release]
# types: [completed]
# branches: [main]
workflow_dispatch:
inputs:
stage:
description: Stage
type: choice
default: prod
options:
- dev
- prod
baseImage:
description: Tag of base image `build-mdcx-base`
default: 'latest'
env:
IMAGE_BASE: build-mdcx
IMAGE_KEY: build-mdcx
PYPI_MIRROR: https://pypi.org/simple
APT_SOURCE_HOST: ''
ENABLE_TG_NOTIFICATION: ${{ secrets.ENABLE_TG_NOTIFICATION }}
jobs:
build:
runs-on: ubuntu-latest
# 如果是workflow_run(即Watch MDCx Release)触发的,只有当上游workflow成功时才运行
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Install apt packages
run: sudo apt-get install -y unrar
-
name: Prepare App source
id: prepare
run: |
bash ./prepare-src.sh --verbose --context $IMAGE_BASE
-
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 [[ "${{ github.event.inputs.stage }}" == "dev" ]]; then
echo "latest=latest-dev" >> $GITHUB_OUTPUT
echo "version=${{ steps.prepare.outputs.APP_VERSION }}-dev" >> $GITHUB_OUTPUT
else
echo "latest=latest" >> $GITHUB_OUTPUT
echo "version=${{ steps.prepare.outputs.APP_VERSION }}" >> $GITHUB_OUTPUT
fi
baseImageTag=${{ github.event.inputs.baseImage }}
baseImageTag=${baseImageTag:-latest}
echo "baseImageTag=${baseImageTag}" >> $GITHUB_OUTPUT
-
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 }}
PYPI_MIRROR=${{ env.PYPI_MIRROR }}
BASE_IMAGE_TAG=${{ steps.imageInfo.outputs.baseImageTag }}
APP_VERSION=${{ steps.prepare.outputs.APP_VERSION }}
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 }}
PYPI_MIRROR=${{ env.PYPI_MIRROR }}
BASE_IMAGE_TAG=${{ steps.imageInfo.outputs.baseImageTag }}
APP_VERSION=${{ steps.prepare.outputs.APP_VERSION }}
📦 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 }}