-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from MickaelFontes/update-dockerfile
build: update Dockerfile
- Loading branch information
Showing
2 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters