Moved the Source Code to a Source Directory #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A workflow, which builds the ComfyUI Docker image and publishes it to the GitHub Container Registry | |
| name: Create and publish a Docker image | |
| # Configures this workflow to run when a tag was pushed to the repository that matches the pattern "v[0-9]+.[0-9]+.[0-9]+", which is a semantic | |
| # versioning pattern; this token will be created when a new release is created; the release event cannot be used, because the docker/metadata-action | |
| # action does not support the release event | |
| on: | |
| push: | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+' | |
| # Defines two custom environment variables for the host name of the registry (ghcr.io for the GitHub Container Registry) and the name of the image, | |
| # which is set to the name of the repository | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| # This workflow has a single job, which builds the Docker image and publishes it to the GitHub Container Registry | |
| jobs: | |
| # The `build-and-publish` builds the Docker image, and publishes it to the GitHub Container Registry | |
| build-and-publish: | |
| # This job will run on an Ubuntu GitHub runner, which is a good default choice and it comes with Docker pre-installed | |
| runs-on: ubuntu-latest | |
| # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| # This job 1) checks out the repository, 2) logs in to the GitHub Container Registry, 3) extracts metadata for the Docker image, 4) builds and | |
| # pushes the Docker image, and 5) generates an artifact attestation for the image | |
| steps: | |
| # Checks out the repository so that the workflow can access the files in the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Installs Python, which is used to extract the version of ComfyUI and the ComfyUI Manager from the Dockerfile using a regular expression | |
| - name: Install Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| # Logs in to the GitHub Container Registry registry using the account of the user that triggered the workflow run and the GitHub token that is | |
| # an automatically generated secret that is usually only used to access the repository (the permissions defined above allow the token to also | |
| # publish Docker images to the GitHub Container Registry) that will publish the packages; once published, the packages are scoped to the account | |
| # defined here | |
| - name: Log in to the GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Extracts the versions of ComfyUI and the ComfyUI Manager from the Dockerfile using a Python script; the versions are written to the output | |
| # file, which are available in subsequent steps under steps.versions.outputs.COMFYUI_VERSION and steps.versions.outputs.COMFYUI_MANAGER_VERSION; | |
| # the versions are used to tag the Docker image, so that users know which versions of ComfyUI and the ComfyUI Manager are included in the image | |
| - name: Extract ComfyUI & ComfyUI Manager Versions | |
| id: versions | |
| shell: python | |
| run: | | |
| import os | |
| import re | |
| def get_version(version_variable_name: str) -> str: | |
| with open('source/Dockerfile', mode='r', encoding='utf-8') as dockerfile: | |
| match = re.search( | |
| rf'^ARG {version_variable_name}=v?([0-9\.-a-z]+)$', | |
| dockerfile.read(), | |
| re.MULTILINE | |
| ) | |
| return match.group(1) if match else 'unknown' | |
| with open(os.environ['GITHUB_OUTPUT'], mode='a', encoding='utf-8') as output_file: | |
| output_file.write(f'COMFYUI_VERSION={get_version('COMFYUI_VERSION')}\n') | |
| output_file.write(f'COMFYUI_MANAGER_VERSION={get_version('COMFYUI_MANAGER_VERSION')}\n') | |
| # Extracts metadata from the Git repository and GitHub, which are then used to label and tag the Docker image that will be build in the next | |
| # step; the "id" property specifies that the output of this step will be available in subsequent steps under the name "metadata"; tags for the | |
| # SHA of the commit, the full semantic version extracted from the current tag (e.g., tag "v1.2.3" will be extracted as "1.2.3"), and the major | |
| # and minor version extracted from the current version (e.g., tag "v1.2.3" will be extracted as "1.2"), as well as a "latest" tag are added; | |
| # besides the hardcoded labels for the title and authors of the image, the GitHub description, GitHub license, GitHub revision, GitHub source | |
| # URL, GitHub URL, and creation date and time are extracted as labels | |
| - name: Extract Tags & Labels for Docker | |
| id: docker-image-metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=sha | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{version}}-comfyui-${{ steps.versions.outputs.COMFYUI_VERSION }} | |
| type=semver,pattern={{version}}-comfyui-${{ steps.versions.outputs.COMFYUI_VERSION }}-comfyui-manager-${{ steps.versions.outputs.COMFYUI_MANAGER_VERSION }} | |
| labels: | | |
| org.opencontainers.image.title=ComfyUI Docker | |
| org.opencontainers.image.authors=David Neumann <[email protected]> | |
| # Builds the Docker image for ComfyUI; if the build succeeds, it is pushed to the GitHub Container Registry; the "context" parameter specifies | |
| # the build context, which is the directory that contains the Dockerfile; the tags and labels extracted in the previous step are used to tag | |
| # and label the image | |
| - name: Build and Push Docker Image | |
| id: build-and-push-docker-image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: source | |
| push: true | |
| tags: ${{ steps.docker-image-metadata.outputs.tags }} | |
| labels: ${{ steps.docker-image-metadata.outputs.labels }} | |
| # Generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built; it increases supply chain | |
| # security for people who consume the image | |
| - name: Generate Artifact Attestation | |
| uses: actions/attest-build-provenance@v1 | |
| with: | |
| subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | |
| subject-digest: ${{ steps.build-and-push-docker-image.outputs.digest }} | |
| push-to-registry: true |