Skip to content

Commit

Permalink
optimize Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
nett00n committed Oct 28, 2024
1 parent f3b6c05 commit 7a01531
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# Use a Python base image
FROM python:3.11-buster
# Use a smaller base image
FROM python:3.11-slim

# Set the Poetry version as a build argument and install it
# Set Poetry version
ARG POETRY_VERSION=1.8.2
RUN pip install poetry==${POETRY_VERSION}

# Copy dependency files and install packages
COPY ./pyproject.toml ./poetry.lock /app/
# Install dependencies for Poetry and Python builds
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl build-essential \
&& pip install poetry==${POETRY_VERSION} \
&& apt-get remove -y build-essential \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app
RUN poetry install --no-root --no-interaction --no-ansi

# Copy application code after dependencies are installed
# Copy only dependency files first to leverage Docker cache for dependencies
COPY ./pyproject.toml ./poetry.lock /app/

# Install dependencies, skipping development dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --only main --no-interaction --no-ansi \
&& rm -rf /root/.cache/pypoetry

# Copy the application code after installing dependencies to avoid rebuilding layers
COPY ./app /app/app
COPY entrypoint.sh /

# Set volume for cache
# Set cache volume
VOLUME [ "/tmp/url-fairy-bot-cache/" ]

# Set environment variables for PYTHONPATH
# Make entrypoint executable
RUN chmod +x /entrypoint.sh

# Set environment variables for Python path
ENV PYTHONPATH="/app"

# Set the command to run the app as a module
Expand Down

0 comments on commit 7a01531

Please sign in to comment.