Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
135 lines (95 loc) · 4.08 KB
/
Copy pathDockerfile
File metadata and controls
135 lines (95 loc) · 4.08 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
########################################################################
# Versions & Images
########################################################################
# renovate: datasource=github-tags depName=elixir packageName=elixir-lang/elixir versioning=semver
ARG ELIXIR_VERSION=1.20.4
# renovate: datasource=github-tags depName=erlang packageName=erlang/otp versioning=regex:^(?<major>\d+?)\.(?<minor>\d+?)(\.(?<patch>\d+))?$ extractVersion=^OTP-(?<version>\S+)
ARG OTP_VERSION=29.1.1
# renovate: datasource=docker depName=ubuntu packageName=ubuntu versioning=ubuntu
ARG UBUNTU_VERSION=resolute-20260927
# renovate: datasource=github-tags depName=bun packageName=oven-sh/bun versioning=semver extractVersion=^bun-v(?<version>\S+)
ARG BUN_VERSION=1.4.2
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-ubuntu-${UBUNTU_VERSION}"
ARG RUNTIME_IMAGE="ubuntu:${UBUNTU_VERSION}"
########################################################################
# Stage: base
########################################################################
FROM ${BUILDER_IMAGE} AS base
ARG BUN_VERSION
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 watchman \
&& 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 unzip \
&& apt-get clean && rm -f /var/lib/apt/lists/*_* \
&& curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}" \
&& install /root/.bun/bin/bun /usr/local/bin/bun \
&& rm -rf /root/.bun
COPY .docker/opt/scripts/ /opt/scripts
ADD https://github.com/naymspace/env-secrets-expand/raw/ed67c7928a5be6d24e25c084ac749006ef5347c1/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
# Install root-level (Backpex) dependencies
COPY package.json bun.lock bunfig.toml ./
RUN bun install --frozen-lockfile
RUN mkdir demo
WORKDIR $APP_HOME/demo
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/
# Backpex is compiled together with the demo, so changes to Backpex do not invalidate the compiled deps
RUN mix deps.compile --skip-local-deps
COPY demo/package.json demo/bun.lock demo/bunfig.toml demo/.stylelintrc.json ./
COPY assets ../assets/
COPY package.json ../
RUN bun install --frozen-lockfile
COPY lib ../lib/
COPY demo/priv priv/
COPY demo/assets assets/
COPY demo/lib lib/
RUN mix compile
RUN mix assets.deploy
########################################################################
# Stage: builder
########################################################################
FROM base AS builder
# Copy the rest of the application files
COPY . ../
ENTRYPOINT ["entrypoint.sh"]
CMD ["mix", "phx.server"]
EXPOSE 4000
########################################################################
# Stage: release
########################################################################
FROM base AS release
ENV MIX_ENV=prod
COPY demo/config/runtime.exs config/
COPY demo/rel rel/
# Compile and create the release
RUN mix do deps.get + deps.compile + 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 libncurses6 locales ca-certificates wget \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
COPY --from=base /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