This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/Dockerfile

73 lines
2.2 KiB
Docker
Raw Normal View History

2022-12-19 22:12:47 +01:00
##############################################
# write git info
##############################################
FROM alpine/git:v2.36.3 AS git
2020-11-11 09:38:37 +01:00
WORKDIR /app
2022-12-19 22:12:47 +01:00
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
2021-01-05 02:36:20 +01:00
2020-12-26 16:49:47 +01:00
2020-11-11 09:38:37 +01:00
2022-12-19 22:12:47 +01:00
##############################################
# Main image
##############################################
FROM python:3.11.3-slim-bullseye AS final
2020-11-11 09:38:37 +01:00
2022-12-19 22:12:47 +01:00
ARG DEBIAN_FRONTEND=noninteractive
2020-09-09 18:32:46 +02:00
2022-12-19 22:12:47 +01:00
# Setup user & group
##############################################
RUN groupadd -g 1000 django
RUN useradd -M -d /app -u 1000 -g 1000 -s /bin/bash django
2020-08-17 08:23:00 +02:00
2022-12-19 22:12:47 +01:00
# Setup system
##############################################
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libxml2 \
media-types
2020-11-11 09:38:37 +01:00
2022-12-19 22:12:47 +01:00
# Fetch project requirements
##############################################
COPY --chown=django:django --from=git /git-describe /git-commit /build-date /app/git/
2020-08-17 12:51:21 +02:00
2022-12-19 22:12:47 +01:00
# Create directory structure
##############################################
2020-08-17 08:23:00 +02:00
WORKDIR /app
2022-12-19 22:12:47 +01:00
COPY --chown=django:django pyproject.toml requirements.txt ./
ADD --chown=django:django ./src ./src
COPY --chown=django:django tasks.py ./tasks.py
2020-08-17 08:23:00 +02:00
2022-12-19 22:12:47 +01:00
RUN mkdir -p /app/data /app/db
RUN chown django:django /app /app/data /app/db
ENV STATIC_ROOT=/app/static
2020-08-17 08:23:00 +02:00
ENV SECRET_KEY "changeme"
ENV DEBUG "false"
2022-12-19 22:12:47 +01:00
ENV DATABASE_URL "sqlite:////app/db/db.sqlite3"
#ENV HOSTS="host1;host2"
#ENV ADMINS='Full Name,email@example.com'
#ENV MAILGUN_API_KEY='key-yourapikey'
#ENV MAILGUN_SENDER_DOMAIN='mailgun.example.com'
#ENV BLOG_BASE_URL='https://url-of-your-blog.example.com'
#ENV SHORTPIXEL_API_KEY='YOURAPIKEY'
#ENV SHORTPIXEL_RESIZE_WIDTH='750'
#ENV SHORTPIXEL_RESIZE_HEIGHT='10000'
#ENV GOATCOUNTER_DOMAIN='blog.goatcounter.example.com'
2020-08-17 08:23:00 +02:00
2022-12-19 22:12:47 +01:00
RUN python -m pip install --no-cache-dir -r requirements.txt
WORKDIR /app/src
RUN python manage.py collectstatic --noinput --clear
EXPOSE 8000
2020-08-17 08:23:00 +02:00
2021-12-19 21:52:20 +01:00
WORKDIR /app/src
2022-12-19 22:12:47 +01:00
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
USER django
CMD ["gunicorn", "blog.wsgi", "--graceful-timeout=5", "--worker-tmp-dir=/dev/shm", "--workers=2", "--threads=4", "--worker-class=gthread", "--bind=0.0.0.0:8000", "--log-file=-"]