|
| 1 | + |
| 2 | +# A workflow, which builds the ComfyUI Docker image and publishes it to the GitHub Container Registry |
| 3 | +name: Create and publish a Docker image |
| 4 | + |
| 5 | +# 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 |
| 6 | +# versioning pattern; this token will be created when a new release is created; the release event cannot be used, because the docker/metadata-action |
| 7 | +# action does not support the release event |
| 8 | +on: |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 12 | + |
| 13 | +# 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, |
| 14 | +# which is set to the name of the repository |
| 15 | +env: |
| 16 | + REGISTRY: ghcr.io |
| 17 | + IMAGE_NAME: ${{ github.repository }} |
| 18 | + |
| 19 | +# This workflow has a single job, which builds the Docker image and publishes it to the GitHub Container Registry |
| 20 | +jobs: |
| 21 | + |
| 22 | + # The `build-and-publish` builds the Docker image, and publishes it to the GitHub Container Registry |
| 23 | + build-and-publish: |
| 24 | + |
| 25 | + # This job will run on an Ubuntu GitHub runner, which is a good default choice and it comes with Docker pre-installed |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + packages: write |
| 32 | + attestations: write |
| 33 | + id-token: write |
| 34 | + |
| 35 | + # 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 |
| 36 | + # pushes the Docker image, and 5) generates an artifact attestation for the image |
| 37 | + steps: |
| 38 | + |
| 39 | + # Checks out the repository so that the workflow can access the files in the repository |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + # 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 |
| 44 | + # an automatically generated secret that is usually only used to access the repository (the permissions defined above allow the token to also |
| 45 | + # publish Docker images to the GitHub Container Registry) that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 46 | + - name: Log in to the GitHub Container Registry |
| 47 | + uses: docker/login-action@v3 |
| 48 | + with: |
| 49 | + registry: ${{ env.REGISTRY }} |
| 50 | + username: ${{ github.actor }} |
| 51 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + # 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 |
| 54 | + # step; the "id" property specifies that the output of this step will be available in subsequent steps under the name "metadata"; tags for the |
| 55 | + # 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 |
| 56 | + # 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; |
| 57 | + # besides the hardcoded labels for the title and authors of the image, the GitHub description, GitHub license, GitHub revision, GitHub source |
| 58 | + # URL, GitHub URL, and creation date and time are extracted as labels |
| 59 | + - name: Extract Tags & Labels for Docker |
| 60 | + id: metadata |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 64 | + tags: | |
| 65 | + type=sha |
| 66 | + type=semver,pattern={{version}} |
| 67 | + type=semver,pattern={{major}}.{{minor}} |
| 68 | + labels: | |
| 69 | + org.opencontainers.image.title=ComfyUI Docker |
| 70 | + org.opencontainers.image.authors=David Neumann <david.neumann@lecode.de> |
| 71 | +
|
| 72 | + # Builds the Docker image for ComfyUI; if the build succeeds, it is pushed to the GitHub Container Registry; the "context" parameter specifies |
| 73 | + # the build context, which is the directory that contains the Dockerfile; the tags and labels extracted in the previous step are used to tag |
| 74 | + # and label the image |
| 75 | + - name: Build and Push Docker Image |
| 76 | + id: push |
| 77 | + uses: docker/build-push-action@v6 |
| 78 | + with: |
| 79 | + context: . |
| 80 | + push: true |
| 81 | + tags: ${{ steps.metadata.outputs.tags }} |
| 82 | + labels: ${{ steps.metadata.outputs.labels }} |
| 83 | + |
| 84 | + # Generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built; it increases supply chain |
| 85 | + # security for people who consume the image |
| 86 | + - name: Generate Artifact Attestation |
| 87 | + uses: actions/attest-build-provenance@v1 |
| 88 | + with: |
| 89 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 90 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 91 | + push-to-registry: true |
0 commit comments