/
Dockerfile.devito
92 lines (71 loc) · 2.81 KB
/
Dockerfile.devito
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
##############################################################
# This Dockerfile contains Devito and can be built using different base images.
##############################################################
# Base image with compilers
ARG base=devitocodes/bases:cpu-gcc
FROM $base as builder
# User/Group Ids
ARG USER_ID=1000
ARG GROUP_ID=1000
################## Install devito ############################################
# Copy Devito
ADD . /app/devito
# Update if outdated
RUN apt-get update && apt-get upgrade -y
# Remove git files
RUN rm -rf /app/devito/.git
# Install pip dependencies and devito as a pip package
RUN python3 -m venv /venv && \
/venv/bin/pip install --no-cache-dir --upgrade pip && \
/venv/bin/pip install --no-cache-dir jupyter && \
/venv/bin/pip install --no-cache-dir wheel && \
eval "$MPI4PY_FLAGS /venv/bin/pip install --no-cache-dir -r /app/devito/requirements-mpi.txt" && \
/venv/bin/pip install --no-cache-dir -e /app/devito[extras,tests] && \
rm -rf ~/.cache/pip
# Usefull utilities
# Nvtop
RUN apt-get install -y git cmake libncurses5-dev libncursesw5-dev libdrm-dev libsystemd-dev cmake && \
git clone https://github.com/Syllo/nvtop.git /app/nvtop && \
mkdir -p /app/nvtop/build && cd /app/nvtop/build && \
cmake .. -DNVIDIA_SUPPORT=ON -DAMDGPU_SUPPORT=ON -DINTEL_SUPPORT=ON && \
make && \
make install && \
ln -fs /app/nvtop/build/src/nvtop /venv/bin/nvtop
# Safety cleanup
RUN apt-get clean && apt-get autoclean && apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
FROM $base as user
# COPY is much faster than RUN chown by order of magnitude so we have a final step that
# just copies the built image into the user.
# User/Group Ids
ARG USER_ID=1000
ARG GROUP_ID=1000
## Create App user
# Set the home directory to our app user's home.
ENV HOME=/app
ENV APP_HOME=/app
# Create the home directory for the new app user.
# Create an app user so our program doesn't run as root.
# Chown all the files to the app user.
RUN groupadd -g ${GROUP_ID} app && \
useradd -l -u ${USER_ID} -g app app && \
install -d -m 0755 -o app -g app /app && \
chown -R app:app $APP_HOME
COPY --from=builder --chown=app:app /app /app
ADD --chown=app:app docker/run-jupyter.sh /jupyter
ADD --chown=app:app docker/run-tests.sh /tests
ADD --chown=app:app docker/run-print-defaults.sh /print-defaults
ADD --chown=app:app docker/entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /print-defaults /jupyter /tests /docker-entrypoint.sh
# Venv
COPY --from=builder --chown=app:app /venv /venv
# opt
COPY --from=builder --chown=app:app /opt /opt
# Install codecov
WORKDIR /app/devito
RUN curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov && chown app:app codecov
# Change to the app user.
USER app
EXPOSE 8888
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/jupyter"]