bonfire-app/Dockerfile.release

198 lines
6.6 KiB
Docker
Raw Permalink Normal View History

2024-03-30 22:11:45 +00:00
# syntax=docker/dockerfile:1.7-labs
2024-03-30 22:52:18 +00:00
# ^ needed for --parents flag
2024-03-30 22:11:45 +00:00
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
2024-04-01 11:19:53 +00:00
ARG FLAVOUR
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
2024-04-16 21:13:38 +00:00
COPY --link deps-alpine.sh ./
COPY --link deps-alpine-build.sh ./
RUN chmod +x ./*.sh
RUN sh deps-alpine-build.sh
# 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
2024-03-30 22:37:22 +00:00
# Prepare elixir deps
COPY --link mix.exs ./
COPY --link 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
COPY --link data/current_flavour/config/config_basics.exs ./config/config.exs
2021-06-17 12:41:23 +00:00
2024-02-20 18:51:38 +00:00
RUN mix do local.hex --force, local.rebar --force
2024-03-30 22:37:22 +00:00
# FIXME: copying mix.lock here means the optimisations of fetching hex and git deps seperately are useless, so commenting those for now
COPY --link mix.lock ./
2021-04-08 18:19:52 +00:00
2024-03-30 22:37:22 +00:00
# # first get deps from hex.pm
# COPY --link data/current_flavour/config/deps*hex ./config/
# COPY --parents --link flavours/*/config/deps*hex ./
2021-04-08 18:19:52 +00:00
2024-03-30 22:37:22 +00:00
# # RUN mix deps.get --only prod
# RUN HEX_HTTP_CONCURRENCY=1 HEX_HTTP_TIMEOUT=120 mix deps.get --only prod
2022-05-06 03:48:49 +00:00
2024-03-30 22:37:22 +00:00
# RUN ls -la config/*
# # 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)
# RUN if [ "$FORKS_TO_COPY_PATH" = "data/null" ] ; then MIX_ENV=prod mix deps.compile ; else echo "Skip" ; fi
# # add flavour's git deps (typically Bonfire extensions)
# COPY --link data/current_flavour/config/deps*git ./config/
# COPY --parents --link flavours/*/config/deps*git ./
2024-02-20 18:51:38 +00:00
2024-03-30 22:37:22 +00:00
# # fetch more deps/extensions
# RUN mix deps.get --only prod
# add main dep sources
2024-04-16 08:47:41 +00:00
COPY --link data/current_flavour/config/deps.flavour.* ./config/
2024-03-30 22:37:22 +00:00
RUN ls -la config/*
2024-03-30 22:52:18 +00:00
RUN mix deps.get --only prod
# RUN HEX_HTTP_CONCURRENCY=1 HEX_HTTP_TIMEOUT=120 mix deps.get --only prod
# # ^ useful in case of spotty connectivity
2024-03-30 22:37:22 +00:00
2024-04-01 11:19:53 +00:00
## add extra deps
2024-03-30 22:37:22 +00:00
# from other flavours
COPY --parents --link flavours/*/config/* ./
2024-04-01 11:19:53 +00:00
# specified by the core app
2024-02-16 23:28:56 +00:00
RUN cp -rfL deps/bonfire/deps.* ./config/
2024-04-01 11:19:53 +00:00
RUN ls -la config/* && ls flavours/*/config/*
2024-02-16 23:28:56 +00:00
2024-03-30 22:37:22 +00:00
# fetch extras (we need extensions for the non-configurable paths in config/deps_hooks.js)
2024-04-01 11:19:53 +00:00
# RUN mix deps.get --only prod
2024-03-30 22:52:18 +00:00
# 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
COPY --link 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
2024-03-30 22:11:45 +00:00
RUN if [ "$FORKS_TO_COPY_PATH" = "data/null" ] ; then rm ./config/deps*path && rm ./flavours/*/config/deps*path ; else echo "Include locally forked extensions." ; fi
COPY --link ${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
2024-04-01 11:19:53 +00:00
RUN ls deps/
2022-06-23 07:11:32 +00:00
# Include translations
COPY --link 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 --link data/current_flavour/config/flavour_assets data/current_flavour/config/flavour_assets
2024-04-16 09:09:16 +00:00
RUN ls -la data/current_flavour/config/flavour_assets && ls -la data/current_flavour/config/flavour_assets/hooks
2023-12-16 14:32:17 +00:00
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
COPY --link js-deps-get.sh ./
# COPY --link assets/package.json ./assets/
# COPY --link assets/pnpm-lock.yaml ./assets/
# COPY --link 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
2021-06-17 12:41:23 +00:00
# bonfire-app code & assets
COPY --link lib lib
# COPY --link assets assets
# RUN ls -la assets/static
2021-04-08 18:19:52 +00:00
2024-02-16 23:19:05 +00:00
# workaround for compilation errors
RUN MIX_ENV=prod mix deps.clean needle_ulid jason poison --build
2024-01-16 16:59:30 +00:00
2024-02-16 23:19:05 +00:00
# compile protocols (attempted fix for 'could not load module Poison.Encoder due to reason :unavailable')
# RUN MIX_ENV=prod mix compile.protocols
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
2024-04-01 11:19:53 +00:00
# Include any migrations provided by flavour (maybe not needed?)
# COPY --link data/current_flavour/repo priv/repo
2024-04-01 11:19:53 +00:00
RUN mkdir -p priv/repo/migrations
2024-03-10 19:52:34 +00:00
# Copy DB/repo migrations from installed extensions
2024-03-10 21:36:13 +00:00
RUN mix bonfire.extension.copy_migrations --force --to priv/repo/migrations
2024-03-10 19:52:34 +00:00
# docs/guides
COPY --link LICENSE ./
COPY --link ./*.md ./
COPY --link docs/*.md ./docs/
2022-04-07 06:38:25 +00:00
# include an archive of the source code
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/
# COPY --link priv/extras/ priv/extras/
2022-04-07 06:38:25 +00:00
2021-04-08 18:19:52 +00:00
# prepare static assets
COPY --link 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
WORKDIR /opt/app
2024-04-16 21:13:38 +00:00
# Essentials
COPY --link deps-alpine.sh ./
RUN chmod +x ./deps-alpine.sh
RUN sh deps-alpine.sh
# RUN apk add --update --no-cache \
# mailcap \
# ca-certificates \
# openssh-client \
# openssl-dev \
# # ^ for HTTPS, etc
# git \
# # build-base \
# # ^ required by tree_magic
# tzdata \
# gettext \
# # ^ localisation
# imagemagick \
# vips-tools \
# poppler-utils \
# # ^ image resizing
# bash \
# curl
# #^ misc
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
2024-04-01 11:19:53 +00:00
COPY --from=builder /opt/app/flavours/ /opt/app/flavours/
RUN ls /opt/app/lib/
2021-04-08 18:19:52 +00:00
# start
CMD ["./bin/bonfire", "start"]