generated from ersilia-os/eos-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
56 lines (47 loc) · 1.97 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
FROM ersiliaos/base-v2:latest as build
ARG MODEL=eos633t
ENV MODEL=$MODEL
RUN ersilia -v fetch $MODEL --from_github
# Install conda pack so we can create a standalone environment from
# the model's conda environment
RUN conda install -c conda-forge -y conda-pack
RUN conda-pack -n $MODEL -o /tmp/env.tar && \
mkdir /$MODEL && cd /$MODEL && tar xf /tmp/env.tar && \
rm /tmp/env.tar
RUN /$MODEL/bin/conda-unpack
# Now we can create a new image that only contains
# the ersilia environment, the model environment,
# and the model itself (as a bentoml bundle)
FROM python:3.7-slim-buster
WORKDIR /root
ARG MODEL=eos633t
ENV MODEL=$MODEL
# The following lines ensure that ersilia environment is directly in the path
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PATH="/venv/bin:$PATH"
# We install nginx here directly instead of the base image
RUN apt-get update && apt-get install nginx -y
# Copy the model env and ersilia env from the build image
COPY --from=build /$MODEL /$MODEL
COPY --from=build /venv /venv
# Retain the bundled model bento from the build stage
COPY --from=build /root/eos /root/eos
# Copy bentoml artifacts so it doesn't complain about model bento not being found
COPY --from=build /root/bentoml /root/bentoml
COPY --from=build /root/docker-entrypoint.sh docker-entrypoint.sh
COPY --from=build /root/nginx.conf /etc/nginx/sites-available/default
# Writing this script here because the Dockerfile gets copied to the model directory
# and the model directory is not known until the build stage. Either we copy this script
# within the build context or we write it here.
RUN echo -e "#!/bin/bash\nset -eux\n\
cd ~/bentoml/repository/$MODEL/*/$MODEL/artifacts/\n\
if [ -f framework/run.sh ]; then\n\
sed -i -n 's/\/usr\/bin\/conda\/envs//p' framework/run.sh\n\
fi" > patch_python_path.sh && \
chmod +x patch_python_path.sh && \
./patch_python_path.sh
RUN chmod + docker-entrypoint.sh
EXPOSE 80
ENTRYPOINT [ "sh", "docker-entrypoint.sh"]