Skip to content

Commit

Permalink
Merge pull request #227 from MickaelFontes/update-dockerfile
Browse files Browse the repository at this point in the history
build: update Dockerfile
  • Loading branch information
MickaelFontes authored Jan 26, 2025
2 parents d538022 + 095f51a commit 43e0bbc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
80 changes: 47 additions & 33 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
# The builder image, used to build the virtual environment
FROM python:3.10 as builder

RUN pip install poetry

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app

COPY pyproject.toml poetry.lock ./
RUN touch README.md

RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR

# The runtime image, used to just run the code provided its virtual environment
FROM python:3.10 as runtime

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH" \
HOST=0.0.0.0 \
DASH_DEBUG_MODE=True
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY assets/ ./assets
COPY data/ ./data
COPY app.py ./
COPY pages/ ./pages

EXPOSE 8080
CMD ["gunicorn", "-b", ":8080", "-w", "2", "app:server"]
FROM python:3.10-slim AS builder

# --- Install Poetry ---
ARG POETRY_VERSION=2.0

ENV POETRY_HOME=/opt/poetry
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
ENV POETRY_VIRTUALENVS_CREATE=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Tell Poetry where to place its cache and virtual environment
ENV POETRY_CACHE_DIR=/opt/.cache

RUN pip install "poetry==${POETRY_VERSION}"

WORKDIR /app

# --- Reproduce the environment ---
# You can comment the following two lines if you prefer to manually install
# the dependencies from inside the container.
COPY pyproject.toml poetry.lock /app/

# Install the dependencies and clear the cache afterwards.
# This may save some MBs.
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR

# Now let's build the runtime image from the builder.
# We'll just copy the env and the PATH reference.
FROM python:3.10-slim AS runtime

ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
ENV HOST=0.0.0.0

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

WORKDIR /app

COPY assets/ ./assets
COPY data/ ./data
COPY app.py ./
COPY pages/ ./pages

EXPOSE 8080
HEALTHCHECK CMD python -c "import requests; import sys; sys.exit(0) if requests.get('http://127.0.0.1:8080/').status_code == 200 else sys.exit(1);"
ENTRYPOINT ["gunicorn", "-b", ":8080", "-w", "2", "app:server"]
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Application file for noplp-stats"""
import os

import dash
import dash_bootstrap_components as dbc
Expand All @@ -14,7 +15,8 @@
)
server = app.server
app.title = "NOPLP stats - Statistiques sur N'oubliez pas les paroles"

# To still have debug control, behind gunicorn, using DASH_DEBUG environment variable.
app.enable_dev_tools(debug=bool(os.getenv("DASH_DEBUG", None)))

app.layout = html.Div(
[
Expand Down

0 comments on commit 43e0bbc

Please sign in to comment.