From 38c2f8733d993363d35e29fdb08e3af72af3b69c Mon Sep 17 00:00:00 2001 From: Vikramjeet Date: Thu, 24 Oct 2024 21:13:33 +0530 Subject: [PATCH] Refactor Dockerfiles for serverless functions --- serverless/image-to-video/Dockerfile | 18 ++---------------- serverless/inpainting/Dockerfile | 18 ++---------------- serverless/outpainting/Dockerfile | 18 ++---------------- serverless/text-to-image/Dockerfile | 18 ++---------------- 4 files changed, 8 insertions(+), 64 deletions(-) diff --git a/serverless/image-to-video/Dockerfile b/serverless/image-to-video/Dockerfile index 04abc7a..14ff82d 100644 --- a/serverless/image-to-video/Dockerfile +++ b/serverless/image-to-video/Dockerfile @@ -1,14 +1,11 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app -# Set up working directory WORKDIR /app -# Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3-pip \ @@ -22,30 +19,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* -# Create user and set permissions RUN useradd -m -u 1000 user && \ chown -R user:user /app -# Switch to user USER user -# Create and activate virtual environment RUN python3.11 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" -# 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/ +COPY --chown=user:user . . -# 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 . -# Copy the service file -COPY --chown=user:user serverless/image-to-video/run_image-to-video.py . - -CMD ["python", "run_image-to-video.py"] \ No newline at end of file +CMD ["python", "serverless/image-to-video/run_image-to-video.py"] \ No newline at end of file diff --git a/serverless/inpainting/Dockerfile b/serverless/inpainting/Dockerfile index adb3603..e215e6d 100644 --- a/serverless/inpainting/Dockerfile +++ b/serverless/inpainting/Dockerfile @@ -1,14 +1,11 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app -# Set up working directory WORKDIR /app -# Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3-pip \ @@ -22,30 +19,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* -# Create user and set permissions RUN useradd -m -u 1000 user && \ chown -R user:user /app -# Switch to user USER user -# Create and activate virtual environment RUN python3.11 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" -# 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/ +COPY --chown=user:user . . -# 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 . -# Copy the service file -COPY --chown=user:user serverless/inpainting/run_inpainting.py . - -CMD ["python", "run_inpainting.py"] \ No newline at end of file +CMD ["python", "serverless/inpainting/run_inpainting.py"] \ No newline at end of file diff --git a/serverless/outpainting/Dockerfile b/serverless/outpainting/Dockerfile index a0f572a..46ec043 100644 --- a/serverless/outpainting/Dockerfile +++ b/serverless/outpainting/Dockerfile @@ -1,14 +1,11 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app -# Set up working directory WORKDIR /app -# Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3-pip \ @@ -22,30 +19,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* -# Create user and set permissions RUN useradd -m -u 1000 user && \ chown -R user:user /app -# Switch to user USER user -# Create and activate virtual environment RUN python3.11 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" -# 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/ +COPY --chown=user:user . . -# 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 . -# Copy the service file -COPY --chown=user:user serverless/outpainting/run_outpainting.py . - -CMD ["python", "run_outpainting.py"] \ No newline at end of file +CMD ["python", "serverless/outpainting/run_outpainting.py"] \ No newline at end of file diff --git a/serverless/text-to-image/Dockerfile b/serverless/text-to-image/Dockerfile index 328f0f3..f5c1971 100644 --- a/serverless/text-to-image/Dockerfile +++ b/serverless/text-to-image/Dockerfile @@ -1,14 +1,11 @@ FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app -# Set up working directory WORKDIR /app -# Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3-pip \ @@ -22,30 +19,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* -# Create user and set permissions RUN useradd -m -u 1000 user && \ chown -R user:user /app -# Switch to user USER user -# Create and activate virtual environment RUN python3.11 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" -# 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/ +COPY --chown=user:user . . -# 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 . -# Copy the service file -COPY --chown=user:user serverless/text-to-image/run_text-to-image.py . - -CMD ["python", "run_text-to-image.py"] \ No newline at end of file +CMD ["python", "serverless/text-to-image/run_text-to-image.py"] \ No newline at end of file