-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile.prod
131 lines (108 loc) · 6.37 KB
/
Dockerfile.prod
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
129
130
131
# TODO: this dockerfile is the latest and greatest out of the large quantity found in this folder
# At some point, Dockerfile.application* and Dockerfile.basis should be obsolete and can be deleted. If you read this in
# the future and that is the case, then "Hello Future Person" and also please delete these dockerfiles.
# !!! This Dockerfile needs to be build from the project root and NOT the application folder !!!
########################################################################################################################
# Build Container #
########################################################################################################################
FROM debian:stable-slim AS build
ENV TZ=Europe/Berlin
RUN <<EOF
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
apt-get -qq update && apt-get -qq install -y locales
echo "en_US.UTF-8 UTF-8" | tee -a /etc/locale.gen && locale-gen
EOF
########################################################################################################################
# Create User #
########################################################################################################################
RUN useradd -ms /bin/bash tira
########################################################################################################################
# Copy all neccessary files over #
########################################################################################################################
USER tira
WORKDIR /tira/
COPY --chown=tira:tira ./application ./
COPY --chown=tira:tira ./python-client ../python-client
########################################################################################################################
# Install Python and Dependencies #
########################################################################################################################
USER root
ENV PIP_BREAK_SYSTEM_PACKAGES=1
# For faster build of GRPCIO (TODO: remove when GRPC is not used anymore)
ENV GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS=16
RUN <<EOF
apt-get -qq update
# Tools
apt-get -qq install -y python3 python3-pip git pkg-config
# Dependencies (stuff needed by at least one python package)
# For MariaDB
apt-get -qq install -y default-libmysqlclient-dev
EOF
USER tira
RUN <<EOF
set -e
export PATH="/home/tira/.local/bin:$PATH"
# Install dependencies
pip3 install -q --no-cache-dir --user ../python-client .[test,deploy,postgreqsql]
chmod +x ./src/tira_app/endpoints/aha # FIXME; aha is not copied to the Production Container
EOF
RUN <<EOF
set -e
export PATH="/home/tira/.local/bin:$PATH"
# Run tests
export TIRA_CONFIG="/tira/config/tira-application-config.yml"
export TIRA_DEBUG=true
make setup
cd test
pytest
EOF
########################################################################################################################
# Production Container #
########################################################################################################################
FROM debian:stable-slim
########################################################################################################################
# Create User #
########################################################################################################################
RUN useradd -ms /bin/bash -u 1010 tira
########################################################################################################################
# Copy Data & Install Python and Dependencies #
########################################################################################################################
COPY --from=build --chown=tira:tira /home/tira/.local /home/tira/.local
COPY --from=build --chown=tira:tira /tira/config /tira/config
COPY --from=build /tira/src/tira_app/management/commands/irds_cli.sh /irds_cli.sh
RUN <<EOF
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
apt-get -qq update && apt-get -qq install -y locales python3-setuptools
echo "en_US.UTF-8 UTF-8" | tee -a /etc/locale.gen && locale-gen
# Tools
apt-get -qq install -y python3 python3-dev git
# For MariaDB
apt-get -qq install -y mariadb-client
#
mkdir -p /tira/application/src
chown -R tira:tira /tira
EOF
########################################################################################################################
# Copy Data & Install Python and Dependencies #
########################################################################################################################
COPY --from=build --chown=tira:tira /tira/src/manage.py /home/tira/manage.py
RUN <<EOF
apt-get -qq install sudo podman
useradd -ms /bin/bash tira
# Change tira's password to tira
echo 'tira:tira' | chpasswd
usermod -aG sudo tira
EOF
########################################################################################################################
# Final Configuration Stuff #
########################################################################################################################
USER tira
ENV LC_ALL=en_US.UTF-8
ENV PATH=/home/tira/.local/bin:$PATH
# CONFIGURE THE FOLLOWING ENVIRONMENT VARIABLES IN YOUR DOCKER-COMPOSE FILE
ENV HF_HOME=/home/tira/data/publicly-shared-datasets/huggingface/
ENV TIRA_CONFIG=/tira/config/tira-application-config.yml
ENV TIRA_DEBUG=false
EXPOSE 8080
# TODO: at some point it probably makes sense, not to use /tira/application/src as a working directory anymore
CMD ["uwsgi", "--strict", "--master", "--enable-threads", "--module", "django_admin.wsgi:application", "--chdir", "/tira/application/src", "--processes", "50", "--http-socket", ":8080", "--vacuum", "--max-requests", "5000"]