Skip to content

Commit 2abf13f

Browse files
committed
feat: create separate image for dev and prod
1 parent f3148f7 commit 2abf13f

File tree

8 files changed

+103
-182
lines changed

8 files changed

+103
-182
lines changed

flux1-dev-lora-worker-project/.runpodignore renamed to .runpodignore

File renamed without changes.

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# Use RunPod's base image
21
FROM runpod/base:0.6.1-cuda12.2.0
32

4-
# Only install absolutely necessary packages for your project
5-
RUN apt-get update && apt-get install -y ffmpeg aria2 git unzip
3+
# Environment variable to differentiate between development and production
4+
ARG ENVIRONMENT=development
5+
ENV ENVIRONMENT=${ENVIRONMENT}
66

7-
# Clone the ComfyUI repository
7+
# Install necessary system packages
8+
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg aria2 git unzip && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Clone the ComfyUI repository
812
RUN git clone https://github.com/comfyanonymous/ComfyUI /content/ComfyUI
913

1014
# Download required model files
@@ -18,8 +22,21 @@ RUN mkdir -p /content/ComfyUI/models/unet && \
1822
mkdir -p /content/ComfyUI/models/loras && \
1923
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M "https://civitai.com/api/download/models/896422?type=Model&format=SafeTensor" -d /content/ComfyUI/models/loras -o zanshou-kin-flux-ueno-manga-style.safetensors
2024

21-
# Reset the working directory to the base image's root
22-
WORKDIR /
25+
# Copy requirements.txt earlier so it can be used for installing dependencies
26+
COPY builder/requirements.txt /requirements.txt
27+
28+
# Install Python dependencies if building for production
29+
RUN if [ "$ENVIRONMENT" = "production" ]; then \
30+
python3.10 -m pip install --upgrade pip && \
31+
python3.10 -m pip install --no-cache-dir -r /requirements.txt; \
32+
fi
33+
34+
# Copy all files from src to the root directory
35+
COPY ./src/ /
2336

24-
# Keep the base image's entrypoint
25-
CMD ["/start.sh"]
37+
# Final CMD based on environment
38+
CMD if [ "$ENVIRONMENT" = "development" ]; then \
39+
/start.sh; \
40+
else \
41+
python3.10 -u /handler.py; \
42+
fi

builder/requirements.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Required Python packages get listed here, one per line.
2+
# Lock the version number to avoid unexpected changes.
3+
4+
# You can also install packages from a git repository, e.g.:
5+
# git+https://github.com/runpod/runpod-python.git
6+
# To learn more, see https://pip.pypa.io/en/stable/reference/requirements-file-format/
7+
8+
torch
9+
torchvision
10+
torchaudio
11+
opencv-python
12+
imageio
13+
imageio-ffmpeg
14+
ffmpeg-python
15+
av
16+
runpod
17+
xformers==0.0.25
18+
torchsde==0.2.6
19+
einops==0.8.0
20+
diffusers==0.28.0
21+
transformers==4.41.2
22+
accelerate==0.30.1
23+
numpy<2
24+

docker-bake.hcl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
variable "DOCKERHUB_REPO" {
2+
default = "timpietruskyblibla"
3+
}
4+
5+
variable "DOCKERHUB_IMG" {
6+
default = "flux-1-dev-lora-worker"
7+
}
8+
9+
variable "RELEASE_VERSION" {
10+
default = "latest"
11+
}
12+
13+
group "default" {
14+
targets = ["development", "production"]
15+
}
16+
17+
target "development" {
18+
context = "."
19+
dockerfile = "Dockerfile"
20+
args = {
21+
ENVIRONMENT = "development"
22+
}
23+
tags = ["${DOCKERHUB_REPO}/${DOCKERHUB_IMG}:dev"]
24+
}
25+
26+
target "production" {
27+
context = "."
28+
dockerfile = "Dockerfile"
29+
args = {
30+
ENVIRONMENT = "production"
31+
}
32+
tags = ["${DOCKERHUB_REPO}/${DOCKERHUB_IMG}:latest"]
33+
}

model.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
2-
"positive_prompt": "A cat holding a sign that says 'I LOVE TOST!'",
3-
"seed": 0,
4-
"steps": 20,
2+
"input": {
3+
"positive_prompt": "a black and white drawing of a city",
4+
"width": 512,
5+
"height": 512,
6+
"seed": 13379,
7+
"steps": 24,
58
"guidance": 3.5,
6-
"lora_url": "https://huggingface.co/TostAI/flux-1-dev-lora/resolve/main/8iiu0y.safetensors",
7-
"lora_strength_model": 1,
8-
"lora_strength_clip": 1,
9+
"lora_strength_model": 0.8,
10+
"lora_strength_clip": 0.8,
911
"sampler_name": "euler",
1012
"scheduler": "simple",
11-
"width": 1024,
12-
"height": 1024
13-
}
13+
"job_id": "test-job-123",
14+
"lora_name": "zanshou-kin-flux-ueno-manga-style.safetensors"
15+
}
16+
}

flux1-dev-lora-worker-project/src/handler.py renamed to src/handler.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import os
2-
import json
3-
import requests
42
import runpod
53
import random
64
import time
@@ -13,11 +11,9 @@
1311

1412
sys.path.append("/content/ComfyUI")
1513

16-
import nodes
1714
from nodes import NODE_CLASS_MAPPINGS
1815
from comfy_extras import nodes_custom_sampler
1916
from comfy_extras import nodes_flux
20-
from comfy import model_management
2117

2218
# Initialize Model Loaders
2319
DualCLIPLoader = NODE_CLASS_MAPPINGS["DualCLIPLoader"]()
@@ -64,17 +60,18 @@ def generate(input):
6460
width = values.get("width", 512)
6561
height = values.get("height", 512)
6662
seed = values.get("seed", 0)
67-
steps = values.get("steps", 50)
68-
guidance = values.get("guidance", 7.5)
63+
steps = values.get("steps", 25)
64+
guidance = values.get("guidance", 3.5)
6965
lora_strength_model = values.get("lora_strength_model", 0.8)
7066
lora_strength_clip = values.get("lora_strength_clip", 0.8)
71-
sampler_name = values.get("sampler_name", "Euler")
72-
scheduler = values.get("scheduler", "default")
67+
sampler_name = values.get("sampler_name", "euler")
68+
scheduler = values.get("scheduler", "simple")
7369
job_id = values.get("job_id", "test-job-123")
7470
lora_name = values.get("lora_name", "zanshou-kin-flux-ueno-manga-style.safetensors")
71+
image_path = None
7572

7673
# Path to the LoRA model based on lora_name
77-
lora_file_path = f"models/loras/{lora_name}"
74+
lora_file_path = f"/content/ComfyUI/models/loras/{lora_name}"
7875

7976
# Validate if the specified LoRA model exists
8077
if not os.path.exists(lora_file_path):
@@ -95,9 +92,10 @@ def generate(input):
9592
print(f"Using seed: {seed}")
9693

9794
try:
95+
9896
# Load LoRA models from the specified file
9997
unet_lora, clip_lora = LoraLoader.load_lora(
100-
unet, clip, lora_file_path, lora_strength_model, lora_strength_clip
98+
unet, clip, lora_name, lora_strength_model, lora_strength_clip
10199
)
102100

103101
# Encode the positive prompt
@@ -151,7 +149,7 @@ def generate(input):
151149

152150
finally:
153151
# Clean up the generated image file
154-
if os.path.exists(image_path):
152+
if image_path is not None and os.path.exists(image_path):
155153
os.remove(image_path)
156154

157155

worker_runpod.py

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)