Skip to content

Commit 833ac6a

Browse files
Added a CI/CD pipeline for building and publishing
Created a GitHub Actions workflow, which builds the ComfyUI Docker image and publishes it to the GitHub Container Registry. The workflow is triggered when a tag is pushed, which occurs when a release is created. The workflow automatically extracts information such as description, version, and URL from the repository and uses it to tag and label the Docker image. For this reason, the labels were removed from the Dockerfile. The documentation in the read me was updated to reflect the changes.
1 parent 63c74d9 commit 833ac6a

File tree

3 files changed

+127
-22
lines changed

3 files changed

+127
-22
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

Dockerfile

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
# This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch
33
FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
44

5-
# Adds some metadata to the resulting Docker image via labels, the label names are standardized by the Open Container Initiative (OCI) in their Image
6-
# Specification Annotation
7-
LABEL org.opencontainers.image.authors="David Neumann <david.neumann@lecode.de>"
8-
LABEL org.opencontainers.image.url="https://github.com/lecode-official/comfyui-docker"
9-
LABEL org.opencontainers.image.documentation="https://github.com/lecode-official/comfyui-docker/tree/main/docs"
10-
LABEL org.opencontainers.image.source="https://github.com/lecode-official/comfyui-docker/tree/main"
11-
LABEL org.opencontainers.image.version="0.1.0"
12-
LABEL org.opencontainers.image.vendor="David Neumann"
13-
LABEL org.opencontainers.image.licenses="MIT"
14-
LABEL org.opencontainers.image.title="ComfyUI Docker"
15-
LABEL org.opencontainers.image.description="A Docker image running ComfyUI."
16-
175
# Installs Git, because ComfyUI and the ComfyUI Manager are installed by cloning their respective Git repositories
186
RUN apt update --assume-yes && \
197
apt install --assume-yes git

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,58 @@ To get started, you have to install [Docker](https://www.docker.com/). This can
88

99
To enable the usage of NVIDIA GPUs, the NVIDIA Container Toolkit must be installed. The installation process is detailed in the [official documentation](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
1010

11-
## Building
11+
## Installation
1212

13-
The image can be build using the following command:
13+
The ComfyUI Docker image is available from the [GitHub Container Registry](https://ghcr.io). Installing ComfyUI is as simple as pulling the image and starting a container, which can be achieved using the following command:
1414

15-
```sh
16-
docker build --tag lecode/comfyui-docker:latest .
15+
```shell
16+
docker run \
17+
--name comfyui \
18+
--detach \
19+
--restart unless-stopped \
20+
--volume <path/to/models/folder>:/opt/comfyui/models \
21+
--publish 8188:8188 \
22+
--runtime nvidia \
23+
--gpus all \
24+
ghcr.io/lecode-official/comfyui-docker:latest
1725
```
1826

19-
## Running
27+
Please note, that the `<path/to/models/folder>` must be replaced with a path to a folder on the host system where the models will be stored, e.g., `$HOME/.comfyui`.
28+
29+
The `--detach` flag causes the container to run in the background and `--restart unless-stopped` configures the Docker Engine to automatically restart the container if it stopped itself, experienced an error, or the computer was shutdown, unless you explicitly stopped the container using `docker stop`. This means that ComfyUI will be automatically started in the background when you boot your computer. The `--runtime nvidia` and `--gpus all` arguments enable ComfyUI to access the GPUs of your host system. If you do not want to expose all GPUs, you can specify the desired GPU index or ID instead.
30+
31+
After the container has started, you can navigate to [localhost:8188](http://localhost:8188) to access ComfyUI.
2032

21-
The built image can be run like so:
33+
If you want to stop ComfyUI, you can use the following commands:
2234

23-
```sh
35+
```shell
36+
docker stop comfyui
37+
docker rm comfyui
38+
```
39+
40+
## Building
41+
42+
If you want to use the bleeding edge development version of the Docker image, you can also clone the repository and build the image yourself:
43+
44+
```shell
45+
git clone https://github.com/lecode-official/comfyui-docker.git
46+
docker build --tag lecode/comfyui-docker:latest comfyui-docker
47+
```
48+
49+
Now, a container can be started like so:
50+
51+
```shell
2452
docker run \
2553
--name comfyui \
2654
--detach \
2755
--restart unless-stopped \
2856
--volume <path/to/models/folder>:/opt/comfyui/models \
2957
--publish 8188:8188 \
30-
--runtime=nvidia \
58+
--runtime nvidia \
3159
--gpus all \
3260
lecode/comfyui-docker:latest
3361
```
3462

35-
Please note, that the `<path/to/models/folder>` must be replaced with a path to a folder on the host system where the models will be stored, e.g., `$HOME/.comfyui`.
36-
3763
## License
3864

3965
The ComfyUI Docker image is licensed under the [MIT License](LICENSE). [ComfyUI](https://github.com/comfyanonymous/ComfyUI/blob/master/LICENSE) and the [ComfyUI Manager](https://github.com/ltdrdata/ComfyUI-Manager/blob/main/LICENSE.txt) are both licensed under the GPL 3.0 license.

0 commit comments

Comments
 (0)