From 986c58182fc34c4bb8dfcf75dfd357cfc4c93532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=A3=9E=E5=BF=AB=E8=B7=91?= <517858721@qq.com> Date: Thu, 2 Jan 2025 15:20:11 +0800 Subject: [PATCH] Create main.yml --- .github/workflows/main.yml | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000000..3832a078c0b4 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,68 @@ +name: Maven Build and Docker Image CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '8' + + - name: Dependies Cache + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build with Maven + run: | + mvn clean package -Dmaven.test.skip=true + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to DockerAlibaba + run: | + docker login --username=${{ secrets.ALIYUN_REGISTRY_USER }} --password=${{ secrets.ALIYUN_REGISTRY_PASSWORD }} registry.cn-hangzhou.aliyuncs.com + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./big-market-app/ActionDockerfile + # 所需要的体系结构,可以在 Available platforms 步骤中获取所有的可用架构 https://docs.docker.com/build/building/multi-platform/ + platforms: linux/amd64 + # 镜像推送时间 + push: ${{ github.event_name != 'pull_request' }} + # 给清单打上多个标签 + tags: | + fuzhengwei/big-market-app:3.0 + fuzhengwei/big-market-app:latest + + - name: Tag image for Alibaba Cloud + run: | + docker tag fuzhengwei/big-market-app:3.0 registry.cn-hangzhou.aliyuncs.com/fuzhengwei/big-market-app:3.0 + docker tag fuzhengwei/big-market-app:latest registry.cn-hangzhou.aliyuncs.com/fuzhengwei/big-market-app:latest + + - name: Push to Alibaba Cloud Container Registry + run: | + docker push registry.cn-hangzhou.aliyuncs.com/fuzhengwei/big-market-app:3.0 + docker push registry.cn-hangzhou.aliyuncs.com/fuzhengwei/big-market-app:latest +