-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
128 lines (105 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.11.9
ARG PYTHON_DISTRIB=slim-bookworm
FROM python:${PYTHON_VERSION}-${PYTHON_DISTRIB} AS base
# Install system packages
RUN set -eux; \
# Uncomment lines below and replace mirrors if needed:
# rm -rf /etc/apt/sources.list; \
# rm -rf /etc/apt/sources.list.d; \
# echo "deb <mirror> <distrib> main" > /etc/apt/sources.list; \
# echo "deb <mirror> <distrib>-updates main contrib" >> /etc/apt/sources.list; \
# echo "deb <mirror> <distrib>-backports main contrib" >> /etc/apt/sources.list; \
# echo "deb <mirror> <distrib>-security main contrib" >> /etc/apt/sources.list; \
DEBIAN_FRONTEND=noninteractive apt-get -y update; \
DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
curl=7.* \
tini=0.19.* \
; \
DEBIAN_FRONTEND=noninteractive apt-get -y clean; rm -rf /var/lib/apt/lists/*
# Create non-root user
ARG \
APP_LOGIN=nonroot \
APP_GROUP=nonroot \
APP_UID=10001 \
APP_GID=10001
ENV \
APP_LOGIN=${APP_LOGIN} \
APP_GROUP=${APP_GROUP} \
APP_UID=${APP_UID} \
APP_GID=${APP_GID}
RUN set -eux; \
groupadd --gid ${APP_GID} ${APP_GROUP} \
; \
useradd \
--no-log-init \
--create-home \
--home /home/${APP_LOGIN} \
--base-dir /home/${APP_LOGIN} \
--uid ${APP_UID} \
--gid ${APP_GID} \
--comment "" \
--shell /bin/bash \
${APP_LOGIN}
# Set timezone
ARG \
TZ=UTC
ENV \
TZ=${TZ}
RUN set -eux; \
cp --remove-destination /usr/share/zoneinfo/${TZ} /etc/localtime ; echo ${TZ} > /etc/timezone
# Set locale
ARG \
LANG=C.UTF-8\
LC_ALL=C.UTF-8
ENV \
LANG=${LANG}\
LC_ALL=${LC_ALL}
# Set terminal
ARG \
TERM=xterm
ENV \
TERM=${TERM}
# Set Python options
ARG \
# Keeps Python from generating .pyc files in the container
PYTHONDONTWRITEBYTECODE=1 \
# Dump the Python traceback
PYTHONFAULTHANDLER=1 \
# Allows you to set a fixed value for the hash seed secret
PYTHONHASHSEED=random \
# Turns off buffering for easier container logging
PYTHONUNBUFFERED=1
ENV \
PYTHONDONTWRITEBYTECODE=${PYTHONDONTWRITEBYTECODE} \
PYTHONFAULTHANDLER=${PYTHONFAULTHANDLER} \
PYTHONHASHSEED=${PYTHONHASHSEED} \
PYTHONUNBUFFERED=${PYTHONUNBUFFERED}
# Set pip options
ARG \
# Network connection timeout
PIP_DEFAULT_TIMEOUT=120 \
# Don't periodically check PyPI to determine whether a new version of pip is available for download
PIP_DISABLE_PIP_VERSION_CHECK=on \
# Disable the cache
PIP_NO_CACHE_DIR=1 \
# Action if pip is run as a root user ('warn' or 'ignore')
PIP_ROOT_USER_ACTION=ignore
ENV \
PIP_DEFAULT_TIMEOUT=${PIP_DEFAULT_TIMEOUT} \
PIP_DISABLE_PIP_VERSION_CHECK=${PIP_DISABLE_PIP_VERSION_CHECK} \
PIP_NO_CACHE_DIR=${PIP_NO_CACHE_DIR} \
PIP_ROOT_USER_ACTION=${PIP_ROOT_USER_ACTION}
# Set entrypoint
ENTRYPOINT ["tini", "--"]
FROM base AS app
# Install requirements as root user
RUN \
--mount=type=bind,source=requirements.txt,target=requirements.txt,readonly \
pip install --no-cache-dir --upgrade -r requirements.txt
# Copy application
WORKDIR /app
RUN chown -R nonroot:nonroot /app
USER nonroot
COPY --chown=nonroot:nonroot ./src ./src
CMD ["python", "-m", "src.main"]