-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.web
98 lines (74 loc) · 2.34 KB
/
Dockerfile.web
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
# syntax=docker/dockerfile:1.6
# full semver just for python base image
ARG PYTHON_VERSION=3.11.9
FROM python:${PYTHON_VERSION}-slim-bullseye AS builder
# avoid stuck build due to user prompt
ARG DEBIAN_FRONTEND=noninteractive
# install dependencies
RUN apt-get -qq update \
&& apt-get -qq install \
--no-install-recommends -y \
curl \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# pip env vars
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
# path
ENV VENV="/opt/venv"
ENV PATH="$VENV/bin:$PATH"
WORKDIR /app
COPY ./app .
COPY ./requirements.txt .
RUN python -m venv $VENV \
&& python -m pip install -r requirements.txt
# ! heroku doesn't use buildkit
# RUN --mount=type=cache,target=/root/.cache/pip \
# --mount=type=bind,source=./requirements.txt,target=/app/requirements.txt \
# python -m pip install -r requirements.txt
FROM python:${PYTHON_VERSION}-slim-bullseye AS runner
# set timezone
ENV TZ=${TZ:-"America/Chicago"}
RUN ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime && echo "$TZ" > /etc/timezone
# setup standard non-root user for use downstream
ENV USER_NAME=appuser
ENV VENV="/opt/venv"
ENV PATH="${VENV}/bin:${VENV}/lib/python${PYTHON_VERSION}/site-packages:/usr/local/bin:${HOME}/.local/bin:/bin:/usr/bin:/usr/share/doc:$PATH"
# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
# workers per core
# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/blob/master/README.md#web_concurrency
ENV WEB_CONCURRENCY=2
# avoid stuck build due to user prompt
ARG DEBIAN_FRONTEND=noninteractive
# install dependencies
RUN apt-get -qq update \
&& apt-get -qq install \
--no-install-recommends -y \
curl \
lsof \
&& rm -rf /var/lib/apt/lists/*
# add non-root user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
${USER_NAME}
USER ${USER_NAME}
WORKDIR /app
COPY --chown=${USER_NAME} ./app .
COPY --from=builder --chown=${USER_NAME} "$VENV" "$VENV"
# expose port
EXPOSE 3000
CMD ["/bin/sh", "startup.sh"]
LABEL org.opencontainers.image.title="meetup_bot"
LABEL org.opencontainers.image.version="latest"