mirror of
https://github.com/Crocmagnon/checkout.git
synced 2024-11-21 23:58:02 +01:00
Update dockerfile
This commit is contained in:
parent
114ae437bc
commit
42b74c4951
2 changed files with 50 additions and 47 deletions
94
Dockerfile
94
Dockerfile
|
@ -1,61 +1,63 @@
|
||||||
## Build venv
|
##############################################
|
||||||
FROM python:3.10.4-bullseye AS venv
|
# write git info
|
||||||
|
##############################################
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
FROM alpine/git:v2.36.3 AS git
|
||||||
gettext
|
|
||||||
|
|
||||||
# https://python-poetry.org/docs/#installation
|
|
||||||
ENV POETRY_VERSION=1.1.13
|
|
||||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
|
||||||
|
|
||||||
ENV PATH /root/.local/bin:$PATH
|
|
||||||
ARG POETRY_OPTIONS
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY .git /app/.git/
|
||||||
|
RUN git describe --tags --always > /git-describe
|
||||||
|
RUN git rev-parse HEAD > /git-commit
|
||||||
|
RUN date +'%Y-%m-%d %H:%M %Z' > /build-date
|
||||||
|
|
||||||
COPY pyproject.toml poetry.lock ./
|
|
||||||
|
|
||||||
RUN python -m venv --copies /app/venv \
|
|
||||||
&& . /app/venv/bin/activate \
|
|
||||||
&& poetry install $POETRY_OPTIONS
|
|
||||||
|
|
||||||
ENV PATH /app/venv/bin:$PATH
|
##############################################
|
||||||
COPY src ./src/
|
# Main image
|
||||||
RUN python ./src/manage.py collectstatic --no-input
|
##############################################
|
||||||
RUN python ./src/manage.py compilemessages -l fr -l en
|
FROM python:3.11.2-slim-bullseye AS final
|
||||||
|
|
||||||
## Get git versions
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
FROM alpine/git AS git
|
|
||||||
ADD . /app
|
# Setup user & group
|
||||||
|
##############################################
|
||||||
|
RUN groupadd -g 1000 django
|
||||||
|
RUN useradd -M -d /app -u 1000 -g 1000 -s /bin/bash django
|
||||||
|
|
||||||
|
# Setup system
|
||||||
|
##############################################
|
||||||
|
RUN apt-get update -y \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
libxml2 \
|
||||||
|
media-types
|
||||||
|
|
||||||
|
# Fetch project requirements
|
||||||
|
##############################################
|
||||||
|
COPY --chown=django:django --from=git /git-describe /git-commit /build-date /app/git/
|
||||||
|
|
||||||
|
# Create directory structure
|
||||||
|
##############################################
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN git rev-parse HEAD | tee /version
|
COPY --chown=django:django pyproject.toml requirements.txt ./
|
||||||
|
ADD --chown=django:django ./src ./src
|
||||||
|
COPY --chown=django:django tasks.py ./tasks.py
|
||||||
|
|
||||||
|
RUN mkdir -p /app/data /app/db
|
||||||
|
RUN chown django:django /app /app/data /app/db
|
||||||
|
|
||||||
## Beginning of runtime image
|
ENV STATIC_ROOT=/app/static
|
||||||
FROM python:3.10.4-slim-bullseye as prod
|
|
||||||
ENV TZ "Europe/Paris"
|
|
||||||
RUN mkdir -p /app/db
|
|
||||||
|
|
||||||
COPY --from=venv /app/venv /app/venv/
|
|
||||||
ENV PATH /app/venv/bin:$PATH
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
COPY LICENSE pyproject.toml ./
|
|
||||||
COPY docker ./docker/
|
|
||||||
COPY src ./src/
|
|
||||||
COPY --from=git /version /app/.version
|
|
||||||
COPY --from=venv /app/staticfiles /app/staticfiles/
|
|
||||||
|
|
||||||
ENV SECRET_KEY "changeme"
|
ENV SECRET_KEY "changeme"
|
||||||
ENV DEBUG "false"
|
ENV DEBUG "false"
|
||||||
ENV DB_BASE_DIR "/app/db"
|
ENV DB_BASE_DIR "/app/db"
|
||||||
#ENV HOSTS="host1;host2"
|
|
||||||
#ENV ADMINS='Full Name,email@example.com'
|
RUN python -m pip install --no-cache-dir -r requirements.txt
|
||||||
#ENV MAILGUN_API_KEY='key-yourapikey'
|
WORKDIR /app/src
|
||||||
#ENV MAILGUN_SENDER_DOMAIN='mailgun.example.com'
|
RUN python manage.py collectstatic --noinput --clear
|
||||||
#ENV BLOG_BASE_URL='https://url-of-your-blog.example.com'
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
WORKDIR /app/src
|
||||||
|
|
||||||
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
|
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
|
||||||
|
|
||||||
WORKDIR /app/src
|
USER django
|
||||||
CMD ["/app/docker/run.sh"]
|
CMD ["gunicorn", "checkout.wsgi", "--graceful-timeout=5", "--worker-tmp-dir=/dev/shm", "--workers=2", "--threads=4", "--worker-class=gthread", "--bind=0.0.0.0:8000", "--log-file=-"]
|
||||||
|
|
|
@ -29,6 +29,7 @@ env = environ.Env(
|
||||||
DB_BASE_DIR=(Path, BASE_DIR),
|
DB_BASE_DIR=(Path, BASE_DIR),
|
||||||
TIME_ZONE=(str, "Europe/Paris"),
|
TIME_ZONE=(str, "Europe/Paris"),
|
||||||
LANGUAGE_CODE=(str, "fr-fr"),
|
LANGUAGE_CODE=(str, "fr-fr"),
|
||||||
|
STATIC_ROOT=(Path, BASE_DIR.parent / "staticfiles"),
|
||||||
)
|
)
|
||||||
|
|
||||||
env_file = os.getenv("ENV_FILE", None)
|
env_file = os.getenv("ENV_FILE", None)
|
||||||
|
@ -193,7 +194,7 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
STATIC_ROOT = BASE_DIR.parent / "staticfiles"
|
STATIC_ROOT = env("STATIC_ROOT")
|
||||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||||
|
|
||||||
MEDIA_URL = "media/"
|
MEDIA_URL = "media/"
|
||||||
|
|
Loading…
Reference in a new issue