fix(deploy): isolate demo settings and monitoring
This commit is contained in:
1 parent
6dd5a0d54a
commit
6d6aa9ffe8
7 files changed
+331
-36
No files matched your search
+33
-10
@@ -20,7 +20,8 @@
|
||||
# differs from APP_PROJECT
|
||||
# APP_PROJECT the ordinary project, only compared against
|
||||
# ENV_FILE root env file with the stand secrets
|
||||
# DEMO_ENV_FILE demo env file with DEMO_ACCOUNT_PASSWORD
|
||||
# DEMO_ENV_FILE local demo env file; the example supplies defaults
|
||||
# APP_HTTP_BIND comes from the demo env file so the core bind is ignored
|
||||
# DEMO_HTTP_PORT host port of the demo frontend
|
||||
# DEMO_PUBLIC_URL public origin of the demo stand
|
||||
# DEMO_SUBNET, DEMO_FRONTEND_IP pinned network of the demo project
|
||||
@@ -45,6 +46,16 @@ fail() {
|
||||
exit 2
|
||||
}
|
||||
|
||||
read_env_value() {
|
||||
local file=$1 key=$2 line value=''
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ "$line" == "$key="* ]]; then
|
||||
value=${line#*=}
|
||||
fi
|
||||
done < "$file"
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
if [[ "$#" -ne 1 ]]; then
|
||||
fail 'usage: demo.sh seed|reset|down'
|
||||
fi
|
||||
@@ -58,18 +69,25 @@ esac
|
||||
if [[ "${DEMO_MODE:-}" != isolated ]]; then
|
||||
fail "refusing to $action: set DEMO_MODE=isolated; the demo targets act only on an isolated demo stand"
|
||||
fi
|
||||
project="${DEMO_PROJECT:-lincodex-demo}"
|
||||
ordinary_project="${APP_PROJECT:-app}"
|
||||
env_file="${ENV_FILE:-$root/.env}"
|
||||
demo_example_file="$root/deploy/demo/demo.env.example"
|
||||
demo_env_file="${DEMO_ENV_FILE:-$root/deploy/demo/demo.env}"
|
||||
[[ -f "$env_file" ]] || fail "missing $env_file; copy .env.example to .env and replace the placeholder passwords"
|
||||
[[ -f "$demo_example_file" ]] || fail "missing demo env example $demo_example_file"
|
||||
[[ -f "$demo_env_file" ]] || fail "missing demo env file $demo_env_file"
|
||||
configured_project=$(read_env_value "$demo_env_file" DEMO_PROJECT)
|
||||
if [[ -z "$configured_project" && "$demo_env_file" != "$demo_example_file" ]]; then
|
||||
configured_project=$(read_env_value "$demo_example_file" DEMO_PROJECT)
|
||||
fi
|
||||
project="${DEMO_PROJECT:-${configured_project:-lincodex-demo}}"
|
||||
configured_ordinary_project=$(read_env_value "$env_file" APP_PROJECT)
|
||||
if [[ ! "$project" =~ ^[a-z0-9][a-z0-9_-]*$ || "$project" != *demo* ]]; then
|
||||
fail "refusing to $action: DEMO_PROJECT must be a Compose project name that contains 'demo'"
|
||||
fi
|
||||
if [[ "$project" == "$ordinary_project" ]]; then
|
||||
fail "refusing to $action: DEMO_PROJECT must differ from the ordinary project APP_PROJECT=$ordinary_project"
|
||||
if [[ "$project" == "$ordinary_project" || ( -n "$configured_ordinary_project" && "$project" == "$configured_ordinary_project" ) ]]; then
|
||||
fail "refusing to $action: DEMO_PROJECT must differ from the ordinary project APP_PROJECT"
|
||||
fi
|
||||
env_file="${ENV_FILE:-$root/.env}"
|
||||
demo_env_file="${DEMO_ENV_FILE:-$root/deploy/demo/demo.env.example}"
|
||||
[[ -f "$env_file" ]] || fail "missing $env_file; copy .env.example to .env and replace the placeholder passwords"
|
||||
[[ -f "$demo_env_file" ]] || fail "missing demo env file $demo_env_file"
|
||||
actor="${DEMO_ACTOR:-operator:demo-seed}"
|
||||
[[ "$actor" =~ ^operator:[a-z0-9][a-z0-9._-]*$ ]] || fail 'DEMO_ACTOR must be operator:<handle>'
|
||||
port="${DEMO_HTTP_PORT:-8090}"
|
||||
@@ -78,18 +96,23 @@ public_url="${DEMO_PUBLIC_URL:-http://localhost:$port}"
|
||||
subnet="${DEMO_SUBNET:-172.29.84.0/24}"
|
||||
frontend_ip="${DEMO_FRONTEND_IP:-172.29.84.10}"
|
||||
release_manifest="${DEMO_RELEASE_MANIFEST:-}"
|
||||
env_files=(--env-file "$env_file" --env-file "$demo_example_file")
|
||||
if [[ "$demo_env_file" != "$demo_example_file" ]]; then
|
||||
env_files+=(--env-file "$demo_env_file")
|
||||
fi
|
||||
compose_files=(-f "$compose_file" -f "$demo_file")
|
||||
# From the current sources by default; pinned by the release override below.
|
||||
up_args=(--build)
|
||||
run_args=(--build)
|
||||
|
||||
# The shell values override the env files, so the root .env cannot point the
|
||||
# demo project at the ordinary project's names, network, or port.
|
||||
# demo project at the ordinary project's names, network, or port. The demo
|
||||
# env file is loaded last to override core-only settings such as APP_HTTP_BIND.
|
||||
compose() {
|
||||
APP_PROJECT="$project" APP_NETWORK="${project}_default" APP_STORAGE_NETWORK="${project}_storage" \
|
||||
APP_HTTP_PORT="$port" APP_SUBNET="$subnet" APP_FRONTEND_IP="$frontend_ip" APP_PUBLIC_URL="$public_url" \
|
||||
DEMO_MODE=isolated "$docker_cli" compose \
|
||||
--env-file "$env_file" --env-file "$demo_env_file" \
|
||||
"${env_files[@]}" \
|
||||
-p "$project" "${compose_files[@]}" "$@"
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user