-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·88 lines (79 loc) · 3.43 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·88 lines (79 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# One-click installer for Zulivio.
#
# Run this from the repo root after cloning:
# ./install.sh
#
# Generates a .env with a random Postgres password (only if one doesn't
# already exist), builds the backend + web Docker images, starts the stack,
# and waits for the app to come online (the `migrate` service applies
# database migrations automatically before `backend` starts). Safe to
# re-run any time (e.g. after `git pull`, to rebuild) — nothing here
# overwrites an existing .env or destroys existing data.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
# --- 1. Check prerequisites -------------------------------------------------
# Docker Engine must be installed and the `docker compose` plugin available
# (it ships by default with current Docker Desktop / Docker Engine).
if ! command -v docker >/dev/null 2>&1; then
echo "Error: Docker is not installed." >&2
echo "Install it from https://docs.docker.com/get-docker/ and re-run this script." >&2
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "Error: the 'docker compose' plugin was not found." >&2
echo "Update Docker Desktop/Engine to a version that bundles Compose v2." >&2
exit 1
fi
# --- 2. Generate .env if one doesn't exist already --------------------------
# A one-click install can't ask you to hand-edit POSTGRES_PASSWORD first —
# compose.yaml has no insecure default, it fails loudly instead — so
# generate a real random value here. Never overwrites an existing .env, so
# re-running this script is safe.
if [ ! -f .env ]; then
echo "No .env found — generating one with a random Postgres password..."
if command -v openssl >/dev/null 2>&1; then
pg_password="$(openssl rand -hex 16)"
else
pg_password="$(head -c24 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c32)"
fi
cat > .env <<EOF
POSTGRES_PASSWORD=${pg_password}
FRONTEND_ORIGIN=http://localhost:3100
HOST_PORT=3100
BOOTSTRAP_DISABLED=false
GOOGLE_SHEETS_CLIENT_EMAIL=
GOOGLE_SHEETS_PRIVATE_KEY=
EOF
echo ".env created with a generated POSTGRES_PASSWORD."
fi
# --- 3. Build the images and start the stack --------------------------------
echo "Building Zulivio images and starting the stack (this can take a few minutes on first run)..."
# Bakes the checked-out git tag into the backend image so the app can report
# its own version (used by the "update available" check) — falls back to
# "dev" outside a git checkout or on a commit with no tag.
export APP_VERSION="$(git describe --tags --always 2>/dev/null || echo dev)"
docker compose up -d --build
# --- 4. Wait for the app to report healthy ----------------------------------
# By the time /api/health/ready returns 200, the `migrate` service has
# already applied all migrations (backend only starts once migrate exits 0).
HOST_PORT="$(grep -m1 '^HOST_PORT=' .env 2>/dev/null | cut -d= -f2-)"
HOST_PORT="${HOST_PORT:-3100}"
echo "Waiting for the app to come online..."
ready=false
for _ in $(seq 1 90); do
if curl -sf "http://localhost:${HOST_PORT}/api/health/ready" >/dev/null 2>&1; then
ready=true
break
fi
sleep 1
done
if [ "$ready" != "true" ]; then
echo "Warning: the app didn't respond within 90s. Check the logs with:" >&2
echo " docker compose logs" >&2
exit 1
fi
# --- 5. Done -----------------------------------------------------------------
echo ""
echo "Zulivio is up and running."
echo "Open http://localhost:${HOST_PORT}/setup to create your organization and Master Owner account."