Skip to content

Commit 1251988

Browse files
authored
Merge pull request #27 from EdCaunt/dockerfile
docker: added dockerfile for reproducibility
2 parents 5c178f9 + 071a2d0 commit 1251988

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

docker/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Dockerfile for running Schism
2+
3+
To aid the reproducibility of work carried out with Schism, alongside its wider usage, this directory contains a Dockerfile which can be used to run the code. With this, both tests and examples can be run.
4+
5+
# Building and running the image
6+
7+
To build the image, one must navigate to the main directory (that above this one) and run the following command:
8+
9+
`docker build --network=host --file docker/dockerfile --tag schism .`.
10+
11+
To run a bash shell inside the image, use:
12+
13+
`docker run -i -t schism /bin/bash`.
14+
15+
Note that these commands may require `sudo`. Once inside the image, one will want to activate the `venv` created, using:
16+
17+
`source venv/bin/activate`.
18+
19+
From here, one can run the tests and examples, found in `app/schism`.

docker/dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
##########################################################
2+
# This Dockerfile can be used to run the Schism examples #
3+
##########################################################
4+
5+
# Base image with compilers
6+
ARG base=devitocodes/bases:cpu-gcc
7+
8+
FROM $base as builder
9+
10+
# Copy Schism
11+
ADD . /app/schism
12+
13+
# Install pip dependencies
14+
RUN python3 -m venv /venv && \
15+
/venv/bin/pip install --no-cache-dir --upgrade pip && \
16+
/venv/bin/pip install --no-cache-dir jupyter && \
17+
/venv/bin/pip install --no-cache-dir wheel && \
18+
/venv/bin/pip install -r /app/schism/requirements.txt
19+
20+
# Upgrade python in venv
21+
RUN python3 -m venv --upgrade /venv
22+
23+
# Install Schism as a pip package
24+
WORKDIR /app/schism
25+
RUN /venv/bin/pip install --no-cache-dir -e . && \
26+
rm -rf ~/.cache/pip
27+
28+
WORKDIR /~
29+
# Safety cleanup
30+
RUN apt-get clean && apt-get autoclean && apt-get autoremove && \
31+
rm -rf /var/lib/apt/lists/*
32+
33+
FROM $base as user
34+
35+
# Create app user
36+
# Set the home directory as out app user's home
37+
ENV HOME=/app
38+
ENV APP_HOME=/app
39+
40+
RUN mkdir -p /app && groupadd -r app && \
41+
useradd -r -g app -d /app -s /sbin/nologin -c "Docker image user" app && \
42+
chown -R app:app $APP_HOME
43+
44+
COPY --from=builder --chown=app:app /app /app
45+
46+
# Venv
47+
COPY --from=builder --chown=app:app /venv /venv
48+
49+
# Change to the app user
50+
USER app
51+
52+
EXPOSE 8888

0 commit comments

Comments
 (0)