|
| 1 | +# Reference: Multi-platform image with GitHub Actions |
| 2 | +# https://docs.docker.com/build/ci/github-actions/multi-platform/ |
| 3 | +# https://docs.docker.com/build/ci/github-actions/push-multi-registries/ |
| 4 | + |
| 5 | +name: docker-image-comfyui |
| 6 | +concurrency: deploy-${{ github.workflow }} |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - '*' |
| 12 | + paths: |
| 13 | + - comfyui/Dockerfile |
| 14 | + - comfyui/entrypoint.sh |
| 15 | + workflow_dispatch: |
| 16 | + schedule: |
| 17 | + - cron: ' 0 20 * * 5' |
| 18 | + |
| 19 | +env: |
| 20 | + IMAGE_CONTEXT: ./comfyui |
| 21 | + REGISTRY_IMAGE: ${{ github.repository_owner }}/comfyui |
| 22 | + BUILD_PLATFORMS: | |
| 23 | + linux/amd64 |
| 24 | +
|
| 25 | +jobs: |
| 26 | + check-updates: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + remote_version: ${{ steps.remote_version.outputs.remote_version }} |
| 30 | + steps: |
| 31 | + # 1. 获取远程版本 |
| 32 | + - name: Get remote version |
| 33 | + id: remote_version |
| 34 | + run: | |
| 35 | + REMOTE_REPO="comfyanonymous/ComfyUI" |
| 36 | + # 使用 GitHub CLI 或 curl/jq 获取最新 Release Tag |
| 37 | + LATEST_TAG=$(curl -s "https://api.github.com/repos/${REMOTE_REPO}/releases/latest" | jq -r .tag_name) |
| 38 | + |
| 39 | + if [ "$LATEST_TAG" = "null" ]; then |
| 40 | + echo "::error::Could not find latest release tag." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | + echo "Remote Version: $LATEST_TAG" |
| 45 | + echo "remote_version=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | +
|
| 48 | + build-images: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + contents: read |
| 52 | + packages: write |
| 53 | + needs: |
| 54 | + - check-updates |
| 55 | + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' |
| 56 | + steps: |
| 57 | + - name: Prepare |
| 58 | + run: | |
| 59 | + echo "TODAY=$(date +'%Y%m%d')" >> $GITHUB_ENV |
| 60 | + echo "TODAY: $TODAY" |
| 61 | +
|
| 62 | + - name: Maximize build space |
| 63 | + uses: easimon/maximize-build-space@master |
| 64 | + with: |
| 65 | + build-mount-path: '/var/lib/docker/' |
| 66 | + root-reserve-mb: 512 |
| 67 | + temp-reserve-mb: 32 |
| 68 | + swap-size-mb: 32 |
| 69 | + remove-dotnet: 'true' |
| 70 | + remove-android: 'true' |
| 71 | + remove-haskell: 'true' |
| 72 | + remove-codeql: 'true' |
| 73 | + remove-docker-images: 'true' |
| 74 | + - name: Restart docker |
| 75 | + run: sudo service docker restart |
| 76 | + |
| 77 | + - name: Checkout |
| 78 | + uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: Login to Docker Hub |
| 81 | + uses: docker/login-action@v3 |
| 82 | + with: |
| 83 | + username: ${{ github.repository_owner }} |
| 84 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 85 | + |
| 86 | + - name: Login to GitHub Container Registry |
| 87 | + uses: docker/login-action@v3 |
| 88 | + with: |
| 89 | + registry: ghcr.io |
| 90 | + username: ${{ github.repository_owner }} |
| 91 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + |
| 93 | + - name: Set up QEMU |
| 94 | + uses: docker/setup-qemu-action@v3 |
| 95 | + |
| 96 | + - name: Set up Docker Buildx |
| 97 | + uses: docker/setup-buildx-action@v3 |
| 98 | + |
| 99 | + - name: Build slim images |
| 100 | + id: build |
| 101 | + uses: docker/build-push-action@v6 |
| 102 | + with: |
| 103 | + platforms: ${{ env.BUILD_PLATFORMS }} |
| 104 | + context: ${{ env.IMAGE_CONTEXT }} |
| 105 | + file: ${{ env.IMAGE_CONTEXT }}/Dockerfile |
| 106 | + tags: | |
| 107 | + ${{ env.REGISTRY_IMAGE }}:latest |
| 108 | + ${{ env.REGISTRY_IMAGE }}:${{ needs.check-updates.outputs.remote_version }}-slim-${{ env.TODAY }} |
| 109 | + ghcr.io/${{ env.REGISTRY_IMAGE }}:latest |
| 110 | + ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ needs.check-updates.outputs.remote_version }}-slim-${{ env.TODAY }} |
| 111 | + push: true |
| 112 | + build-args: | |
| 113 | + VERSION=${{ needs.check-updates.outputs.remote_version }} |
| 114 | + BUILD_MODE=slim |
| 115 | +
|
| 116 | + - name: Build pro images |
| 117 | + id: build |
| 118 | + uses: docker/build-push-action@v6 |
| 119 | + with: |
| 120 | + platforms: ${{ env.BUILD_PLATFORMS }} |
| 121 | + context: ${{ env.IMAGE_CONTEXT }} |
| 122 | + file: ${{ env.IMAGE_CONTEXT }}/Dockerfile |
| 123 | + tags: | |
| 124 | + ${{ env.REGISTRY_IMAGE }}:${{ needs.check-updates.outputs.remote_version }}-pro-${{ env.TODAY }} |
| 125 | + ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ needs.check-updates.outputs.remote_version }}-pro-${{ env.TODAY }} |
| 126 | + push: true |
| 127 | + build-args: | |
| 128 | + VERSION=${{ needs.check-updates.outputs.remote_version }} |
| 129 | + BUILD_MODE=pro |
0 commit comments