bonfire-app/Dockerfile.release

161 lines
5.3 KiB
Docker
Raw Normal View History

2022-05-06 03:48:49 +00:00
# Define what version of Elixir to use - ATTENTION: when changing Elixir version
# make sure to update the `ALPINE_VERSION` arg to match,
# as well as the Elixir version in:
# - mix.exs
# - .github/workflows/test.yaml or .gitlab-ci.yml
# - Dockerfile.dev
# - .tool-versions
2023-01-05 03:36:11 +00:00
ARG ELIXIR_IMAGE=1.14-alpine
2021-04-08 18:19:52 +00:00
# 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:
2022-05-21 21:41:40 +00:00
# 1. Locate the dockerfile for the elixir image matching the version, and check what erlang version it uses
2022-06-14 09:56:00 +00:00
# e.g. https://github.com/erlef/docker-elixir/blob/master/1.13/otp-25-alpine/Dockerfile
2022-05-21 21:41:40 +00:00
# 2. Locate the corresponding dockerfile for the erlang version used, and check what alpine version it uses, and then copy that number into the ARG below:
2022-06-14 09:56:00 +00:00
# e.g. https://github.com/erlang/docker-erlang-otp/blob/master/25/alpine/Dockerfile
ARG ALPINE_VERSION=3.16
2021-04-08 18:19:52 +00:00
# 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
2021-06-16 19:25:54 +00:00
ARG FLAVOUR
2021-06-08 14:11:02 +00:00
ARG FLAVOUR_PATH
2021-04-08 18:19:52 +00:00
2021-07-06 10:06:13 +00:00
#### STEP 1 - Build our app
2022-06-14 10:06:49 +00:00
FROM elixir:${ELIXIR_IMAGE} as builder
2021-04-08 18:19:52 +00:00
2022-12-09 04:07:07 +00:00
# necessary utils + dependencies for comeonin
RUN apk --update add tar curl git rust cargo npm yarn bash make gcc libc-dev
2021-06-17 12:41:23 +00:00
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod APP_NAME=$APP_NAME FLAVOUR=$FLAVOUR 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
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
RUN mix do deps.get --only prod
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)
RUN if [ "$FORKS_TO_COPY_PATH" = "data/null" ] ; then MIX_ENV=prod mix do 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)
2021-06-17 13:17:47 +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
2021-04-08 18:19:52 +00:00
RUN mix do deps.get --only prod
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
ARG FORKS_TO_COPY_PATH
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)
# RUN mix do bonfire.deps.update
2021-04-27 10:20:18 +00:00
2022-06-23 07:11:32 +00:00
# Fetch git deps (should be after forks are copied and updates are fetched, in case a forked/updated extension specified any different deps)
RUN mix do deps.get --only prod
# Include translations
COPY priv/localisation/ priv/localisation/
# RUN ls -la priv/localisation/
2021-04-08 18:19:52 +00:00
2022-12-09 04:07:07 +00:00
COPY docs/*.md ./docs/
2022-05-06 03:48:49 +00:00
# Compile remaining deps
RUN MIX_ENV=prod mix do deps.compile
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
RUN MIX_ENV=prod mix do deps.clean --build mime
# 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
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}
# The name of your application/release (required)
ARG APP_NAME
ARG APP_VSN
ARG APP_BUILD
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
2022-03-13 07:02:01 +00:00
imagemagick \
2022-05-16 11:04:45 +00:00
vips-tools \
2022-03-13 07:02:01 +00:00
# ^ image resizing
2021-04-08 18:19:52 +00:00
bash \
2022-03-13 07:02:01 +00:00
curl
#^ 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"]