diff --git a/.github/workflows/base_ci.yml b/.github/workflows/base_ci.yml index 76eb0b799..65e2debaa 100644 --- a/.github/workflows/base_ci.yml +++ b/.github/workflows/base_ci.yml @@ -14,7 +14,7 @@ concurrency: cancel-in-progress: true jobs: - build_bisheng: + build_bisheng_arm: runs-on: ubuntu-latest # if: startsWith(github.event.ref, 'refs/tags') steps: @@ -38,13 +38,6 @@ jobs: # DOCKERHUB_TOKEN: docker hub => Account Setting => Security 创建. username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - # - name: Login to DockerHub - # uses: docker/login-action@v1 - # with: - # registry: https://cr.dataelem.com/ - # username: ${{ secrets.CR_DOCKERHUB_USERNAME }} - # password: ${{ secrets.CR_DOCKERHUB_TOKEN }} # 构建 backend 并推送到 Docker hub - name: Set up QEMU @@ -53,10 +46,63 @@ jobs: - name: set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: install poetry - uses: snok/install-poetry@v1 + - name: Build backend arm64 and push + id: docker_build_backend_arm + uses: docker/build-push-action@v2 with: - installer-parallel: true + # backend 的context目录 + context: "./src/backend/" + file: ./src/backend/base.Dockerfile + # 是否 docker push + push: true + # docker build arg, 注入 APP_NAME/APP_VERSION + platforms: linux/arm64 + build-args: | + APP_NAME="bisheng-backend" + APP_VERSION=${{ steps.get_version.outputs.VERSION }} + PANDOC_ARCH=arm64 + # 生成两个 docker tag: ${APP_VERSION} 和 latest + tags: | + ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }}-arm64 + # 获取提交信息 + - name: Process git message + id: process_message + run: | + value=$(echo "${{ github.event.head_commit.message }}" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/%0A/g') + value=$(echo "${value}" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\r/%0A/g') + echo "message=${value}" >> $GITHUB_ENV + shell: bash + # 飞书通知 + - name: notify feishu + uses: fjogeleit/http-request-action@v1 + with: + url: ${{ secrets.FEISHU_WEBHOOK }} + method: 'POST' + data: '{"msg_type":"post","content":{"post":{"zh_cn":{"title": "${{ steps.get_version.outputs.VERSION }}发布成功", "content": [[{"tag":"text","text":"基础镜像"},{"tag":"text","text":"${{ env.message }}"}]]}}}}' + + build_bisheng_amd: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: Get version + id: get_version + run: | + echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: Set Environment Variable + run: echo "RELEASE_VERSION=${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_ENV + + # 登录 docker hub + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + # GitHub Repo => Settings => Secrets 增加 docker hub 登录密钥信息 + # DOCKERHUB_USERNAME 是 docker hub 账号名. + # DOCKERHUB_TOKEN: docker hub => Account Setting => Security 创建. + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build backend amd64 and push id: docker_build_backend_amd @@ -75,37 +121,32 @@ jobs: PANDOC_ARCH=amd64 # 生成两个 docker tag: ${APP_VERSION} 和 latest tags: | - ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }} - - name: Build backend arm64 and push - id: docker_build_backend_arm - uses: docker/build-push-action@v2 - with: - # backend 的context目录 - context: "./src/backend/" - file: ./src/backend/base.Dockerfile - # 是否 docker push - push: true - # docker build arg, 注入 APP_NAME/APP_VERSION - platforms: linux/arm64 - build-args: | - APP_NAME="bisheng-backend" - APP_VERSION=${{ steps.get_version.outputs.VERSION }} - PANDOC_ARCH=arm64 - # 生成两个 docker tag: ${APP_VERSION} 和 latest - tags: | - ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }} - # 获取提交信息 - - name: Process git message - id: process_message + ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }}-amd64 + + combine_two_images: + runs-on: ubuntu-latest + needs: + - build_bisheng_amd + - build_bisheng_arm + steps: + - name: Get version + id: get_version run: | - value=$(echo "${{ github.event.head_commit.message }}" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/%0A/g') - value=$(echo "${value}" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\r/%0A/g') - echo "message=${value}" >> $GITHUB_ENV - shell: bash - # 飞书通知 - - name: notify feishu - uses: fjogeleit/http-request-action@v1 + echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: Set Environment Variable + run: echo "RELEASE_VERSION=${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_ENV + + # 登录 docker hub + - name: Login to DockerHub + uses: docker/login-action@v1 with: - url: ${{ secrets.FEISHU_WEBHOOK }} - method: 'POST' - data: '{"msg_type":"post","content":{"post":{"zh_cn":{"title": "${{ steps.get_version.outputs.VERSION }}发布成功", "content": [[{"tag":"text","text":"基础镜像"},{"tag":"text","text":"${{ env.message }}"}]]}}}}' \ No newline at end of file + # GitHub Repo => Settings => Secrets 增加 docker hub 登录密钥信息 + # DOCKERHUB_USERNAME 是 docker hub 账号名. + # DOCKERHUB_TOKEN: docker hub => Account Setting => Security 创建. + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Combine Two images + run: | + docker manifest create ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }} --amend ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }}-arm64 --amend ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }}-amd64 + docker manifest push ${{ env.DOCKERHUB_REPO }}bisheng-backend:${{ steps.get_version.outputs.VERSION }} \ No newline at end of file