Build Docker Image #13
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: Build Docker Image | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the "main" branch | |
push: | |
branches: [ "main" ] | |
paths: | |
- 'LATEST_VERSION' | |
workflow_dispatch: | |
env: | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: docker.io/lamgc/poweradmin | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
platform: [linux/amd64, linux/arm64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v5, linux/mips64le] | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# 从仓库目录下读取 LATEST_VERSION 文件,获取最新版本号 | |
- name: Read latest version | |
id: read-version | |
run: echo "version=$(cat LATEST_VERSION)" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# Set up BuildKit Docker container builder to be able to build | |
# multi-platform images and export cache | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 # v3.0.0 | |
- name: Download latest PowerAdmin | |
run: chmod +x ./download-latest-poweradmin.sh && ./download-latest-poweradmin.sh | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Login docker hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 # v3.0.0 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 # v5.0.0 | |
with: | |
context: . | |
platforms: ${{ matrix.platform }} | |
push: true | |
tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ steps.read-version.outputs.version }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |