-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
106 lines (82 loc) · 2.24 KB
/
Dockerfile
File metadata and controls
106 lines (82 loc) · 2.24 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
# Remmber to bump .github worflow as well
FROM elixir:1.18.3-alpine AS build
RUN apk update \
&& apk add --virtual build-dependencies \
build-base
RUN apk add bash nodejs npm inotify-tools openssl
WORKDIR /app
RUN mix local.hex --force \
&& mix local.rebar --force
ENV MIX_ENV="prod"
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only prod
# compile dependencies
RUN mix deps.compile
# copy compile configuration files
RUN mkdir config
COPY config/config.exs config/prod.exs config/
# copy assets
COPY priv priv
# Compile assets
# Install here and pass path to dart-sass config in config.exs
RUN npm install -g sass
COPY assets assets
# Build sass here, cos doing it via mix dun werk on fly
RUN cd assets && \
sass --no-source-map --style=compressed css/app.scss ../priv/static/assets/app.css
RUN cd assets && npm install
RUN mix assets.deploy
# compile project
COPY lib lib
RUN mix compile
# copy runtime configuration file
COPY config/runtime.exs config/
COPY rel rel
# assemble release
RUN mix sentry.package_source_code
RUN mix release
FROM alpine:3.18 AS app
RUN apk update \
&& apk add --virtual build-dependencies \
build-base
# Get build arg to be in the env
ARG APP_REVISION
ENV APP_REVISION $APP_REVISION
# install runtime dependencies
RUN apk add --no-cache libstdc++ openssl ncurses-libs bash
ENV USER="elixir"
ENV LANG en_GB.UTF-8
ENV LANGUAGE en_GB:en
ENV LC_ALL en_GB.UTF-8
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
WORKDIR "/home/${USER}/app"
RUN mkdir "/home/${USER}/app/tmp"
# Create unprivileged user to run the release
RUN \
addgroup \
-g 1000 \
-S "${USER}" \
&& adduser \
-s /bin/sh \
-u 1000 \
-G "${USER}" \
-h "/home/${USER}" \
-D "${USER}" \
&& su "${USER}"
RUN chown ${USER}:${USER} "/home/${USER}/app/tmp"
# run as user
USER "${USER}"
# Pretend this is in bash history
# It seems to be called .ash_history on alpine
RUN touch /home/elixir/.bash_history && \
echo "/home/elixir/app/bin/pr remote" > /home/elixir/.ash_history
# copy release executables
COPY --from=build --chown="${USER}":"${USER}"\
/app/_build/prod/rel/pr ./
# Copy scritps to working directory
COPY --chown="${USER}":"${USER}"\
scripts/start.sh ./ \
scripts/clear.sh ./
CMD ["./start.sh"]