-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
55 lines (45 loc) · 1.48 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
FROM python:3.10-slim-bullseye
ARG APP_ENV
ENV APP_ENV=${APP_ENV} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.3.2 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
PATH="$PATH:/root/.local/bin"
# System dependencies
RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
bash \
# For poetry
curl \
# For psycopg2
libpq-dev \
# Define build-time-only dependencies
$BUILD_ONLY_PACKAGES \
&& curl -sSL https://install.python-poetry.org | python3 - \
&& poetry --version \
# Remove build-time-only dependencies
&& apt-get remove -y $BUILD_ONLY_PACKAGES \
# Clean cache
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Set up permissions
RUN groupadd -r web && useradd -d /app -r -g web web \
&& chown -R web:web /app
# Copy only requirements to cache them in docker layer
COPY --chown=web:web ./poetry.lock ./pyproject.toml /app/
# Project initialization
RUN poetry install --without dev --no-root --no-interaction --no-ansi \
# Clean poetry installation's cache
&& rm -rf "$POETRY_CACHE_DIR"
COPY --chown=web:web . /app
# Run as non-root user
USER web
ENTRYPOINT ["poetry", "run", "python", "./thisishappening/app.py"]