1# https://docs.docker.com/engine/reference/builder/#from
2#   "The FROM instruction initializes a new build stage and sets the
3#    Base Image for subsequent instructions."
4FROM erlang:20.3.8.1-alpine as builder
5# https://docs.docker.com/engine/reference/builder/#label
6#   "The LABEL instruction adds metadata to an image."
7LABEL stage=builder
8
9# Install git for fetching non-hex depenencies. Also allows rebar3
10# to find it's own git version.
11# Add any other Alpine libraries needed to compile the project here.
12# See https://wiki.alpinelinux.org/wiki/Local_APK_cache for details
13# on the local cache and need for the symlink
14RUN ln -s /var/cache/apk /etc/apk/cache && \
15    apk update && \
16    apk add --update openssh-client git
17
18# WORKDIR is located in the image
19#   https://docs.docker.com/engine/reference/builder/#workdir
20WORKDIR /root/rebar3
21
22# copy the entire src over and build
23COPY . .
24RUN ./bootstrap
25
26# this is the final runner layer, notice how it diverges from the original erlang
27# alpine layer, this means this layer won't have any of the other stuff that was
28# generated previously (deps, build, etc)
29FROM erlang:20.3.8.1-alpine as runner
30
31# copy the generated `rebar3` binary over here
32COPY --from=builder /root/rebar3/_build/prod/bin/rebar3 .
33
34# and install it
35RUN HOME=/opt ./rebar3 local install \
36    && rm -f /usr/local/bin/rebar3 \
37    && ln /opt/.cache/rebar3/bin/rebar3 /usr/local/bin/rebar3 \
38    && rm -rf rebar3
39
40# simply print out the version for visibility
41ENTRYPOINT ["/usr/local/bin/rebar3"]
42CMD ["--version"]
43
44