Build and Push Docker Image to Aliyun #39
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 and Push Docker Image to Aliyun | |
on: | |
workflow_dispatch: | |
release: | |
types: [ published ] | |
tags: [ v* ] | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: | |
- amd64 | |
- arm64 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: 'maven' | |
- name: Build with Maven | |
run: mvn clean package -DskipTests | |
- name: Extract project version from pom.xml | |
run: | | |
VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) | |
echo "PROJECT_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Aliyun Container Registry guangzhou | |
uses: docker/login-action@v3 | |
with: | |
registry: registry.cn-guangzhou.aliyuncs.com | |
username: ${{ secrets.ALIYUN_DOCKER_USERNAME }} | |
password: ${{ secrets.ALIYUN_DOCKER_PASSWORD }} | |
- name: Log in to Aliyun Container Registry beijing | |
uses: docker/login-action@v3 | |
with: | |
registry: registry.cn-beijing.aliyuncs.com | |
username: ${{ secrets.ALIYUN_DOCKER_USERNAME }} | |
password: ${{ secrets.ALIYUN_DOCKER_PASSWORD }} | |
- name: Set tag for amd64 | |
if: matrix.arch == 'amd64' | |
run: | | |
echo "TAG_LATEST_0=registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest" >> $GITHUB_ENV | |
echo "TAG_VERSION_0=registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:${{ env.PROJECT_VERSION }}" >> $GITHUB_ENV | |
echo "TAG_LATEST_1=registry.cn-beijing.aliyuncs.com/jmalcloud/jmalcloud:latest" >> $GITHUB_ENV | |
echo "TAG_VERSION_1=registry.cn-beijing.aliyuncs.com/jmalcloud/jmalcloud:${{ env.PROJECT_VERSION }}" >> $GITHUB_ENV | |
- name: Set tag for non-amd64 | |
if: matrix.arch != 'amd64' | |
run: | | |
echo "TAG_LATEST_0=registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest-${{ matrix.arch }}" >> $GITHUB_ENV | |
echo "TAG_VERSION_0=registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:${{ env.PROJECT_VERSION }}-${{ matrix.arch }}" >> $GITHUB_ENV | |
echo "TAG_LATEST_1=registry.cn-beijing.aliyuncs.com/jmalcloud/jmalcloud:latest-${{ matrix.arch }}" >> $GITHUB_ENV | |
echo "TAG_VERSION_1=registry.cn-beijing.aliyuncs.com/jmalcloud/jmalcloud:${{ env.PROJECT_VERSION }}-${{ matrix.arch }}" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/${{ matrix.arch }} | |
push: true | |
tags: | | |
${{ env.TAG_LATEST_0 }} | |
${{ env.TAG_VERSION_0 }} | |
${{ env.TAG_LATEST_1 }} | |
${{ env.TAG_VERSION_1 }} | |
build-args: | | |
VERSION=${{ env.PROJECT_VERSION }} |