2023-06-15 20:17:03 +08:00
|
|
|
ARG BASE_IMAGE
|
2022-12-13 06:35:13 +08:00
|
|
|
|
2021-04-27 22:34:02 +08:00
|
|
|
# Stage 1
|
|
|
|
# Builds the Livebook release
|
2022-12-13 06:35:13 +08:00
|
|
|
FROM ${BASE_IMAGE} AS build
|
2021-04-27 22:34:02 +08:00
|
|
|
|
2021-09-19 00:17:44 +08:00
|
|
|
RUN apt-get update && apt-get upgrade -y && \
|
|
|
|
apt-get install --no-install-recommends -y \
|
|
|
|
build-essential git && \
|
|
|
|
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
|
|
|
|
apt-get clean -y && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2021-04-27 22:34:02 +08:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
2023-05-31 17:47:31 +08:00
|
|
|
# This flag disables JIT behaviour that causes a segfault under QEMU.
|
|
|
|
# Note that we set this runtime flag only during the build stage and
|
|
|
|
# it has no impact when running the final image. See [1] for more
|
|
|
|
# information.
|
|
|
|
#
|
|
|
|
# [1]: https://github.com/erlang/otp/pull/6340
|
2023-07-13 18:29:46 +08:00
|
|
|
ENV ERL_FLAGS="+JMsingle true"
|
2023-05-31 17:47:31 +08:00
|
|
|
|
2021-04-27 22:34:02 +08:00
|
|
|
# Install hex and rebar
|
|
|
|
RUN mix local.hex --force && \
|
|
|
|
mix local.rebar --force
|
|
|
|
|
|
|
|
# Build for production
|
|
|
|
ENV MIX_ENV=prod
|
|
|
|
|
|
|
|
# Install mix dependencies
|
|
|
|
COPY mix.exs mix.lock ./
|
|
|
|
COPY config config
|
|
|
|
RUN mix do deps.get, deps.compile
|
|
|
|
|
|
|
|
# Compile and build the release
|
2021-06-18 23:32:53 +08:00
|
|
|
COPY rel rel
|
2021-10-19 04:32:09 +08:00
|
|
|
COPY static static
|
2022-02-08 21:45:58 +08:00
|
|
|
COPY iframe/priv/static/iframe iframe/priv/static/iframe
|
2022-11-10 23:02:59 +08:00
|
|
|
COPY proto proto
|
2021-04-27 22:34:02 +08:00
|
|
|
COPY lib lib
|
|
|
|
# We need README.md during compilation
|
|
|
|
# (look for @external_resource "README.md")
|
|
|
|
COPY README.md README.md
|
2022-01-18 00:58:54 +08:00
|
|
|
RUN mix do compile, release livebook
|
2021-04-27 22:34:02 +08:00
|
|
|
|
|
|
|
# Stage 2
|
2022-06-13 00:10:37 +08:00
|
|
|
# Prepares the runtime environment and copies over the release.
|
2021-04-27 22:34:02 +08:00
|
|
|
# We use the same base image, because we need Erlang, Elixir and Mix
|
|
|
|
# during runtime to spawn the Livebook standalone runtimes.
|
|
|
|
# Consequently the release doesn't include ERTS as we have it anyway.
|
2022-12-13 06:35:13 +08:00
|
|
|
FROM ${BASE_IMAGE}
|
2021-04-27 22:34:02 +08:00
|
|
|
|
2021-09-19 00:17:44 +08:00
|
|
|
RUN apt-get update && apt-get upgrade -y && \
|
|
|
|
apt-get install --no-install-recommends -y \
|
|
|
|
# Runtime dependencies
|
|
|
|
build-essential ca-certificates libncurses5-dev \
|
|
|
|
# In case someone uses `Mix.install/2` and point to a git repo
|
2021-09-21 00:41:25 +08:00
|
|
|
git \
|
|
|
|
# Additional standard tools
|
2021-11-10 18:31:38 +08:00
|
|
|
wget \
|
|
|
|
# In case someone uses Torchx for Nx
|
|
|
|
cmake && \
|
2021-09-19 00:17:44 +08:00
|
|
|
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
|
|
|
|
apt-get clean -y && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2021-04-27 22:34:02 +08:00
|
|
|
|
|
|
|
# Run in the /data directory by default, makes for
|
|
|
|
# a good place for the user to mount local volume
|
|
|
|
WORKDIR /data
|
|
|
|
|
|
|
|
ENV HOME=/home/livebook
|
|
|
|
# Make sure someone running the container with `--user`
|
|
|
|
# has permissions to the home dir (for `Mix.install/2` cache)
|
|
|
|
RUN mkdir $HOME && chmod 777 $HOME
|
|
|
|
|
|
|
|
# Install hex and rebar for `Mix.install/2` and Mix runtime
|
|
|
|
RUN mix local.hex --force && \
|
|
|
|
mix local.rebar --force
|
|
|
|
|
|
|
|
# Override the default 127.0.0.1 address, so that the app
|
|
|
|
# can be accessed outside the container by binding ports
|
2024-05-16 22:28:41 +08:00
|
|
|
ENV LIVEBOOK_IP "::"
|
2021-04-27 22:34:02 +08:00
|
|
|
|
2022-05-17 04:14:39 +08:00
|
|
|
ENV LIVEBOOK_HOME=/data
|
|
|
|
|
2021-04-27 22:34:02 +08:00
|
|
|
# Copy the release build from the previous stage
|
|
|
|
COPY --from=build /app/_build/prod/rel/livebook /app
|
|
|
|
|
2022-05-18 05:11:39 +08:00
|
|
|
# Make release files available to any user, in case someone
|
|
|
|
# runs the container with `--user`
|
|
|
|
RUN chmod -R go=u /app
|
2023-04-28 00:37:31 +08:00
|
|
|
# Make all home files available (specifically .mix/)
|
|
|
|
RUN chmod -R go=u $HOME
|
2021-04-27 22:34:02 +08:00
|
|
|
|
2024-03-25 22:05:34 +08:00
|
|
|
HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:${LIVEBOOK_PORT-8080}/public/health || exit 1
|
|
|
|
|
2024-06-08 02:58:48 +08:00
|
|
|
CMD [ "/app/bin/server" ]
|