-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
81 lines (61 loc) · 1.91 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
# set base image (host OS)
FROM python:3.9.13-slim as base
# install OS dependencies
RUN apt-get update
RUN apt-get -y install sudo rabbitmq-server build-essential libssl-dev
# create user
RUN useradd -r -m -g sudo milo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER milo
# set the working directory in the container
RUN sudo mkdir /milo
RUN sudo chown -R milo /milo
WORKDIR /milo
# update path for Python
ENV PATH="/home/milo/.local/bin:${PATH}"
# create required directories
RUN mkdir data
RUN mkdir ssl
# generate SSL certificate
RUN openssl req -x509 -nodes \
-subj "/CN=localhost" \
-addext "subjectAltName = DNS:localhost" \
-addext "keyUsage = digitalSignature" \
-addext "extendedKeyUsage = serverAuth" \
-newkey rsa:2048 -keyout ssl/milo.key \
-out ssl/milo.crt
# copy the Python dependencies to the working directory
COPY --chown=milo requirements.txt .
# install app dependencies
RUN pip install -r requirements.txt
# copy client assets
COPY --chown=milo client/ client/
# copy remaining Python code
COPY --chown=milo server.py .
COPY --chown=milo worker.py .
COPY --chown=milo ml/ ml/
COPY --chown=milo api/ api/
COPY --chown=milo uwsgi.ini .
COPY --chown=milo preprocessor/modules/ preprocessor/modules/
# copy static assets (UI and documentation)
COPY --chown=milo static/ static/
# copy the public license key
COPY --chown=milo public_key.pem .
# create a worker service image
FROM base as worker
# start the application
CMD celery -A worker worker -c 1
# create an api service image
FROM base as api
# expose ports
EXPOSE 5000
EXPOSE 8443
# env variables
ENV LOCAL_USER true
ENV LDAP_AUTH false
# start the application
CMD uwsgi --ini uwsgi.ini --processes $(grep -c 'cpu[0-9]' /proc/stat)
# create an all-in-one image used for a single instance
FROM api as aio
# start the application
CMD sudo rabbitmq-server & celery -A worker worker -c 1 & uwsgi --ini uwsgi.ini --processes 1