Skip to content

Commit

Permalink
chore: Update Dockerfile to use virtual environment for Python depend…
Browse files Browse the repository at this point in the history
…encies and set app path
  • Loading branch information
inean committed Sep 3, 2024
1 parent ca7efb2 commit f2f58ae
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
# Define the build argument with no default value
# Global args
ARG PYTHON_VERSION=3.10
ARG APP_PATH=/app
ARG VIRTUAL_ENV_PATH=.venv

# Builder stage
FROM python:${PYTHON_VERSION}-slim AS builder

# Re-declare the ARG to use it in this stage
ARG APP_PATH
ARG VIRTUAL_ENV_PATH

# hadolint ignore=DL3008
RUN <<EOF
apt-get update
apt-get install --no-install-recommends -y git
EOF

# Set the working directory:
WORKDIR /app
WORKDIR ${APP_PATH}

# Set a Virtual env
RUN python3 -m venv "${APP_PATH}/${VIRTUAL_ENV_PATH}"
ENV PATH="${APP_PATH}/${VIRTUAL_ENV_PATH}/bin:$PATH"

# Copy and install dependencies:
COPY requirements.lock ./
COPY requirements.lock .
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -r requirements.lock

# Copy the application source code:
COPY src .

# Final stage
FROM python:${PYTHON_VERSION}-slim
FROM python:${PYTHON_VERSION}-slim as target

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Define the build argument with a default value
# Redeclare args
ARG APP_PATH
ARG VIRTUAL_ENV_PATH

# Image args
ARG REGISTRY="ghcr.io"
ARG REPOSITORY="inean/dns-synchub"

Expand All @@ -33,10 +47,13 @@ LABEL image="${REGISTRY}/${REPOSITORY}"
LABEL maintainer="Carlos Martín (github.com/inean)"

# Set the working directory:
WORKDIR /app
WORKDIR ${APP_PATH}

# Ensure venv is used
ENV PATH="${APP_PATH}/${VIRTUAL_ENV_PATH}/bin:$PATH"

# Copy dependencies and source code from the builder stage
COPY --from=builder /app /app
COPY --from=builder ${APP_PATH} ${APP_PATH}

# Run the application:
ENTRYPOINT ["python", "-m", "dns_synchub"]
Expand Down

0 comments on commit f2f58ae

Please sign in to comment.