|
| 1 | +name: Build fastgpt-sandbox images and copy image to docker hub |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'projects/sandbox/**' |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | +jobs: |
| 10 | + build-fastgpt-sandbox-images: |
| 11 | + runs-on: ubuntu-20.04 |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v3 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + - name: Install Dependencies |
| 18 | + run: | |
| 19 | + sudo apt update && sudo apt install -y nodejs npm |
| 20 | + - name: Set up QEMU (optional) |
| 21 | + uses: docker/setup-qemu-action@v2 |
| 22 | + - name: Set up Docker Buildx |
| 23 | + uses: docker/setup-buildx-action@v2 |
| 24 | + with: |
| 25 | + driver-opts: network=host |
| 26 | + - name: Cache Docker layers |
| 27 | + uses: actions/cache@v2 |
| 28 | + with: |
| 29 | + path: /tmp/.buildx-cache |
| 30 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 31 | + restore-keys: | |
| 32 | + ${{ runner.os }}-buildx- |
| 33 | + - name: Login to GitHub Container Registry |
| 34 | + uses: docker/login-action@v2 |
| 35 | + with: |
| 36 | + registry: ghcr.io |
| 37 | + username: ${{ github.repository_owner }} |
| 38 | + password: ${{ secrets.GH_PAT }} |
| 39 | + - name: Set DOCKER_REPO_TAGGED based on branch or tag |
| 40 | + run: | |
| 41 | + if [[ "${{ github.ref_name }}" == "main" ]]; then |
| 42 | + echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:latest" >> $GITHUB_ENV |
| 43 | + else |
| 44 | + echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{ github.ref_name }}" >> $GITHUB_ENV |
| 45 | + fi |
| 46 | + - name: Build and publish image for main branch or tag push event |
| 47 | + env: |
| 48 | + DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }} |
| 49 | + run: | |
| 50 | + docker buildx build \ |
| 51 | + -f projects/sandbox/Dockerfile \ |
| 52 | + --platform linux/amd64,linux/arm64 \ |
| 53 | + --label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/fastgpt-sandbox" \ |
| 54 | + --label "org.opencontainers.image.description=fastgpt-sandbox image" \ |
| 55 | + --push \ |
| 56 | + --cache-from=type=local,src=/tmp/.buildx-cache \ |
| 57 | + --cache-to=type=local,dest=/tmp/.buildx-cache \ |
| 58 | + -t ${DOCKER_REPO_TAGGED} \ |
| 59 | + . |
| 60 | + push-to-ali-hub: |
| 61 | + needs: build-fastgpt-sandbox-images |
| 62 | + runs-on: ubuntu-20.04 |
| 63 | + steps: |
| 64 | + - name: Checkout code |
| 65 | + uses: actions/checkout@v3 |
| 66 | + - name: Login to Ali Hub |
| 67 | + uses: docker/login-action@v2 |
| 68 | + with: |
| 69 | + registry: registry.cn-hangzhou.aliyuncs.com |
| 70 | + username: ${{ secrets.ALI_HUB_USERNAME }} |
| 71 | + password: ${{ secrets.ALI_HUB_PASSWORD }} |
| 72 | + - name: Set DOCKER_REPO_TAGGED based on branch or tag |
| 73 | + run: | |
| 74 | + if [[ "${{ github.ref_name }}" == "main" ]]; then |
| 75 | + echo "IMAGE_TAG=latest" >> $GITHUB_ENV |
| 76 | + else |
| 77 | + echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV |
| 78 | + fi |
| 79 | + - name: Pull image from GitHub Container Registry |
| 80 | + run: docker pull ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{env.IMAGE_TAG}} |
| 81 | + - name: Tag image with Docker Hub repository name and version tag |
| 82 | + run: docker tag ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{env.IMAGE_TAG}} ${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sandbox:${{env.IMAGE_TAG}} |
| 83 | + - name: Push image to Docker Hub |
| 84 | + run: docker push ${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sandbox:${{env.IMAGE_TAG}} |
0 commit comments