mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-23 22:37:41 +08:00
Embed fly clustering into the release (#2519)
This commit is contained in:
parent
1038ef8d24
commit
e892d9dea0
5 changed files with 28 additions and 21 deletions
|
@ -201,8 +201,9 @@ The following environment variables can be used to configure Livebook on boot:
|
|||
accesses files from external sources.
|
||||
|
||||
* `LIVEBOOK_CLUSTER` - configures clustering strategy when running multiple
|
||||
instances of Livebook. See the "Clustering" section of our Docker Deployment
|
||||
guide for more information: https://hexdocs.pm/livebook/docker.html
|
||||
instances of Livebook using either the Docker image or an Elixir release.
|
||||
See the "Clustering" section of our Docker Deployment guide for more
|
||||
information: https://hexdocs.pm/livebook/docker.html
|
||||
|
||||
* `LIVEBOOK_COOKIE` - sets the cookie for running Livebook in a cluster.
|
||||
Defaults to a random string that is generated on boot.
|
||||
|
|
|
@ -50,16 +50,18 @@ If you are using [Livebook Teams](https://livebook.dev/teams/), you will also ha
|
|||
|
||||
## Clustering
|
||||
|
||||
If you plan to run several Livebook instances behind a load balancer, you need to enable clustering via the `LIVEBOOK_CLUSTER` environment variable. Currently the only supported value is `dns:QUERY`, in which case nodes ask DNS for A/AAAA records using the given query and try to connect to peer nodes on the discovered IPs.
|
||||
If you plan to run several Livebook instances behind a load balancer, you need to enable clustering via the `LIVEBOOK_CLUSTER` environment variable. Depending on the strategy of your choice, you must set additional environment variables, oftentimes, at runtime. When using the Livebook Docker image, you can create a file at `/app/user/env.sh` that exports the necessary environment variables. This file is invoked right before booting Livebook. `LIVEBOOK_DISTRIBUTION` is automatically set to `name` if clustering is enabled.
|
||||
|
||||
When clustering is enabled, you must additionally set the following env vars:
|
||||
### `LIVEBOOK_CLUSTER=fly`
|
||||
|
||||
It automatically sets up a cluster to run on Fly using DNS configuration. It automatically sets up the environment variables based on your Fly Application name and enables IPv6 support.
|
||||
|
||||
### `LIVEBOOK_CLUSTER=dns:QUERY`
|
||||
|
||||
Sets up a cluster using DNS for queries for A/AAAA records to discover new nodes. Additionally, you must additionally set the following env vars:
|
||||
|
||||
* `LIVEBOOK_NODE=livebook_server@IP`, where `IP` is the machine IP of each deployed node
|
||||
|
||||
* You must set `LIVEBOOK_SECRET_KEY_BASE` and `LIVEBOOK_COOKIE` to different random values (use `openssl rand -base64 48` to generate said values)
|
||||
|
||||
* If your cloud requires IPv6, also set `ERL_AFLAGS="-proto_dist inet6_tcp"`
|
||||
|
||||
`LIVEBOOK_DISTRIBUTION` is automatically set to `name` if clustering is enabled.
|
||||
|
||||
Some variables, like `LIVEBOOK_NODE`, are oftentimes computed at runtime. When using the Livebook Docker image, you can create a file at `/app/user/env.sh` that exports the necessary environment variables. This file is invoked right before booting Livebook.
|
||||
|
|
|
@ -132,16 +132,8 @@ defmodule Livebook.Hubs.Dockerfile do
|
|||
# Set the same Livebook secrets across all nodes
|
||||
ENV LIVEBOOK_SECRET_KEY_BASE "#{random_secret_key_base}"
|
||||
ENV LIVEBOOK_COOKIE "#{random_cookie}"
|
||||
|
||||
""" <>
|
||||
~S"""
|
||||
# Runtime configuration to cluster multiple Livebook nodes on Fly.io
|
||||
RUN printf '\
|
||||
export ERL_AFLAGS="-proto_dist inet6_tcp"\n\
|
||||
export LIVEBOOK_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}"\n\
|
||||
export LIVEBOOK_CLUSTER="dns:${FLY_APP_NAME}.internal"\n\
|
||||
' > /app/user/env.sh
|
||||
"""
|
||||
ENV LIVEBOOK_CLUSTER "fly"
|
||||
"""
|
||||
end
|
||||
|
||||
[
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
DISTRIBUTION_DEFAULT="sname"
|
||||
NODE_DEFAULT="livebook_server"
|
||||
|
||||
if [ ! -z "$LIVEBOOK_CLUSTER" ]; then
|
||||
DISTRIBUTION_DEFAULT="name";
|
||||
fi
|
||||
|
||||
if [ "$LIVEBOOK_CLUSTER" = "fly" ]; then
|
||||
export ERL_AFLAGS="-proto_dist inet6_tcp"
|
||||
export LIVEBOOK_CLUSTER="dns:${FLY_APP_NAME}.internal"
|
||||
NODE_DEFAULT="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}"
|
||||
fi
|
||||
|
||||
if [ -f "${RELEASE_ROOT}/user/env.sh" ]; then
|
||||
. "${RELEASE_ROOT}/user/env.sh"
|
||||
fi
|
||||
|
||||
export RELEASE_MODE=interactive
|
||||
export RELEASE_NODE=${LIVEBOOK_NODE:-${RELEASE_NODE:-livebook_server}}
|
||||
if [ -z "${LIVEBOOK_CLUSTER}" ]; then DISTRIBUTION_DEFAULT="sname"; else DISTRIBUTION_DEFAULT="name"; fi
|
||||
export RELEASE_NODE=${LIVEBOOK_NODE:-${RELEASE_NODE:-${NODE_DEFAULT}}}
|
||||
export RELEASE_DISTRIBUTION=${LIVEBOOK_DISTRIBUTION:-${RELEASE_DISTRIBUTION:-${DISTRIBUTION_DEFAULT}}}
|
||||
|
||||
if [ ! -z "${LIVEBOOK_COOKIE}" ]; then export RELEASE_COOKIE=${LIVEBOOK_COOKIE}; fi
|
||||
|
|
|
@ -202,7 +202,7 @@ defmodule Livebook.Hubs.DockerfileTest do
|
|||
|
||||
dockerfile = Dockerfile.build_dockerfile(config, hub, [], [], file, [], %{})
|
||||
|
||||
assert dockerfile =~ ~s/export LIVEBOOK_CLUSTER="dns:${FLY_APP_NAME}.internal"/
|
||||
assert dockerfile =~ ~s/ENV LIVEBOOK_CLUSTER "fly"/
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue