-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
64 lines (49 loc) · 2.11 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
# Dockerfile
# * builder steps:
# - create environment and build package
# - save environment for runner
# * runner steps:
# - recreate the same environment and install built package
# - optionally execute provided console_script in ENTRYPOINT
#
# Alternatively, remove builder steps, take `environment.docker.yml` from your repo
# and `pip install xtal2png` using an artifact store. Faster and more robust.
FROM condaforge/mambaforge AS builder
WORKDIR /root
COPY . /root
RUN rm -rf dist build
RUN mamba env create -f environment.yml
# RUN pip install -e . # not needed since it's in environment.yml
SHELL ["mamba", "run", "-n", "xtal2png", "/bin/bash", "-c"]
# Build package
RUN tox -e build
RUN mamba env export -n xtal2png -f environment.docker.yml
FROM condaforge/mambaforge AS runner
# Create default pip.conf.
# Replace value of `index-url` with your artifact store if needed.
RUN echo "[global]\n" \
"timeout = 60\n" \
"index-url = https://pypi.org/simple/\n" > /etc/pip.conf
# Create and become user with lower privileges than root
RUN useradd -u 1001 -m app && usermod -aG app app
USER app
WORKDIR /home/app
# WORKAROUND: Assure ownership for older versions of docker
RUN mkdir /home/app/.cache
RUN mkdir /home/app/.conda
# Copy caches, environment.docker.yml and built package
COPY --from=builder --chown=app:app /root/.cache/pip /home/app/.cache/pip
COPY --from=builder --chown=app:app /opt/conda/pkgs /home/app/.conda/pkgs
COPY --from=builder --chown=app:app /root/environment.docker.yml environment.yml
COPY --from=builder --chown=app:app /root/dist/*.whl .
RUN mamba env create -f environment.yml
RUN mamba clean --packages --yes
RUN rm -rf /home/app/.cache/pip
# Make RUN commands use the conda environment
SHELL ["conda", "run", "-n", "xtal2png", "/bin/bash", "-c"]
RUN pip install ./*.whl
# Expose a port for a web-service for instance.
# EXPOSE 80/tcp
# Code to run when container is started. Replace `YOUR_CONSOLE_SCRIPT` with the
# value of `console_scripts` in section `[options.entry_points]` of `setup.cfg`.
# ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "xtal2png", "YOUR_CONSOLE_SCRIPT"]