-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
114 lines (88 loc) · 3.68 KB
/
Copy pathDockerfile
File metadata and controls
114 lines (88 loc) · 3.68 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# syntax = docker/dockerfile:experimental
#--- Builder -------------------------------------------------------------------
ARG profile=container
ARG erlang_version=27
FROM erlang:$erlang_version-alpine as builder
WORKDIR /app/src
ENV REBAR_BASE_DIR /app/_build
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories
# Install git for fetching non-hex depenencies.
# Add any other Alpine libraries needed to compile the project here.
# See https://wiki.alpinelinux.org/wiki/Local_APK_cache for details
# on the local cache and need for the symlink
RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \
ln -s /var/cache/apk /etc/apk/cache && \
apk add --update \
openssl \
git \
# Needed for NIFs:
make \
gcc \
g++ \
libc-dev \
libbsd-dev
# build and cache dependencies as their own layer
COPY rebar.config rebar.lock ./
# RUN apk add --no-cache openssh-client git && \
# mkdir -p -m 0600 ~/.ssh && \
# ssh-keyscan github.com >> ~/.ssh/known_hosts && \
# git config --global url."git@github.com:".insteadOf "https://github.com/"
RUN --mount=id=hex-cache,type=cache,sharing=locked,target=/root/.cache/rebar3 \
rebar3 compile
#--- Profile Builder -----------------------------------------------------------
FROM builder as builder-profile
ARG profile
RUN --mount=target=. \
--mount=id=hex-cache,type=cache,sharing=locked,target=/root/.cache/rebar3 \
rebar3 as $profile compile
#--- Releaser ------------------------------------------------------------------
FROM builder-profile as releaser
# create the directory to unpack the release to
RUN mkdir -p /opt/rel
# tar for unpacking the target system
RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \
apk add --update tar
ARG profile
RUN --mount=target=. \
--mount=id=hex-cache,type=cache,sharing=locked,target=/root/.cache/rebar3 \
rebar3 as $profile tar && \
tar -zxvf $REBAR_BASE_DIR/$profile/rel/*/*.tar.gz -C /opt/rel
#--- Runner --------------------------------------------------------------------
FROM docker:29.0-dind as runner
WORKDIR /opt/braidnet/
# write files generated during startup to /tmp
ENV RELX_OUT_FILE_PATH=/tmp \
# braidnet specific env variables to act as defaults
LOGGER_LEVEL=debug \
SCHEDULERS=1 \
# Configure Docker-in-Docker to use vfs storage driver instead of overlay2
# overlay2 is not supported in Fly.io's filesystem environment
DOCKER_STORAGE_DRIVER=vfs
# Configure Docker daemon to use vfs storage driver instead of overlay2
# overlay2 is not supported in Fly.io's filesystem environment
RUN mkdir -p /etc/docker && \
echo '{"storage-driver": "vfs"}' > /etc/docker/daemon.json
# openssl needed by the crypto app
RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \
ln -s /var/cache/apk /etc/apk/cache && \
apk add --update \
libstdc++ \
zip \
openssl \
ncurses \
curl
COPY --from=releaser /opt/rel .
# Alias remote shell script under a single command
RUN touch ~/.profile && \
printf "%s\n" 'alias remshell='\''/opt/braidnet/erts-*/bin/erl -boot $(find /opt/braidnet/releases -type f -name start_clean.boot | sed "s/\.boot$//") -setcookie cookie -proto_dist inet6_tls -ssl_dist_optfile lib/braidnet-*/priv/prod.ssl_dist_opts.rel -sname console -remsh braidnet@$(hostname)'\''' \
>> ~/.profile
# Note:
# Exposing these ports do not affects the Fly.io deployment,
# this is just for development or convenience,
# in case braidnet is runned as container locally.
EXPOSE 80/tcp
EXPOSE 4369/tcp
EXPOSE 50000/tcp
EXPOSE 50100/tcp
ENTRYPOINT ["/opt/braidnet/bin/braidnet"]
CMD ["foreground"]