-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
95 lines (81 loc) · 3.23 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# This Dockerfile uses multi-stage build to customize DEV and PROD images:
# https://docs.docker.com/develop/develop-images/multistage-build/
FROM python:3.8.9-slim-buster AS development_build
ARG DJANGO_ENV
ENV DJANGO_ENV=${DJANGO_ENV} \
# build:
BUILD_ONLY_PACKAGES='wget' \
# python:
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
# pip:
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
# dockerize:
DOCKERIZE_VERSION=v0.6.1 \
# tini:
TINI_VERSION=v0.19.0 \
# poetry:
POETRY_VERSION=1.1.5 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
PATH="$PATH:/root/.poetry/bin"
# System deps:
RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
bash \
build-essential \
curl \
gettext \
git \
libpq-dev \
# Defining build-time-only dependencies:
$BUILD_ONLY_PACKAGES \
# Installing `dockerize` utility:
# https://github.com/jwilder/dockerize
&& wget "https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" \
&& tar -C /usr/local/bin -xzvf "dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" \
&& rm "dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" && dockerize --version \
# Installing `tini` utility:
# https://github.com/krallin/tini
&& wget -O /usr/local/bin/tini "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini" \
&& chmod +x /usr/local/bin/tini && tini --version \
# Installing `poetry` package manager:
# https://github.com/python-poetry/poetry
&& curl -sSL 'https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py' | python \
&& poetry --version \
# Removing build-time-only dependencies:
&& apt-get remove -y $BUILD_ONLY_PACKAGES \
# Cleaning cache:
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /code
# This is a special case. We need to run this script as an entry point:
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
# Setting up proper permissions:
RUN chmod +x '/docker-entrypoint.sh' \
&& groupadd -r web && useradd -d /code -r -g web web \
&& chown web:web -R /code \
&& mkdir -p /var/www/django/static /var/www/django/media \
&& chown web:web /var/www/django/static /var/www/django/media
# Copy only requirements, to cache them in docker layer
COPY --chown=web:web ./poetry.lock ./pyproject.toml /code/
# Project initialization:
RUN echo "$DJANGO_ENV" \
&& poetry install \
$(if [ "$DJANGO_ENV" = 'production' ]; then echo '--no-dev'; fi) \
--no-interaction --no-ansi \
# Cleaning poetry installation's cache for production:
&& if [ "$DJANGO_ENV" = 'production' ]; then rm -rf "$POETRY_CACHE_DIR"; fi
# Running as non-root user:
USER web
# We customize how our app is loaded with the custom entrypoint:
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
# The following stage is only for Prod:
# https://wemake-django-template.readthedocs.io/en/latest/pages/template/production.html
# FROM development_build AS production_build
# COPY --chown=web:web . /code