Skip to content

Commit fff49a5

Browse files
committed
Refactor Dockerfiles for serverless functions
1 parent f868688 commit fff49a5

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

serverless/image-to-video/Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
66
PATH="/home/user/.local/bin:$PATH" \
77
PYTHONPATH=/app
88

9-
# Set working directory in the container
109
WORKDIR /app
1110

12-
# Install system dependencies, Python, and build tools
11+
# Install system dependencies
1312
RUN apt-get update && apt-get install -y --no-install-recommends \
1413
python3.11 \
1514
python3-pip \
@@ -23,30 +22,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2322
build-essential \
2423
&& rm -rf /var/lib/apt/lists/*
2524

26-
# Create a non-root user to run the application
25+
# Create user
2726
RUN useradd -m -u 1000 user
2827

29-
# Create a virtual environment and give ownership to the non-root user
28+
# Create venv
3029
RUN python3.11 -m venv /home/user/venv && chown -R user:user /home/user/venv
3130
ENV PATH="/home/user/venv/bin:$PATH"
3231

33-
# Switch to the non-root user
32+
# Switch to user
3433
USER user
3534

36-
# Copy required directories and files
35+
# Copy necessary files
36+
COPY --chown=user:user api/requirements.txt .
37+
COPY --chown=user:user setup.py .
3738
COPY --chown=user:user scripts/ scripts/
3839
COPY --chown=user:user api/ api/
39-
COPY --chown=user:user setup.py .
40-
COPY --chown=user:user api/requirements.txt api/requirements.txt
40+
COPY --chown=user:user serverless/image-to-video/run_image-to-video.py .
4141

4242
# Install Python dependencies
4343
RUN pip install --no-cache-dir -U pip setuptools wheel && \
44-
pip install --no-cache-dir -r api/requirements.txt && \
44+
pip install --no-cache-dir -r requirements.txt && \
4545
pip install --no-cache-dir runpod && \
4646
pip install --no-cache-dir -e .
4747

48-
# Copy the RunPod handler
49-
COPY --chown=user:user serverless/image-to-video/run_image-to-video.py .
50-
51-
# Command to run the RunPod handler
48+
# Command to run the handler
5249
CMD ["python", "run_image-to-video.py"]

serverless/inpainting/Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
66
PATH="/home/user/.local/bin:$PATH" \
77
PYTHONPATH=/app
88

9-
# Set working directory in the container
109
WORKDIR /app
1110

12-
# Install system dependencies, Python, and build tools
11+
# Install system dependencies
1312
RUN apt-get update && apt-get install -y --no-install-recommends \
1413
python3.11 \
1514
python3-pip \
@@ -23,30 +22,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2322
build-essential \
2423
&& rm -rf /var/lib/apt/lists/*
2524

26-
# Create a non-root user to run the application
25+
# Create user
2726
RUN useradd -m -u 1000 user
2827

29-
# Create a virtual environment and give ownership to the non-root user
28+
# Create venv
3029
RUN python3.11 -m venv /home/user/venv && chown -R user:user /home/user/venv
3130
ENV PATH="/home/user/venv/bin:$PATH"
3231

33-
# Switch to the non-root user
32+
# Switch to user
3433
USER user
3534

36-
# Copy required directories and files
35+
# Copy necessary files
36+
COPY --chown=user:user api/requirements.txt .
37+
COPY --chown=user:user setup.py .
3738
COPY --chown=user:user scripts/ scripts/
3839
COPY --chown=user:user api/ api/
39-
COPY --chown=user:user setup.py .
40-
COPY --chown=user:user api/requirements.txt api/requirements.txt
40+
COPY --chown=user:user serverless/inpainting/run_inpainting.py .
4141

4242
# Install Python dependencies
4343
RUN pip install --no-cache-dir -U pip setuptools wheel && \
44-
pip install --no-cache-dir -r api/requirements.txt && \
44+
pip install --no-cache-dir -r requirements.txt && \
4545
pip install --no-cache-dir runpod && \
4646
pip install --no-cache-dir -e .
4747

48-
# Copy the RunPod handler
49-
COPY --chown=user:user serverless/inpainting/run_inpainting.py .
50-
51-
# Command to run the RunPod handler
48+
# Command to run the handler
5249
CMD ["python", "run_inpainting.py"]

serverless/outpainting/Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
66
PATH="/home/user/.local/bin:$PATH" \
77
PYTHONPATH=/app
88

9-
# Set working directory in the container
109
WORKDIR /app
1110

12-
# Install system dependencies, Python, and build tools
11+
# Install system dependencies
1312
RUN apt-get update && apt-get install -y --no-install-recommends \
1413
python3.11 \
1514
python3-pip \
@@ -23,30 +22,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2322
build-essential \
2423
&& rm -rf /var/lib/apt/lists/*
2524

26-
# Create a non-root user to run the application
25+
# Create user
2726
RUN useradd -m -u 1000 user
2827

29-
# Create a virtual environment and give ownership to the non-root user
28+
# Create venv
3029
RUN python3.11 -m venv /home/user/venv && chown -R user:user /home/user/venv
3130
ENV PATH="/home/user/venv/bin:$PATH"
3231

33-
# Switch to the non-root user
32+
# Switch to user
3433
USER user
3534

36-
# Copy required directories and files
35+
# Copy necessary files
36+
COPY --chown=user:user api/requirements.txt .
37+
COPY --chown=user:user setup.py .
3738
COPY --chown=user:user scripts/ scripts/
3839
COPY --chown=user:user api/ api/
39-
COPY --chown=user:user setup.py .
40-
COPY --chown=user:user api/requirements.txt api/requirements.txt
40+
COPY --chown=user:user serverless/outpainting/run_outpainting.py .
4141

4242
# Install Python dependencies
4343
RUN pip install --no-cache-dir -U pip setuptools wheel && \
44-
pip install --no-cache-dir -r api/requirements.txt && \
44+
pip install --no-cache-dir -r requirements.txt && \
4545
pip install --no-cache-dir runpod && \
4646
pip install --no-cache-dir -e .
4747

48-
# Copy the RunPod handler
49-
COPY --chown=user:user outpainting/run_outpainting.py .
50-
51-
# Command to run the RunPod handler
48+
# Command to run the handler
5249
CMD ["python", "run_outpainting.py"]

serverless/text-to-image/Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
66
PATH="/home/user/.local/bin:$PATH" \
77
PYTHONPATH=/app
88

9-
# Set working directory in the container
109
WORKDIR /app
1110

12-
# Install system dependencies, Python, and build tools
11+
# Install system dependencies
1312
RUN apt-get update && apt-get install -y --no-install-recommends \
1413
python3.11 \
1514
python3-pip \
@@ -23,30 +22,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2322
build-essential \
2423
&& rm -rf /var/lib/apt/lists/*
2524

26-
# Create a non-root user to run the application
25+
# Create user
2726
RUN useradd -m -u 1000 user
2827

29-
# Create a virtual environment and give ownership to the non-root user
28+
# Create venv
3029
RUN python3.11 -m venv /home/user/venv && chown -R user:user /home/user/venv
3130
ENV PATH="/home/user/venv/bin:$PATH"
3231

33-
# Switch to the non-root user
32+
# Switch to user
3433
USER user
3534

36-
# Copy required directories and files
35+
# Copy necessary files
36+
COPY --chown=user:user api/requirements.txt .
37+
COPY --chown=user:user setup.py .
3738
COPY --chown=user:user scripts/ scripts/
3839
COPY --chown=user:user api/ api/
39-
COPY --chown=user:user setup.py .
40-
COPY --chown=user:user api/requirements.txt api/requirements.txt
40+
COPY --chown=user:user serverless/text-to-image/run_text-to-image.py .
4141

4242
# Install Python dependencies
4343
RUN pip install --no-cache-dir -U pip setuptools wheel && \
44-
pip install --no-cache-dir -r api/requirements.txt && \
44+
pip install --no-cache-dir -r requirements.txt && \
4545
pip install --no-cache-dir runpod && \
4646
pip install --no-cache-dir -e .
4747

48-
# Copy the RunPod handler
49-
COPY --chown=user:user text-to-image/run_text-to-image.py .
50-
51-
# Command to run the RunPod handler
48+
# Command to run the handler
5249
CMD ["python", "run_text-to-image.py"]

0 commit comments

Comments
 (0)