|
| 1 | +name: Build FastGPT Admin images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-fastgpt-admin-images: |
| 11 | + permissions: |
| 12 | + packages: write |
| 13 | + contents: read |
| 14 | + attestations: write |
| 15 | + id-token: write |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + sub_routes: |
| 19 | + - repo: fastgpt-pro |
| 20 | + base_url: "" |
| 21 | + - repo: fastgpt-pro-sub-route |
| 22 | + base_url: "/fastaipro" |
| 23 | + - repo: fastgpt-pro-sub-route-gchat |
| 24 | + base_url: "/gchat-admin" |
| 25 | + archs: |
| 26 | + - arch: amd64 |
| 27 | + - arch: arm64 |
| 28 | + runs-on: ubuntu-24.04-arm |
| 29 | + runs-on: ${{ matrix.archs.runs-on || 'ubuntu-24.04' }} |
| 30 | + steps: |
| 31 | + # install env |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 1 |
| 36 | + |
| 37 | + - name: Update submodules |
| 38 | + env: |
| 39 | + PRO_SUBMODULE_TOKEN: ${{ secrets.PRO_SUBMODULE_TOKEN }} |
| 40 | + run: | |
| 41 | + if [ -f .gitmodules ]; then |
| 42 | + if [ -z "${PRO_SUBMODULE_TOKEN}" ]; then |
| 43 | + echo "::error::PRO_SUBMODULE_TOKEN is required to clone the private pro submodule. Add it to this repository's Actions secrets, or run this workflow from a repository that has the secret configured." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + git config --global url."https://x-access-token:${PRO_SUBMODULE_TOKEN}@github.com/".insteadOf "https://github.com/" |
| 47 | + git submodule update --init --recursive |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Set up Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@v3 |
| 52 | + with: |
| 53 | + driver-opts: network=host |
| 54 | + |
| 55 | + - name: Cache Docker layers |
| 56 | + uses: actions/cache@v4 |
| 57 | + with: |
| 58 | + path: /tmp/.buildx-cache |
| 59 | + key: ${{ runner.os }}-${{ matrix.archs.arch }}-${{ matrix.sub_routes.repo |
| 60 | + }}-buildx-${{ github.sha }} |
| 61 | + restore-keys: | |
| 62 | + ${{ runner.os }}-${{ matrix.archs.arch }}-${{ matrix.sub_routes.repo }}-buildx- |
| 63 | +
|
| 64 | + # login docker (GHCR only; Ali tags are pushed in release job via imagetools) |
| 65 | + - name: Login to GitHub Container Registry |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + registry: ghcr.io |
| 69 | + username: ${{ github.repository_owner }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Build for ${{ matrix.archs.arch }} |
| 73 | + id: build |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + file: pro/admin/Dockerfile |
| 78 | + platforms: linux/${{ matrix.archs.arch }} |
| 79 | + build-args: | |
| 80 | + ${{ matrix.sub_routes.base_url && format('base_url={0}', matrix.sub_routes.base_url) || '' }} |
| 81 | + labels: | |
| 82 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 83 | + org.opencontainers.image.description=${{ matrix.sub_routes.repo }} image |
| 84 | + outputs: type=image,"name=ghcr.io/${{ github.repository_owner }}/${{ |
| 85 | + matrix.sub_routes.repo }}",push-by-digest=true,push=true |
| 86 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 87 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 88 | + |
| 89 | + - name: Export digest |
| 90 | + run: | |
| 91 | + mkdir -p ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }} |
| 92 | + digest="${{ steps.build.outputs.digest }}" |
| 93 | + touch "${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/${digest#sha256:}" |
| 94 | +
|
| 95 | + - name: Upload digest |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-${{ |
| 99 | + matrix.archs.arch }} |
| 100 | + path: ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/* |
| 101 | + if-no-files-found: error |
| 102 | + retention-days: 1 |
| 103 | + |
| 104 | + release-fastgpt-images: |
| 105 | + permissions: |
| 106 | + packages: write |
| 107 | + contents: read |
| 108 | + attestations: write |
| 109 | + id-token: write |
| 110 | + needs: build-fastgpt-admin-images |
| 111 | + strategy: |
| 112 | + matrix: |
| 113 | + sub_routes: |
| 114 | + - repo: fastgpt-pro |
| 115 | + - repo: fastgpt-pro-sub-route |
| 116 | + - repo: fastgpt-pro-sub-route-gchat |
| 117 | + runs-on: ubuntu-24.04 |
| 118 | + steps: |
| 119 | + - name: Login to GitHub Container Registry |
| 120 | + uses: docker/login-action@v3 |
| 121 | + with: |
| 122 | + registry: ghcr.io |
| 123 | + username: ${{ github.repository_owner }} |
| 124 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + - name: Login to Ali Hub |
| 126 | + uses: docker/login-action@v3 |
| 127 | + with: |
| 128 | + registry: registry.cn-hangzhou.aliyuncs.com |
| 129 | + username: ${{ secrets.FASTGPT_ALI_IMAGE_USER }} |
| 130 | + password: ${{ secrets.FASTGPT_ALI_IMAGE_PSW }} |
| 131 | + |
| 132 | + - name: Download digests |
| 133 | + uses: actions/download-artifact@v4 |
| 134 | + with: |
| 135 | + path: ${{ runner.temp }}/digests |
| 136 | + pattern: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-* |
| 137 | + merge-multiple: true |
| 138 | + |
| 139 | + - name: Set up Docker Buildx |
| 140 | + uses: docker/setup-buildx-action@v3 |
| 141 | + |
| 142 | + - name: Set image name and tag |
| 143 | + run: | |
| 144 | + if [[ "${{ github.ref_name }}" == "main" ]]; then |
| 145 | + echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 146 | + echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 147 | + echo "Ali_Tag=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 148 | + echo "Ali_Latest=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 149 | + else |
| 150 | + echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV |
| 151 | + echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 152 | + echo "Ali_Tag=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV |
| 153 | + echo "Ali_Latest=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV |
| 154 | + fi |
| 155 | +
|
| 156 | + - name: Create manifest list and push |
| 157 | + working-directory: ${{ runner.temp }}/digests |
| 158 | + run: | |
| 159 | + TAGS="$(echo -e "${Git_Tag}\n${Git_Latest}\n${Ali_Tag}\n${Ali_Latest}")" |
| 160 | + for TAG in $TAGS; do |
| 161 | + docker buildx imagetools create -t $TAG \ |
| 162 | + $(printf 'ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}@sha256:%s ' *) |
| 163 | + sleep 5 |
| 164 | + done |
0 commit comments