1
+ FROM nvcr.io/nvidia/pytorch:21.07-py3 AS foundation
2
+
3
+ ARG EXTRA_PYTHON_PACKAGES
4
+
5
+ RUN apt-get -y update && \
6
+ apt-get -y install python3-distutils python3-pip python3-venv && \
7
+ python3 -m pip install --no-cache-dir --upgrade pip && \
8
+ python3 -m pip install --no-cache-dir --ignore-installed setuptools
9
+
10
+ # Create a Virtual Environment to limit the size of the application container
11
+ RUN python3 -m venv /opt/venv
12
+ ENV PATH="/opt/venv/bin:$PATH"
13
+ RUN python3 -m pip install --upgrade pip
14
+
15
+ # Copy the ai_service wheel, this is separate from requirements.txt to help with layer caching for repeated builds
16
+ COPY lib/ai_service-*-py3-none-any.whl /tmp/
17
+ RUN python3 -m pip install --no-cache-dir /tmp/ai_service-*-py3-none-any.whl
18
+
19
+ COPY requirements.txt /tmp/
20
+ # Add any other python packages your AI Service requires
21
+ RUN python3 -m pip install --no-cache-dir ${EXTRA_PYTHON_PACKAGES} -r /tmp/requirements.txt
22
+
1
23
FROM nvcr.io/nvidia/pytorch:21.07-py3 AS application
2
24
3
25
ARG PARTNER_NAME
4
26
ARG SERVICE_NAME
5
27
ARG VERSION
6
28
ARG MONAI_APP_MODULE
7
29
ARG MODEL_PATH
8
- ARG EXTRA_PYTHON_PACKAGES
9
30
10
31
ENV TZ=Etc/UTC
11
32
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
12
33
13
34
# python3-gdcm or python-gdcm is required for decompression
14
35
RUN apt-get -y update && \
15
- apt-get -y install --no-install-recommends python3-distutils python3-gdcm && \
16
- # apt-get -y install python3.7 && \
36
+ apt-get -y install --no-install-recommends python3-gdcm && \
17
37
apt-get autoclean && \
18
38
apt-get clean && \
19
39
rm -rf /var/lib/apt/lists/*
20
40
21
- ENV DEBUG=YES
22
- ENV KEEP_FILES=YES
23
-
24
- # make sure all messages reach the console
25
- ENV PYTHONUNBUFFERED=1
26
-
27
- # copy MONAI app files
28
- COPY . /app/.
29
- WORKDIR /app
30
-
31
41
# copy model file to model folder
32
42
RUN wget -q https://github.com/Project-MONAI/model-zoo/releases/download/hosting_storage_v1/lung_nodule_ct_detection_v0.2.0.zip && \
33
43
unzip lung_nodule_ct_detection_v0.2.0.zip -d /tmp/ && \
34
- cp /tmp/lung_nodule_ct_detection/models/model.ts model/. && \
44
+ mkdir -p /app/model && \
45
+ cp /tmp/lung_nodule_ct_detection/models/model.ts /app/model/ && \
35
46
rm -rf /tmp/lung_nodule_ct_detection && \
36
47
rm lung_nodule_ct_detection_v0.2.0.zip
37
48
38
49
# non-root aiserviceuser in group aiserviceuser with UserID and GroupID as 20225
39
- RUN groupadd -g 20225 -r aiserviceuser && useradd -u 20225 -r -g aiserviceuser aiserviceuser && chown -R aiserviceuser:aiserviceuser /app && \
40
- chown -R aiserviceuser:aiserviceuser /var
50
+ RUN groupadd -g 20225 -r aiserviceuser && \
51
+ useradd -u 20225 -r -g aiserviceuser aiserviceuser && \
52
+ chown -R aiserviceuser:aiserviceuser /app /var
41
53
USER aiserviceuser:aiserviceuser
42
54
43
- ENV VIRTUAL_ENV=.venv
44
- RUN python3 -m venv $VIRTUAL_ENV
45
- ENV PATH="$VIRTUAL_ENV/bin:$PATH"
55
+ # Enable Matplotlib cache folder
56
+ RUN mkdir -p /app/.config/matplotlib
57
+ ENV MPLCONFIGDIR=/app/.config/matplotlib
58
+
59
+ # Copy the virtual environment from the foundation image
60
+ ENV VIRTUAL_ENV=/app/venv
61
+ COPY --from=foundation --chown=aiserviceuser:aiserviceuser /opt/venv "${VIRTUAL_ENV}"
62
+ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
63
+
64
+ # make sure all messages reach the console
65
+ ENV PYTHONUNBUFFERED=1
46
66
47
- RUN python -m pip install --upgrade pip && \
48
- python -m pip install --upgrade --no-cache-dir ${EXTRA_PYTHON_PACKAGES} -r requirements.txt && \
49
- python -m pip install --upgrade --no-cache-dir lib/ai_service-*-py3-none-any.whl && \
50
- pip install --upgrade numpy && \
51
- rm -rf lib && \
52
- rm requirements.txt
67
+ # copy MONAI app files
68
+ COPY --chown=aiserviceuser:aiserviceuser app_wrapper.py /app/
69
+ COPY --chown=aiserviceuser:aiserviceuser app/* /app/app/
70
+ WORKDIR /app
53
71
54
72
ENV AI_PARTNER_NAME ${PARTNER_NAME}
55
73
ENV AI_SVC_NAME ${SERVICE_NAME}
@@ -58,4 +76,8 @@ ENV AI_MODEL_PATH ${MODEL_PATH}
58
76
ENV MONAI_APP_CLASSPATH ${MONAI_APP_MODULE}
59
77
60
78
ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
79
+
80
+ ENV DEBUG=NO
81
+ ENV KEEP_FILES=NO
82
+
61
83
CMD ["python" , "app_wrapper.py" ]
0 commit comments