-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile.gnu-linux
87 lines (65 loc) · 2.58 KB
/
Dockerfile.gnu-linux
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
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.14.2-erlang-25.0.2-debian-bullseye-20210902-slim
#
ARG ELIXIR_VERSION=1.14.2
ARG OTP_VERSION=25.0.2
ARG DEBIAN_VERSION=bullseye-20210902-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
ARG RUSTLER_NIF_VERSION
FROM ${BUILDER_IMAGE} as builder
# install build dependencies
RUN apt-get update -y && apt-get install -y cmake build-essential git curl wget \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# install Rust non-interactively, and put it in the $PATH so the netcdf Elixir dep can find it
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.66.1
ENV PATH="/root/.cargo/bin:$PATH"
ENV CONDA_PREFIX=/opt/conda
ENV PATH=${CONDA_PREFIX}/bin:$PATH
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-$(arch).sh -O ~/miniconda.sh && /bin/bash ~/miniconda.sh -b -p ${CONDA_PREFIX}
RUN conda install -y -c conda-forge libnetcdf=4.8.1 hdf5=1.12.1
ENV HDF5_DIR=${CONDA_PREFIX}
ENV NETCDF_DIR=${CONDA_PREFIX}
ENV RUSTFLAGS="-C link-args=-Wl,-rpath,$CONDA_PREFIX/lib"
ENV NETCDF_BUILD=true
ENV MIX_ENV=prod
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# install mix dependencies
COPY mix.exs mix.lock VERSION ./
RUN mix deps.get --only prod
RUN mkdir config
# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
# COPY config/config.exs config/prod.exs config/
RUN mix deps.compile
COPY lib lib
COPY native native
# Compile the release
RUN mix compile
# Changes to config/runtime.exs don't require recompiling the code
# COPY config/runtime.exs config/
ENV RUSTLER_NIF_VERSION=${RUSTLER_NIF_VERSION}
RUN mix release
FROM ${RUNNER_IMAGE}
WORKDIR "/app"
COPY --from=builder --chown=nobody:nogroup /app/_build/prod/rel/netcdf ./
RUN mkdir /mnt/release
RUN chown nobody:nogroup /mnt/release
RUN chown nobody:nogroup /app
USER nobody
CMD ["/bin/bash"]