forked from dyne/bonfire-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.release
executable file
·122 lines (96 loc) · 3.71 KB
/
Dockerfile.release
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
# The version of Elixir to use
# ATTENTION: when changing Elixir version, make sure to update the `ALPINE_VERSION` arg
# as well as the Elixir version in mix.exs and .gitlab-ci.yml and Dockerfile.dev and .tool-versions
ARG ELIXIR_VERSION=1.12
# The version of Alpine to use for the final image
# This should match the version of Alpine that the current elixir & erlang images (in Step 1) use.
# To find this you need to:
# 1. Locate the dockerfile for the elixir image to get the erlang image version
# e.g. https://github.com/erlef/docker-elixir/blob/master/1.12/Dockerfile
# 2. Locate the corresponding dockerfile for the erlang versio used and copy the alpine version indicated there below:
# e.g. https://github.com/erlang/docker-erlang-otp/blob/master/24/alpine/Dockerfile
ARG ALPINE_VERSION=3.14
# The following are build arguments used to change variable parts of the image, they should be set as env variables.
# The name of your application/release (required)
ARG APP_NAME
# The version of the application we are building (required)
ARG APP_VSN
ARG FLAVOUR
ARG FLAVOUR_PATH
#### STEP 1 - Build our app
FROM elixir:${ELIXIR_VERSION}-alpine as builder
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod APP_NAME=$APP_NAME FLAVOUR=$FLAVOUR FLAVOUR_PATH=./
WORKDIR $HOME
# necessary utils
RUN apk add --no-cache curl git rust cargo npm bash
# dependencies for comeonin
RUN apk add --no-cache make gcc libc-dev
# Cache elixir deps
COPY mix.exs mess.exs mix.lock ./
COPY data/current_flavour/config ./config
RUN mix do local.hex --force, local.rebar --force
RUN mix do deps.get --only prod
# Compile elixir deps (warning this makes the assumption that no Bonfire extensions are coming from Hex. otherwise this should be done only after copying config)
# RUN MIX_ENV=prod mix do deps.compile
RUN mix do deps.get --only prod
# Comment the line above and uncomment the ones below only if you want to include locally-forked deps in the release
# RUN ls -la ./config
# RUN MIX_ENV=prod mix do deps.compile
# Update Bonfire extensions to latest git version
# RUN mix do bonfire.deps.update
# Uncomment these lines only if you want to include locally-forked deps in the release
# COPY data/current_flavour/config/deps.path ./config
# COPY forks/ ./
# RUN mix do deps.get --only prod
# JS package manager
RUN npm install -g pnpm
# install JS deps
COPY assets/package.json assets/pnpm-lock.yaml assets/*.sh ./assets/
COPY priv/*.sh ./priv/
RUN chmod +x assets/*.sh && sh assets/install.sh
RUN chmod +x config/*.sh && chmod +x priv/*.sh && sh config/deps.js.sh
# Compile Bonfire extensions
RUN MIX_ENV=prod mix do deps.compile
# migrations
COPY data/current_flavour/repo priv/repo
# bonfire-app code & assets
COPY lib lib
COPY assets assets
# COPY . .
# In case some dep lockfile has a different version
RUN mix do deps.get --only prod
# prepare static assets
COPY data/current_flavour/config/hooks.js data/current_flavour/config/hooks.js
RUN mix assets.release
RUN MIX_ENV=prod CI=1 mix phx.digest
# build final OTP release
RUN MIX_ENV=prod CI=1 mix release
##### STEP 2 - Prepare the server image
# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}
# The name of your application/release (required)
ARG APP_NAME
ARG APP_VSN
ARG APP_BUILD
ARG PROXY_FRONTEND_URL
ENV APP_NAME=${APP_NAME} APP_VSN=${APP_VSN} APP_REVISION=${APP_VSN}-${APP_BUILD}
# Essentials
RUN apk add --update --no-cache \
mailcap \
ca-certificates \
openssh-client \
openssl-dev \
# ^ for HTTPS
git \
build-base \
# ^ required by tree_magic
tzdata \
gettext \
# ^ localisation
bash \
curl
WORKDIR /opt/app
# install app
COPY --from=builder /opt/app/_build/prod/rel/bonfire /opt/app
# start
CMD ["./bin/bonfire", "start"]