Image build-mdcx CI #304
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |