Skip to content

Commit

Permalink
Refactor Dockerfiles for serverless functions
Browse files Browse the repository at this point in the history
  • Loading branch information
VikramxD committed Oct 24, 2024
1 parent 846c47e commit 8c11dc5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 70 deletions.
33 changes: 15 additions & 18 deletions serverless/image-to-video/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH="/usr/local/bin:$PATH"
PYTHONPATH=/app

# Set up working directory
WORKDIR /app
Expand All @@ -14,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3-pip \
python3.11-dev \
python3.11-venv \
ffmpeg \
libsm6 \
libxext6 \
Expand All @@ -22,33 +22,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Create symbolic link for python and pip
RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip

# Create user and set permissions
RUN useradd -m -u 1000 user && \
chown -R user:user /app

# Install base packages as root
RUN pip install --no-cache-dir -U pip setuptools wheel
# Switch to user
USER user

# Create and activate virtual environment
RUN python3.11 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"

# Copy all required files and directories
# Copy necessary files maintaining structure
COPY --chown=user:user api/ /app/api/
COPY --chown=user:user scripts/ /app/scripts/
COPY --chown=user:user configs/ /app/configs/
COPY --chown=user:user setup.py /app/

# Install Python dependencies as root
RUN pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod==1.3.3 && \
# Install dependencies in venv
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod && \
pip install --no-cache-dir -e .

# Switch to user after installations
USER user

# Copy the service file
COPY --chown=user:user serverless/image-to-video/run_image-to-video.py .



CMD ["/usr/bin/python3.11", "run_image-to-video.py"]
CMD ["python", "run_image-to-video.py"]
32 changes: 15 additions & 17 deletions serverless/inpainting/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH="/usr/local/bin:$PATH"
PYTHONPATH=/app

# Set up working directory
WORKDIR /app
Expand All @@ -14,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3-pip \
python3.11-dev \
python3.11-venv \
ffmpeg \
libsm6 \
libxext6 \
Expand All @@ -22,32 +22,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Create symbolic link for python and pip
RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip

# Create user and set permissions
RUN useradd -m -u 1000 user && \
chown -R user:user /app

# Install base packages as root
RUN pip install --no-cache-dir -U pip setuptools wheel
# Switch to user
USER user

# Create and activate virtual environment
RUN python3.11 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"

# Copy all required files and directories
# Copy necessary files maintaining structure
COPY --chown=user:user api/ /app/api/
COPY --chown=user:user scripts/ /app/scripts/
COPY --chown=user:user configs/ /app/configs/
COPY --chown=user:user setup.py /app/

# Install Python dependencies as root
RUN pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod==1.3.3 && \
# Install dependencies in venv
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod && \
pip install --no-cache-dir -e .

# Switch to user after installations
USER user

# Copy the service file
COPY --chown=user:user serverless/inpainting/run_inpainting.py .


CMD ["/usr/bin/python3.11", "run_inpainting.py"]
CMD ["python", "run_inpainting.py"]
32 changes: 15 additions & 17 deletions serverless/outpainting/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH="/usr/local/bin:$PATH"
PYTHONPATH=/app

# Set up working directory
WORKDIR /app
Expand All @@ -14,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3-pip \
python3.11-dev \
python3.11-venv \
ffmpeg \
libsm6 \
libxext6 \
Expand All @@ -22,32 +22,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Create symbolic link for python and pip
RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip

# Create user and set permissions
RUN useradd -m -u 1000 user && \
chown -R user:user /app

# Install base packages as root
RUN pip install --no-cache-dir -U pip setuptools wheel
# Switch to user
USER user

# Create and activate virtual environment
RUN python3.11 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"

# Copy all required files and directories
# Copy necessary files maintaining structure
COPY --chown=user:user api/ /app/api/
COPY --chown=user:user scripts/ /app/scripts/
COPY --chown=user:user configs/ /app/configs/
COPY --chown=user:user setup.py /app/

# Install Python dependencies as root
RUN pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod==1.3.3 && \
# Install dependencies in venv
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod && \
pip install --no-cache-dir -e .

# Switch to user after installations
USER user

# Copy the service file
COPY --chown=user:user serverless/outpainting/run_outpainting.py .


CMD ["/usr/bin/python3.11", "run_outpainting.py"]
CMD ["python", "run_outpainting.py"]
33 changes: 15 additions & 18 deletions serverless/text-to-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH="/usr/local/bin:$PATH"
PYTHONPATH=/app

# Set up working directory
WORKDIR /app
Expand All @@ -14,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3-pip \
python3.11-dev \
python3.11-venv \
ffmpeg \
libsm6 \
libxext6 \
Expand All @@ -22,33 +22,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Create symbolic link for python and pip
RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip

# Create user and set permissions
RUN useradd -m -u 1000 user && \
chown -R user:user /app

# Install base packages as root
RUN pip install --no-cache-dir -U pip setuptools wheel
# Switch to user
USER user

# Create and activate virtual environment
RUN python3.11 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"

# Copy all required files and directories
# Copy necessary files maintaining structure
COPY --chown=user:user api/ /app/api/
COPY --chown=user:user scripts/ /app/scripts/
COPY --chown=user:user configs/ /app/configs/
COPY --chown=user:user setup.py /app/

# Install Python dependencies as root
RUN pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod==1.3.3 && \
# Install dependencies in venv
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -r api/requirements.txt && \
pip install --no-cache-dir runpod && \
pip install --no-cache-dir -e .

# Switch to user after installations
USER user

# Copy the service file
COPY --chown=user:user serverless/text-to-image/run_text-to-image.py .



CMD ["/usr/bin/python3.11", "run_text-to-image.py"]
CMD ["python", "run_text-to-image.py"]

0 comments on commit 8c11dc5

Please sign in to comment.