Build Application #59
This file contains hidden or 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
| # This workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
| name: Build Application | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| schedule: | |
| - cron: "3 4 */15 * *" # 每两周的午夜触发一次 | |
| concurrency: | |
| group: build-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| IMAGE_NAME: docker-atrust-autologin | |
| jobs: | |
| build-docker-multiarch: | |
| runs-on: ubuntu-24.04 | |
| name: Build Multi-Arch Docker Image | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@master | |
| - name: submodules-init | |
| uses: snickerbockers/submodules-init@v4 | |
| - name: Run Docker Prebuild shell | |
| run: | | |
| echo "Prebuild shell" | |
| ls -al | |
| ls -al ./docker/bin | |
| mkdir -p ./build/output || true | |
| ls -al ./build/output | |
| - name: Set Up QEMU | |
| uses: docker/setup-qemu-action@v1 | |
| - name: Set Up Buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login DockerHub | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Set Up Cache | |
| uses: actions/cache@v4 | |
| id: buildx-cache | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx | |
| - name: Buildx | |
| uses: docker/build-push-action@v2 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest | |
| - name: Upload ModelScope | |
| run: | | |
| echo "Upload ModelScope 1: Save docker image" | |
| cd ./build/output | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest --platform=linux/amd64 | |
| docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:amd64 | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest --platform=linux/arm64 | |
| docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:arm64 | |
| # 第一组并行:保存 Docker 镜像为 amd64 | |
| ( | |
| echo "Save docker image to ./${{ env.IMAGE_NAME }}-amd64.tar.xz" | |
| docker save ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:amd64 | xz -T0 -c -9 -v > ./${{ env.IMAGE_NAME }}-amd64.tar.xz | |
| ) & | |
| # 第二组并行:拉取 Docker 镜像,标记为 arm64,保存为 .tar.xz 文件 | |
| ( | |
| echo "Save docker image to ./${{ env.IMAGE_NAME }}-arm64.tar.xz" | |
| docker save ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:arm64 | xz -T0 -c -9 -v > ./${{ env.IMAGE_NAME }}-arm64.tar.xz | |
| ) & | |
| # 等待所有后台任务完成 | |
| wait | |
| ls -al . | |
| echo "Upload ModelScope 2: Upload to ModelScope" | |
| git lfs install | |
| export GIT_LFS_SKIP_SMUDGE=1 | |
| git clone https://oauth2:${{ secrets.MODELSCOPE_TOKEN }}@www.modelscope.cn/kenvix/aTrustLoginRepo.git aTrustLoginRepo | |
| rm -f aTrustLoginRepo/${{ env.IMAGE_NAME }}-amd64.tar.xz | |
| rm -f aTrustLoginRepo/${{ env.IMAGE_NAME }}-arm64.tar.xz | |
| mv ./${{ env.IMAGE_NAME }}-amd64.tar.xz aTrustLoginRepo/ | |
| mv ./${{ env.IMAGE_NAME }}-arm64.tar.xz aTrustLoginRepo/ | |
| cd aTrustLoginRepo | |
| ls -al . | |
| git lfs track "*.tar.xz" | |
| git add .gitattributes | |
| git add ${{ env.IMAGE_NAME }}-amd64.tar.xz | |
| git add ${{ env.IMAGE_NAME }}-arm64.tar.xz | |
| git config --global user.name "Kenvix CI Auto Commit" | |
| git config --global user.email "ci@kenvix.com" | |
| git commit -m "Upload docker image" | |
| git push |