forked from Giskard-AI/giskard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
176 lines (126 loc) · 4.39 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
FROM ubuntu:latest as build
# >>> BACKEND
RUN apt-get update
RUN apt -y install openjdk-17-jdk
ENV _JAVA_OPTIONS="-Xmx4048m -Xms512m" \
SPRING_PROFILES_ACTIVE=prod \
MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED=true \
SPRING_DATASOURCE_USERNAME=postgres
WORKDIR /app
COPY supervisord.conf /etc/
COPY gradle gradle
COPY gradlew .
COPY gradle.properties .
COPY settings.gradle.kts .
COPY build.gradle.kts .
COPY .git .git
COPY common common
COPY backend backend
WORKDIR /app/backend
ARG RUN_TESTS=false
RUN bash -c " \
echo RUN_TESTS=$RUN_TESTS && \
if [ "$RUN_TESTS" = true ] ; \
then ../gradlew -Pprod clean test bootJar --info --stacktrace; \
else ../gradlew -Pprod clean bootJar --info --stacktrace ; \
fi"
# <<< BACKEND
# >>> FRONTEND
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN apt-get update -y && apt-get install -y libxml2-dev libgcrypt-dev npm
RUN npm install
COPY frontend/ ./
ARG FRONTEND_ENV=production
ENV VUE_APP_ENV=${FRONTEND_ENV}
RUN npm run build
# <<< FRONTEND
# >>> ML-WORKER
FROM python:3.7.13 as python-base
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.2.2 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
ENV PATH="$VENV_PATH/bin:$POETRY_HOME/bin:$PATH"
FROM python-base as builder-base
RUN apt-get update && \
apt-get install --no-install-recommends -y \
git \
curl \
build-essential vim
RUN pip install --upgrade pip && \
pip install -U pip setuptools
RUN curl -sSL https://install.python-poetry.org | python3 -
WORKDIR $PYSETUP_PATH
COPY ./python-client/pyproject.toml ./python-client/poetry.lock ./
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --only main ; fi"
RUN pip install \
torch==1.12.0 \
transformers==4.20.1 \
nlpaug==1.1.11
FROM builder-base as proto-builder
WORKDIR $PYSETUP_PATH
RUN poetry install --only main,dev
COPY ./common/proto ./proto
COPY ./python-client/giskard ./giskard
COPY ./python-client/scripts ./scripts
RUN mkdir -p giskard/ml_worker/generated && \
python -m grpc_tools.protoc \
-Iproto \
--python_out=giskard/ml_worker/generated \
--grpc_python_out=giskard/ml_worker/generated \
--mypy_out=giskard/ml_worker/generated \
--mypy_grpc_out=giskard/ml_worker/generated \
proto/ml-worker.proto && \
python scripts/fix_grpc_generated_imports.py giskard/ml_worker/generated giskard.ml_worker.generated
# <<< ML-WORKER
# >>> FINAL CONFIGURATION
FROM python-base as production
ENV SPRING_PROFILES_ACTIVE=prod
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y \
postgresql \
nginx \
openjdk-17-jre \
supervisor
ENV PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
PGDATA=/var/lib/postgresql/data/pgdata \
SPRING_DATASOURCE_USERNAME=postgres \
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/app \
SPRING_LIQUIBASE_URL=jdbc:postgresql://localhost:5432/app
ENV PATH="$VENV_PATH/bin:$POETRY_HOME/bin:$PATH"
WORKDIR /app
COPY --from=builder-base $VENV_PATH $VENV_PATH
COPY --from=proto-builder $PYSETUP_PATH/giskard $PYSETUP_PATH/giskard
COPY --from=build /app/backend/build/libs/backend*.jar /app/backend/lib/giskard.jar
COPY --from=build /etc/supervisord.conf /app/
COPY --from=build /app/frontend/dist /usr/share/nginx/html
COPY supervisord.conf /app/supervisord.conf
COPY frontend/packaging/nginx_single_dockerfile.conf /etc/nginx/sites-enabled/default.conf
RUN rm /etc/nginx/sites-enabled/default
ENV GSK_HOST=0.0.0.0
ENV PYTHONPATH=$PYSETUP_PATH
RUN mkdir /var/lib/postgresql/data /root/giskard-home
RUN useradd -u 1000 postgres; exit 0
RUN usermod -u 1000 postgres; exit 0
RUN chown -R 1000:1000 /var/run/postgresql && \
chown -R 1000:1000 /var/log/nginx && \
chown -R 1000:1000 /var/lib/nginx && \
chown -R 1000:1000 /etc/nginx && \
chown -R 1000:1000 /root/giskard-home && \
chown -R 1000:1000 /var/lib/postgresql/data && \
chown -R 1000:1000 /run && \
chown -R 1000:1000 $PYSETUP_PATH && \
chown -R 1000:1000 /app
ENTRYPOINT ["supervisord", "-c", "/app/supervisord.conf"]
# <<< FINAL CONFIGURATION