Docker Image Build #229
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: Docker Image CI | |
on: | |
workflow_dispatch: | |
inputs: | |
username: | |
description: 'Version of this branch' | |
default: 'v1.6.2' | |
required: true | |
type: string | |
paths: | |
- 'scripts/**' | |
- 'Dockerfile-for-github-action' | |
- 'requirements.txt' | |
- 'example.env' | |
- '.github/workflows/docker-image.yml' | |
jobs: | |
build-per-arch: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: [amd64, arm64] # 定义要支持的架构 | |
name: Build and Push for ${{ matrix.arch }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log into Docker Hub registry | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image to Docker Hub | |
run: | | |
DOCKER_IMAGE=arcw/sgcc_electricity | |
ARCH=${{ matrix.arch }} | |
VERSION=${{ inputs.username }} | |
docker buildx build \ | |
--platform linux/${ARCH} \ | |
--build-arg VERSION=${VERSION} \ | |
-t ${DOCKER_IMAGE}:latest-${ARCH} \ | |
-t ${DOCKER_IMAGE}:${VERSION}-${ARCH} \ | |
--file Dockerfile-for-github-action \ | |
--push . | |
- name: Log into Aliyun registry | |
uses: docker/login-action@v2 | |
with: | |
registry: registry.cn-hangzhou.aliyuncs.com | |
username: ${{ secrets.ALIYUN_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image to Aliyun | |
run: | | |
ALIYUN_IMAGE=registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity | |
ARCH=${{ matrix.arch }} | |
VERSION=${{ inputs.username }} | |
docker buildx build \ | |
--platform linux/${ARCH} \ | |
--build-arg VERSION=${VERSION} \ | |
-t ${ALIYUN_IMAGE}:latest-${ARCH} \ | |
-t ${ALIYUN_IMAGE}:${VERSION}-${ARCH} \ | |
--file Dockerfile-for-github-action \ | |
--push . | |
build-multi-arch: | |
needs: build-per-arch | |
runs-on: ubuntu-latest | |
name: Build and Push Multi-Arch Image | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log into Docker Hub registry | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push multi-arch Docker image to Docker Hub | |
run: | | |
DOCKER_IMAGE=arcw/sgcc_electricity | |
VERSION=${{ inputs.username }} | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg VERSION=${VERSION} \ | |
-t ${DOCKER_IMAGE}:latest \ | |
-t ${DOCKER_IMAGE}:${VERSION} \ | |
--file Dockerfile-for-github-action \ | |
--push . | |
- name: Log into Aliyun registry | |
uses: docker/login-action@v2 | |
with: | |
registry: registry.cn-hangzhou.aliyuncs.com | |
username: ${{ secrets.ALIYUN_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push multi-arch Docker image to Aliyun | |
run: | | |
ALIYUN_IMAGE=registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity | |
VERSION=${{ inputs.username }} | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--build-arg VERSION=${VERSION} \ | |
-t ${ALIYUN_IMAGE}:latest \ | |
-t ${ALIYUN_IMAGE}:${VERSION} \ | |
--file Dockerfile-for-github-action \ | |
--push . |