bonfire-app/Dockerfile.release

150 lines
4.8 KiB
Docker
Raw Normal View History

2023-07-31 21:13:20 +00:00
ARG ALPINE_VERSION
2023-07-31 21:17:04 +00:00
ARG ELIXIR_DOCKER_IMAGE
2021-04-08 18:19:52 +00:00
2021-07-06 10:06:13 +00:00
#### STEP 1 - Build our app
2023-07-03 09:49:43 +00:00
FROM hexpm/elixir:${ELIXIR_DOCKER_IMAGE} as builder
2021-04-08 18:19:52 +00:00
2023-07-31 20:48:27 +00:00
ARG FLAVOUR_PATH
2023-07-31 21:03:07 +00:00
ARG FORKS_TO_COPY_PATH
2023-07-31 20:48:27 +00:00
2022-12-09 04:07:07 +00:00
# necessary utils + dependencies for comeonin
2023-02-25 08:39:05 +00:00
RUN apk --update add tar curl git rust cargo npm yarn bash make gcc libc-dev openssl-dev
2022-12-09 04:07:07 +00:00
2023-07-31 20:48:27 +00:00
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod FLAVOUR_PATH=./
2021-04-08 18:19:52 +00:00
WORKDIR $HOME
# Cache elixir deps
2022-10-17 08:43:10 +00:00
COPY mix.exs mix.lock ./
2022-12-09 01:49:21 +00:00
COPY lib/mix ./lib/mix
2021-05-05 19:32:06 +00:00
# sometimes mix tries to read the config
2021-07-10 19:05:56 +00:00
RUN mkdir -p ./config
2021-07-13 08:44:58 +00:00
COPY data/current_flavour/config/config_basics.exs ./config/config.exs
2021-06-17 12:41:23 +00:00
# get deps from hex.pm
2023-03-12 00:28:07 +00:00
COPY data/current_flavour/config/deps*hex ./config/
2021-04-08 18:19:52 +00:00
RUN mix do local.hex --force, local.rebar --force
2023-12-16 15:10:10 +00:00
RUN mix deps.get --only prod
# RUN HEX_HTTP_CONCURRENCY=1 HEX_HTTP_TIMEOUT=120 mix deps.get --only prod
2023-06-26 16:34:34 +00:00
# ^ useful in case of spotting connectivity
2021-04-08 18:19:52 +00:00
2022-06-23 07:11:32 +00:00
# Compile initial hex deps, only if we're not using forks (warning: this makes the assumption that no Bonfire extensions are coming from Hex. otherwise this should be done only after copying config)
2023-12-16 15:10:10 +00:00
RUN if [ "$FORKS_TO_COPY_PATH" = "data/null" ] ; then MIX_ENV=prod mix deps.compile ; else echo "Skip" ; fi
2021-04-08 18:19:52 +00:00
2022-05-06 03:48:49 +00:00
# add git deps (typically Bonfire extensions)
2023-03-12 00:28:07 +00:00
COPY data/current_flavour/config/deps*git ./config/
2022-05-06 03:48:49 +00:00
2022-06-23 07:11:32 +00:00
# fetch them because we need them for the non-configurable paths in config/deps_hooks.js
2023-12-16 15:10:10 +00:00
RUN mix deps.get --only prod
# RUN HEX_HTTP_CONCURRENCY=1 HEX_HTTP_TIMEOUT=120 mix deps.get --only prod
2021-04-08 18:19:52 +00:00
2021-05-05 19:48:17 +00:00
# we need config before compiling Bonfire extensions
2022-06-23 07:11:32 +00:00
COPY data/current_flavour/config/ ./config/
2022-06-23 01:16:54 +00:00
2022-06-23 07:11:32 +00:00
# Optionally include local forks
2023-03-12 00:28:07 +00:00
RUN if [ "$FORKS_TO_COPY_PATH" = "data/null" ] ; then rm ./config/deps*path ; else echo "Include locally forked extensions." ; fi
COPY ${FORKS_TO_COPY_PATH} ./${FORKS_TO_COPY_PATH}
2021-05-05 19:48:17 +00:00
2022-05-06 03:48:49 +00:00
# Update Bonfire extensions to latest git version (mostly useful in CI, and temporary: eventually we want to rely on version numbers and lockfile)
2023-12-16 15:10:10 +00:00
# RUN mix bonfire.deps.update
2021-04-27 10:20:18 +00:00
2023-12-18 11:08:43 +00:00
# Fetch git deps - should be after forks are copied (and updates are fetched, if doing so) in case a forked/updated extension specified any different deps)
2023-12-16 15:10:10 +00:00
RUN mix deps.get --only prod
2022-06-23 07:11:32 +00:00
# Include translations
COPY priv/localisation/ priv/localisation/
# RUN ls -la priv/localisation/
2021-04-08 18:19:52 +00:00
2023-12-16 14:32:17 +00:00
# copy these before compiling so we don't override things like flavour_assets/components.css (generated by Surface compiler)
COPY data/current_flavour/config/flavour_assets data/current_flavour/config/flavour_assets
RUN ls -la data/current_flavour/config/flavour_assets
# docs/guides
2022-12-09 04:07:07 +00:00
COPY docs/*.md ./docs/
2022-05-06 03:48:49 +00:00
# Compile remaining deps
2023-12-16 15:10:10 +00:00
# RUN MIX_ENV=prod mix deps.compile # disabled because doesn't properly compile Surface hooks/CSS
2022-05-06 03:48:49 +00:00
2021-06-08 11:37:53 +00:00
# JS package manager
# RUN npm install -g pnpm
2021-05-15 18:23:52 +00:00
# install JS deps
2022-12-09 04:07:07 +00:00
COPY js-deps-get.sh ./
# COPY assets/package.json ./assets/
# COPY assets/pnpm-lock.yaml ./assets/
2022-12-09 04:07:07 +00:00
# COPY assets/yarn.lock ./assets/
RUN chmod +x config/*.sh
2022-12-09 04:07:07 +00:00
RUN chmod +x ./*.sh
2022-07-20 02:13:44 +00:00
RUN sh config/deps.js.sh
2022-07-20 01:49:32 +00:00
# FIXME: should we be installing dev deps here?
2021-05-15 18:23:52 +00:00
2022-04-07 03:26:40 +00:00
# Update mime types
2023-12-16 15:10:10 +00:00
RUN MIX_ENV=prod mix deps.clean --build mime
2022-04-07 03:26:40 +00:00
# Include migrations
2021-06-17 13:17:47 +00:00
COPY data/current_flavour/repo priv/repo
2021-06-17 12:41:23 +00:00
# bonfire-app code & assets
2021-06-17 13:17:47 +00:00
COPY lib lib
2022-12-09 04:07:07 +00:00
# COPY assets assets
# RUN ls -la assets/static
2021-04-08 18:19:52 +00:00
2024-01-16 16:59:30 +00:00
# workaround for compilation error
RUN MIX_ENV=prod mix deps.clean needle_ulid --build
2023-12-16 15:10:10 +00:00
# compile app (needs to be before building assets so it includes Surface hooks & component CSS)
RUN MIX_ENV=prod mix compile
2022-04-07 06:38:25 +00:00
# include an archive of the source code
2022-04-07 07:03:17 +00:00
COPY LICENSE ./
RUN mkdir -p apps/
2022-12-09 04:07:07 +00:00
RUN mkdir -p extensions/
2022-07-19 08:50:42 +00:00
RUN mkdir -p forks/
RUN mkdir -p priv/static/
2022-12-09 01:49:21 +00:00
# COPY priv/extras/ priv/extras/
2022-04-07 06:38:25 +00:00
2021-04-08 18:19:52 +00:00
# prepare static assets
2022-03-15 22:08:28 +00:00
COPY data/current_flavour/config/deps_hooks.js data/current_flavour/config/deps_hooks.js
2022-12-09 04:07:07 +00:00
RUN cd ./deps/bonfire_ui_common/assets && yarn && yarn build
2021-06-10 17:11:23 +00:00
RUN MIX_ENV=prod CI=1 mix phx.digest
2022-12-09 05:22:16 +00:00
RUN ls -la priv/static
RUN ls -la priv/static/assets
2022-12-09 09:18:28 +00:00
RUN tar --exclude=*.env --exclude=.git --exclude=node_modules --exclude=priv/static/data --exclude=*/*/assets/static/data -czvf priv/static/source.tar.gz lib deps apps extensions forks config docs priv/repo priv/static mix.exs mix.lock LICENSE || echo "Could not prepare code archive"
2021-04-08 18:19:52 +00:00
# build final OTP release
2021-06-10 17:11:23 +00:00
RUN MIX_ENV=prod CI=1 mix release
2021-04-08 18:19:52 +00:00
2022-12-09 04:07:07 +00:00
##### STEP 2 - Prepare the server image ####
2021-04-08 18:19:52 +00:00
# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}
2023-07-31 20:48:27 +00:00
ENV APP_REVISION=${APP_VSN}-${APP_BUILD}
2021-04-08 18:19:52 +00:00
# Essentials
RUN apk add --update --no-cache \
mailcap \
ca-certificates \
openssh-client \
openssl-dev \
2023-02-25 08:39:05 +00:00
# ^ for HTTPS, etc
2021-04-08 18:19:52 +00:00
git \
build-base \
# ^ required by tree_magic
tzdata \
gettext \
# ^ localisation
2022-03-13 07:02:01 +00:00
imagemagick \
2022-05-16 11:04:45 +00:00
vips-tools \
2023-10-09 22:19:41 +00:00
poppler-utils \
2022-03-13 07:02:01 +00:00
# ^ image resizing
2021-04-08 18:19:52 +00:00
bash \
2023-02-25 08:39:05 +00:00
curl
2022-03-13 07:02:01 +00:00
#^ misc
2022-03-15 22:08:28 +00:00
2021-04-08 18:19:52 +00:00
WORKDIR /opt/app
2022-06-23 01:16:54 +00:00
# copy app build
2021-04-08 18:19:52 +00:00
COPY --from=builder /opt/app/_build/prod/rel/bonfire /opt/app
# start
CMD ["./bin/bonfire", "start"]