-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (56 loc) · 2.2 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (56 loc) · 2.2 KB
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
FROM python:3.9-buster as base
# ----------
# 1. Stage
# ----------
FROM base as builder
ENV DUMB_INIT_VERSION=1.2.5
RUN mkdir /install
WORKDIR /install
COPY backend/requirements.txt /requirements.txt
# Install python dependencies
RUN pip install --prefix="/install" -r /requirements.txt
# install NodeJS and npm
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y nodejs
COPY frontend /frontend
WORKDIR /frontend
# Install frontend dependencies
RUN ["npm", "ci"]
# Build an optimized react app
RUN ["npm", "run", "build"]
# download and install dumb-init using binaries (https://github.com/Yelp/dumb-init)
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_x86_64 && \
chmod +x /usr/local/bin/dumb-init
# ----------
# 2. Stage
# - Create user dedicated to run the application (security!)
# - Copy over dependencies
# - Copy over application code
# - Start program and let dumb-init handle PID 1 responsibilities
# ----------
FROM base
ENV USERNAME=pythonuser
ENV APP_HOME=/imdb-analyser-project
# create special user to run the application to prevent running the application as root (security!)
RUN addgroup --system ${USERNAME} && \
# no login shell; username, group
useradd -s /sbin/nologin -g ${USERNAME} ${USERNAME}
# Copy over dumb-init binaries
COPY --from=builder /usr/local/bin/dumb-init /usr/local/bin/dumb-init
# Copy over dependencies
COPY --from=builder /install /usr/local
# Copy source code
COPY /backend/imdb_analyser ${APP_HOME}/backend/imdb_analyser
# Set python path so python can find the defined modules
ENV PYTHONPATH=${APP_HOME}/backend/imdb_analyser
# Copy over built React app
COPY --from=builder /frontend/build ${APP_HOME}/frontend/build
# Create directory for data (.csv) files
RUN mkdir -p ${APP_HOME}/backend/data
# Make created user owner of the applciation directory
RUN chown -R ${USERNAME}:${USERNAME} /${APP_HOME}
# Set working directory
WORKDIR ${APP_HOME}/backend
USER ${USERNAME}
# Start gunicorn webserver and let dumb-init handle PID process responsibilities
CMD ["/usr/local/bin/dumb-init", "gunicorn", "--workers", "1", "-b", "0.0.0.0:5000", "imdb_analyser.app:app"]