|
| 1 | +name: Build ComfyUI Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + comfyuiVersion: |
| 7 | + description: "ComfyUI stable release (latest, v0.33.1, or 0.33.1)" |
| 8 | + default: "latest" |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + pushLatest: |
| 12 | + description: "Push latest when this is the newest upstream stable release" |
| 13 | + default: true |
| 14 | + required: true |
| 15 | + type: boolean |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: comfyui-release |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +env: |
| 25 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
| 26 | + IMAGE_NAME: 1panel/comfyui |
| 27 | + |
| 28 | +jobs: |
| 29 | + resolve: |
| 30 | + runs-on: ubuntu-24.04 |
| 31 | + outputs: |
| 32 | + version: ${{ steps.release.outputs.version }} |
| 33 | + release_tag: ${{ steps.release.outputs.release_tag }} |
| 34 | + revision: ${{ steps.release.outputs.revision }} |
| 35 | + push_latest: ${{ steps.release.outputs.push_latest }} |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v6 |
| 39 | + |
| 40 | + - name: Resolve and verify ComfyUI release |
| 41 | + id: release |
| 42 | + shell: bash |
| 43 | + env: |
| 44 | + GH_TOKEN: ${{ github.token }} |
| 45 | + INPUT_COMFYUI_VERSION: ${{ inputs.comfyuiVersion }} |
| 46 | + INPUT_PUSH_LATEST: ${{ inputs.pushLatest }} |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | +
|
| 50 | + requested="${INPUT_COMFYUI_VERSION}" |
| 51 | + if [ "${requested}" = "latest" ]; then |
| 52 | + release_url="https://api.github.com/repos/Comfy-Org/ComfyUI/releases/latest" |
| 53 | + else |
| 54 | + version="${requested#v}" |
| 55 | + if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then |
| 56 | + echo "::error::Invalid ComfyUI release version: ${requested}" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + release_url="https://api.github.com/repos/Comfy-Org/ComfyUI/releases/tags/v${version}" |
| 60 | + fi |
| 61 | +
|
| 62 | + release_json="$(mktemp)" |
| 63 | + curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors \ |
| 64 | + -H "Accept: application/vnd.github+json" \ |
| 65 | + -H "Authorization: Bearer ${GH_TOKEN}" \ |
| 66 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 67 | + "${release_url}" -o "${release_json}" |
| 68 | +
|
| 69 | + release_tag="$(jq -r '.tag_name' "${release_json}")" |
| 70 | + if [ "$(jq -r '.draft' "${release_json}")" != "false" ] || \ |
| 71 | + [ "$(jq -r '.prerelease' "${release_json}")" != "false" ]; then |
| 72 | + echo "::error::${release_tag} is not a published stable release" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + version="${release_tag#v}" |
| 77 | + if [[ "${release_tag}" != "v${version}" ]] || \ |
| 78 | + [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then |
| 79 | + echo "::error::Unexpected upstream release tag: ${release_tag}" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + direct_revision="$(git ls-remote https://github.com/Comfy-Org/ComfyUI.git "refs/tags/${release_tag}" | awk 'NR == 1 { print $1 }')" |
| 84 | + peeled_revision="$(git ls-remote https://github.com/Comfy-Org/ComfyUI.git "refs/tags/${release_tag}^{}" | awk 'NR == 1 { print $1 }')" |
| 85 | + revision="${peeled_revision:-${direct_revision}}" |
| 86 | + if [[ ! "${revision}" =~ ^[0-9a-f]{40}$ ]]; then |
| 87 | + echo "::error::Unable to resolve commit for ${release_tag}" |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | +
|
| 91 | + latest_json="$(mktemp)" |
| 92 | + curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors \ |
| 93 | + -H "Accept: application/vnd.github+json" \ |
| 94 | + -H "Authorization: Bearer ${GH_TOKEN}" \ |
| 95 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 96 | + "https://api.github.com/repos/Comfy-Org/ComfyUI/releases/latest" \ |
| 97 | + -o "${latest_json}" |
| 98 | + latest_release_tag="$(jq -r '.tag_name' "${latest_json}")" |
| 99 | +
|
| 100 | + { |
| 101 | + echo "version=${version}" |
| 102 | + echo "release_tag=${release_tag}" |
| 103 | + echo "revision=${revision}" |
| 104 | + if [ "${INPUT_PUSH_LATEST}" = "true" ] && [ "${release_tag}" = "${latest_release_tag}" ]; then |
| 105 | + echo "push_latest=true" |
| 106 | + elif [ "${INPUT_PUSH_LATEST}" = "true" ]; then |
| 107 | + echo "::warning::Skipping latest because ${release_tag} is not upstream latest (${latest_release_tag})" >&2 |
| 108 | + echo "push_latest=false" |
| 109 | + else |
| 110 | + echo "push_latest=false" |
| 111 | + fi |
| 112 | + } >> "${GITHUB_OUTPUT}" |
| 113 | +
|
| 114 | + build-amd64: |
| 115 | + needs: resolve |
| 116 | + runs-on: ubuntu-24.04 |
| 117 | + outputs: |
| 118 | + digest: ${{ steps.build.outputs.digest }} |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@v6 |
| 122 | + |
| 123 | + - name: Set up Docker Buildx |
| 124 | + uses: docker/setup-buildx-action@v4 |
| 125 | + |
| 126 | + - name: Login to Docker Hub |
| 127 | + uses: docker/login-action@v4 |
| 128 | + with: |
| 129 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 130 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 131 | + |
| 132 | + - name: Build and push amd64 image |
| 133 | + id: build |
| 134 | + uses: docker/build-push-action@v7 |
| 135 | + with: |
| 136 | + context: comfyui |
| 137 | + file: comfyui/Dockerfile |
| 138 | + platforms: linux/amd64 |
| 139 | + build-args: | |
| 140 | + COMFYUI_VERSION=${{ needs.resolve.outputs.version }} |
| 141 | + COMFYUI_REVISION=${{ needs.resolve.outputs.revision }} |
| 142 | + outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 143 | + |
| 144 | + build-arm64: |
| 145 | + needs: resolve |
| 146 | + runs-on: ubuntu-24.04-arm |
| 147 | + outputs: |
| 148 | + digest: ${{ steps.build.outputs.digest }} |
| 149 | + steps: |
| 150 | + - name: Checkout |
| 151 | + uses: actions/checkout@v6 |
| 152 | + |
| 153 | + - name: Set up Docker Buildx |
| 154 | + uses: docker/setup-buildx-action@v4 |
| 155 | + |
| 156 | + - name: Login to Docker Hub |
| 157 | + uses: docker/login-action@v4 |
| 158 | + with: |
| 159 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 160 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 161 | + |
| 162 | + - name: Build and push arm64 image |
| 163 | + id: build |
| 164 | + uses: docker/build-push-action@v7 |
| 165 | + with: |
| 166 | + context: comfyui |
| 167 | + file: comfyui/Dockerfile |
| 168 | + platforms: linux/arm64 |
| 169 | + build-args: | |
| 170 | + COMFYUI_VERSION=${{ needs.resolve.outputs.version }} |
| 171 | + COMFYUI_REVISION=${{ needs.resolve.outputs.revision }} |
| 172 | + outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 173 | + |
| 174 | + create-manifest: |
| 175 | + needs: [resolve, build-amd64, build-arm64] |
| 176 | + runs-on: ubuntu-24.04 |
| 177 | + steps: |
| 178 | + - name: Set up Docker Buildx |
| 179 | + uses: docker/setup-buildx-action@v4 |
| 180 | + |
| 181 | + - name: Login to Docker Hub |
| 182 | + uses: docker/login-action@v4 |
| 183 | + with: |
| 184 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 185 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 186 | + |
| 187 | + - name: Create and verify multi-platform manifest |
| 188 | + shell: bash |
| 189 | + env: |
| 190 | + GH_TOKEN: ${{ github.token }} |
| 191 | + IMAGE: ${{ env.IMAGE_NAME }} |
| 192 | + VERSION: ${{ needs.resolve.outputs.version }} |
| 193 | + RELEASE_TAG: ${{ needs.resolve.outputs.release_tag }} |
| 194 | + PUSH_LATEST: ${{ needs.resolve.outputs.push_latest }} |
| 195 | + AMD64_DIGEST: ${{ needs.build-amd64.outputs.digest }} |
| 196 | + ARM64_DIGEST: ${{ needs.build-arm64.outputs.digest }} |
| 197 | + CANDIDATE_TAG: candidate-${{ github.run_id }}-${{ github.run_attempt }} |
| 198 | + run: | |
| 199 | + set -euo pipefail |
| 200 | +
|
| 201 | + for digest in "${AMD64_DIGEST}" "${ARM64_DIGEST}"; do |
| 202 | + if [[ ! "${digest}" =~ ^sha256:[0-9a-f]{64}$ ]]; then |
| 203 | + echo "::error::Invalid image digest: ${digest}" |
| 204 | + exit 1 |
| 205 | + fi |
| 206 | + done |
| 207 | +
|
| 208 | + verify_manifest() { |
| 209 | + local image_ref="$1" |
| 210 | + local manifest_json |
| 211 | + manifest_json="$(docker buildx imagetools inspect --format '{{json .Manifest}}' "${image_ref}")" |
| 212 | + printf '%s\n' "${manifest_json}" | jq -e ' |
| 213 | + (.digest | test("^sha256:[0-9a-f]{64}$")) and |
| 214 | + any(.manifests[]; .platform.os == "linux" and .platform.architecture == "amd64") and |
| 215 | + any(.manifests[]; .platform.os == "linux" and .platform.architecture == "arm64") and |
| 216 | + all(.manifests[]; |
| 217 | + .platform.os != "linux" or |
| 218 | + .platform.architecture == "amd64" or |
| 219 | + .platform.architecture == "arm64" |
| 220 | + ) |
| 221 | + ' >/dev/null |
| 222 | + } |
| 223 | +
|
| 224 | + candidate="${IMAGE}:${CANDIDATE_TAG}" |
| 225 | + docker buildx imagetools create \ |
| 226 | + -t "${candidate}" \ |
| 227 | + "${IMAGE}@${AMD64_DIGEST}" \ |
| 228 | + "${IMAGE}@${ARM64_DIGEST}" |
| 229 | + verify_manifest "${candidate}" |
| 230 | +
|
| 231 | + candidate_json="$(docker buildx imagetools inspect --format '{{json .Manifest}}' "${candidate}")" |
| 232 | + candidate_digest="$(printf '%s\n' "${candidate_json}" | jq -r '.digest')" |
| 233 | + publish_args=( |
| 234 | + --tag "${IMAGE}:${RELEASE_TAG}" |
| 235 | + --tag "${IMAGE}:${VERSION}" |
| 236 | + ) |
| 237 | + publish_latest=false |
| 238 | +
|
| 239 | + if [ "${PUSH_LATEST}" = "true" ]; then |
| 240 | + current_latest="$( |
| 241 | + curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors \ |
| 242 | + -H "Accept: application/vnd.github+json" \ |
| 243 | + -H "Authorization: Bearer ${GH_TOKEN}" \ |
| 244 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 245 | + "https://api.github.com/repos/Comfy-Org/ComfyUI/releases/latest" \ |
| 246 | + | jq -r '.tag_name' |
| 247 | + )" |
| 248 | + if [ "${RELEASE_TAG}" = "${current_latest}" ]; then |
| 249 | + publish_args+=(--tag "${IMAGE}:latest") |
| 250 | + publish_latest=true |
| 251 | + else |
| 252 | + echo "::warning::Skipping latest because upstream advanced to ${current_latest} during the build" |
| 253 | + fi |
| 254 | + fi |
| 255 | +
|
| 256 | + docker buildx imagetools create \ |
| 257 | + "${publish_args[@]}" \ |
| 258 | + "${IMAGE}@${candidate_digest}" |
| 259 | +
|
| 260 | + verify_manifest "${IMAGE}:${RELEASE_TAG}" |
| 261 | + verify_manifest "${IMAGE}:${VERSION}" |
| 262 | + if [ "${publish_latest}" = "true" ]; then |
| 263 | + verify_manifest "${IMAGE}:latest" |
| 264 | + fi |
0 commit comments