Skip to content

Image mdcx-builtin-webtop-base CI #293

Image mdcx-builtin-webtop-base CI

Image mdcx-builtin-webtop-base CI #293

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 }}