-
Notifications
You must be signed in to change notification settings - Fork 42
/
Dockerfile
108 lines (76 loc) · 3.17 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
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
########################################################################
# Versions & Images
########################################################################
# renovate: datasource=github-tags depName=elixir packageName=elixir-lang/elixir versioning=semver
ARG ELIXIR_VERSION=1.17.3
# renovate: datasource=github-tags depName=erlang packageName=erlang/otp versioning=regex:^(?<major>\d+?)\.(?<minor>\d+?)(\.(?<patch>\d+))?$ extractVersion=^OTP-(?<version>\S+)
ARG OTP_VERSION=27.1.2
# renovate: datasource=docker depName=ubuntu packageName=ubuntu versioning=ubuntu
ARG UBUNTU_VERSION=jammy-20240808
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-ubuntu-${UBUNTU_VERSION}"
ARG RUNTIME_IMAGE="ubuntu:${UBUNTU_VERSION}"
########################################################################
# Stage: builder
########################################################################
FROM ${BUILDER_IMAGE} AS builder
ENV MIX_HOME=/opt/mix \
HEX_HOME=/opt/hex \
APP_HOME=/opt/app \
ERL_AFLAGS="-kernel shell_history enabled"
WORKDIR $APP_HOME
RUN apt-get update -y \
&& apt-get install -y build-essential curl git inotify-tools \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs \
&& npm install --global yarn
COPY .docker/opt/scripts/ /opt/scripts
ADD https://github.com/naymspace/env-secrets-expand/raw/main/env-secrets-expand.sh /opt/scripts/
RUN chmod -R +x /opt/scripts/
ENV PATH=/opt/scripts/:/opt/app/_build/prod/rel/demo/bin:$PATH
ARG MIX_ENV=prod
ENV MIX_ENV=$MIX_ENV
RUN mkdir demo
WORKDIR $APP_HOME/demo
COPY lib ../lib/
COPY mix.exs mix.lock .formatter.exs ../
COPY demo/mix.exs demo/mix.lock ./
RUN mix deps.get --only $MIX_ENV
COPY demo/config/config.exs demo/config/${MIX_ENV}.exs config/
RUN mix do deps.compile
COPY demo/priv priv/
COPY demo/package.json demo/yarn.lock demo/.stylelintrc.json ./
RUN yarn install --pure-lockfile
COPY demo/assets assets/
COPY demo/lib lib/
RUN mix assets.deploy
# Copy the rest of the application files
COPY . ../
ENTRYPOINT ["entrypoint.sh"]
CMD ["mix", "phx.server"]
EXPOSE 4000
########################################################################
# Stage: release
########################################################################
FROM builder as release
ENV MIX_ENV=prod
# Compile and create the release
RUN mix do deps.get, deps.compile, assets.deploy, sentry.package_source_code, release --overwrite
########################################################################
# Stage: runtime
########################################################################
FROM ${RUNTIME_IMAGE} AS runtime
ENV APP_HOME=/opt/app
WORKDIR $APP_HOME
RUN apt-get update -y \
&& apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates wget \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
COPY --from=builder /opt/scripts /opt/scripts
RUN chown -R nobody /opt
ENV PATH=/opt/scripts/:/opt/app/bin:$PATH \
MIX_ENV=prod
COPY --from=release --chown=nobody /opt/app/demo/_build/${MIX_ENV}/rel/demo .
USER nobody
ENTRYPOINT ["entrypoint.sh"]
CMD ["bash", "-c", "demo start"]
EXPOSE 4000