From 87f1e402f1cf5475a16a41a163841ab2c48d3f3d Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:07:10 +0200 Subject: [PATCH 1/5] feat(install): pelican.dev/install.sh, the Panel on Docker Swarm with Traefik and automatic HTTPS One command on a fresh server, in the spirit of Coolify and Dokploy: curl -fsSL https://pelican.dev/install.sh | sudo bash It checks the server (Linux, x86_64/arm64, virtualization, ports 80/443, DNS), installs Docker if missing, starts a one-node Swarm and deploys the "pelican" stack from /opt/pelican: Traefik on 80/443 (HTTP to HTTPS, Let's Encrypt on the first request, renewals on its own) and the Panel behind it (BEHIND_PROXY, TRUSTED_PROXIES set to the network it shares with Traefik). Profiles: quick (SQLite) or production (MariaDB 11.4 and Redis 7, passwords generated). With --wings it installs Wings as the docs do and routes its domain through Traefik. - Guided: asks for what's missing; with --yes every answer is an option, so automation and AI assistants can drive it. --dry-run shows the plan and writes the files without root and without touching the server. - Configurable afterwards: settings in pelican.env (0600), stack.yml reads them, deploy.sh applies them (and updates the Panel). A second run keeps APP_KEY and passwords and refuses to switch profiles over existing data. - Networks clear of Wings: docker_gwbridge is created on 10.204.0.0/24 before "swarm init" (it would take Wings' 172.18.0.0/16), and Swarm uses 10.203.0.0/16 rather than 10.0.0.0/x, which cloud private networks use. - Traefik in host-mode ports (real client IPs), readTimeout 600s for uploads, every service pinned to this node (local volumes). - Safe output: the swarm join token is never printed; the log is root-only; Let's Encrypt's forbidden example.com contacts are refused up front. Served as a root file (router/paths.mjs ROOT_FILES; the Hub's DocsBuildService::ROOT_FILES needs it too). Tested in scripts/install-sh.test.mjs (dry runs, generated stack parsed as YAML, deploy.sh with a stub docker, shellcheck) and end to end in an Ubuntu 24.04 VM. --- README.md | 2 +- public/install.sh | 751 ++++++++++++++++++++++++++++++++++++ router/README.md | 2 +- router/paths.mjs | 2 +- scripts/README.md | 1 + scripts/install-sh.test.mjs | 251 ++++++++++++ 6 files changed, 1006 insertions(+), 3 deletions(-) create mode 100644 public/install.sh create mode 100644 scripts/install-sh.test.mjs diff --git a/README.md b/README.md index 5b8c50c3..6189c547 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ bun test && bun run typecheck && bun run build | `content/docs/**/meta.json` | Sidebar order and section names for that folder. | | `content/pages/` | Stand-alone pages: `/support` and `/faq`. | | `app/(home)/page.tsx` | The homepage. | -| `public/` | Files served as they are, including the `update-panel.sh` and `migrate-*.sh` scripts. | +| `public/` | Files served as they are, including the `install.sh`, `update-panel.sh` and `migrate-*.sh` scripts (`install.sh` is tested in `scripts/install-sh.test.mjs`). | | `netlify.toml` | Build settings and redirects such as `/discord`. | | `ui/` | Design tokens (`tokens.css`) and site nav (`nav.json`) shared with the Hub; published at `/docs/ui/v1/`. | | `scripts/` | The build's checks, the egg data sync and the packing for the Hub. Listed in [scripts/README.md](scripts/README.md). | diff --git a/public/install.sh b/public/install.sh new file mode 100644 index 00000000..314898b8 --- /dev/null +++ b/public/install.sh @@ -0,0 +1,751 @@ +#!/bin/bash +# Pelican one-command install: Docker Swarm, Traefik (automatic HTTPS) and the Panel, and Wings +# on the same server if you want it. +# +# curl -fsSL https://pelican.dev/install.sh | sudo bash +# curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com \ +# --email you@example.com --profile production --yes +# +# Docs: https://pelican.dev/docs/panel/install/ (every option, and how to change things later) +# +# What it does: checks the server, installs Docker if it's missing, starts a one-node Docker +# Swarm, and deploys a stack named "pelican" from /opt/pelican: Traefik on ports 80 and 443, +# which gets a Let's Encrypt certificate for your domain on the first request, and the Panel +# behind it. "production" adds MariaDB and Redis. With --wings it also installs Wings (the +# binary and systemd service, as in the docs) and routes its domain through Traefik. +# +# Settings live in /opt/pelican/pelican.env; change one and run /opt/pelican/deploy.sh. Running +# this script again keeps your keys and passwords, and updates the stack. + +set -Eeuo pipefail + +VERSION="1" +STACK="pelican" +DEFAULT_DIR="/opt/pelican" +PANEL_IMAGE_DEFAULT="ghcr.io/pelican/panel:latest" +TRAEFIK_IMAGE_DEFAULT="traefik:v3" +LE_PRODUCTION="https://acme-v02.api.letsencrypt.org/directory" +LE_STAGING="https://acme-staging-v02.api.letsencrypt.org/directory" +WINGS_RELEASES="https://github.com/pelican/wings/releases/latest/download" + +# Address ranges, picked to stay clear of Docker's defaults (172.17/16), Wings' own network +# (172.18/16, pelican_nw) and the 10.0.0.0/x private networks many cloud providers use. +# Override them in the environment if they clash with your network. +SWARM_POOL="${PELICAN_SWARM_POOL:-10.203.0.0/16}" # Swarm's overlay networks (/24 each) +GWBRIDGE_SUBNET="${PELICAN_GWBRIDGE_SUBNET:-10.204.0.0/24}" # docker_gwbridge: containers <-> host +PUBLIC_SUBNET="${PELICAN_PUBLIC_SUBNET:-10.203.250.0/24}" # Traefik <-> Panel (TRUSTED_PROXIES) + +# ---- Options ------------------------------------------------------------------------------- +domain="" +email="" +profile="" +with_wings="" +wings_domain="" +dir="$DEFAULT_DIR" +panel_image="" +staging=false +check_dns=true +assume_yes=false +dry_run=false + +usage() { + cat <&2; usage >&2; exit 2 ;; + esac +done + +if $dry_run && [[ "$dir" == "$DEFAULT_DIR" ]]; then + dir="$(mktemp -d -t pelican-install.XXXXXX)" +fi + +# ---- Output -------------------------------------------------------------------------------- +if [[ -t 1 ]]; then + bold=$'\e[1m' dim=$'\e[2m' red=$'\e[31m' green=$'\e[32m' yellow=$'\e[33m' reset=$'\e[0m' +else + bold="" dim="" red="" green="" yellow="" reset="" +fi +step() { printf '\n%s==> %s%s\n' "$bold" "$1" "$reset"; } +info() { printf ' %s\n' "$1"; } +ok() { printf ' %s✓%s %s\n' "$green" "$reset" "$1"; } +warn() { printf ' %s!%s %s\n' "$yellow" "$reset" "$1" >&2; } +die() { printf '\n%sError:%s %s\n' "$red" "$reset" "$1" >&2; exit 1; } + +# run CMD...: runs a command, or in a dry run only shows it. +run() { + if $dry_run; then + printf ' %s$ %s%s\n' "$dim" "$*" "$reset" + else + "$@" + fi +} + +# quietly CMD...: runs a command and shows its output only if it fails (or, in a dry run, only +# shows the command). For commands that print what shouldn't be in the log, like swarm tokens. +quietly() { + if $dry_run; then + run "$@" + return + fi + local output + if ! output="$("$@" 2>&1)"; then + printf '%s\n' "$output" >&2 + return 1 + fi +} + +trap 'die "line $LINENO: \"$BASH_COMMAND\" failed. Nothing after this step ran; fix the cause and run the script again (it picks up where it stopped)."' ERR + +# ---- Asking -------------------------------------------------------------------------------- +can_ask() { ! $assume_yes && { : /dev/null; } + +# ask VAR "Question" default: prompts on the terminal (also under curl | bash). +ask() { + local reply="" + if can_ask; then + read -rp " $2${3:+ [$3]}: " reply /dev/null; then + die "No terminal for questions: pass the options and --yes (see --help)." +fi + +# ---- Saved settings ------------------------------------------------------------------------ +env_file="$dir/pelican.env" +declare -A saved=() + +# Reads KEY='value' lines written by save_settings (not sourced: nothing in it runs). +load_settings() { + [[ -f "$env_file" ]] || return 0 + local line key value + while IFS= read -r line || [[ -n "$line" ]]; do + [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]] || continue + key="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + value="${value#\'}" + value="${value%\'}" + saved[$key]="$value" + done <"$env_file" +} + +setting() { printf '%s' "${saved[$1]:-}"; } + +load_settings + +# ---- Gather the options ---------------------------------------------------------------------- +step "Pelican install (script v$VERSION)" +$dry_run && info "Dry run: files go to $dir, nothing on this server changes." +[[ -f "$env_file" ]] && info "Found $env_file: keeping its keys and passwords." + +domain="${domain:-$(setting PANEL_DOMAIN)}" +email="${email:-$(setting LE_EMAIL)}" +old_profile="$(setting PROFILE)" +profile="${profile:-$old_profile}" +wings_domain="${wings_domain:-$(setting WINGS_DOMAIN)}" +[[ -z "$with_wings" && -n "$wings_domain" ]] && with_wings=yes +panel_image="${panel_image:-$(setting PANEL_IMAGE)}" +panel_image="${panel_image:-$PANEL_IMAGE_DEFAULT}" + +if [[ -z "$domain" ]]; then + $assume_yes && die "--domain is needed with --yes (the Panel's address, e.g. panel.example.com)." + ask domain "The Panel's domain (its DNS must point at this server), e.g. panel.example.com" "" +fi +valid_domain "$domain" || die "\"$domain\" isn't a domain name like panel.example.com." + +if [[ -z "$email" ]]; then + $assume_yes && die "--email is needed with --yes (Let's Encrypt sends certificate notices to it)." + ask email "Your email, for Let's Encrypt" "" +fi +valid_email "$email" || die "\"$email\" isn't an email address." +case "${email##*@}" in + example.com | example.net | example.org | localhost) + die "Let's Encrypt refuses addresses at ${email##*@}: use a real email (it only sends certificate notices)." ;; +esac + +if [[ -z "$profile" ]]; then + if can_ask; then + info "Profiles: quick = SQLite, the least to run, fine for one server and a small community." + info " production = MariaDB and Redis, for more servers, users and nodes." + fi + ask profile "Profile (quick/production)" "quick" +fi +[[ "$profile" == quick || "$profile" == production ]] || die "--profile is quick or production, not \"$profile\"." +if [[ -n "$old_profile" && "$profile" != "$old_profile" ]]; then + die "This install uses the $old_profile profile. Switching to $profile would start on an empty database; move the data first (see the docs: panel/install), then change PROFILE in $env_file." +fi + +if [[ -z "$with_wings" ]]; then + if confirm "Install Wings on this server too, to run game servers here?" "n"; then with_wings=yes; else with_wings=no; fi +fi +if [[ "$with_wings" == yes ]]; then + if [[ -z "$wings_domain" ]]; then + $assume_yes && die "--wings-domain is needed with --wings and --yes (e.g. node.example.com)." + ask wings_domain "Wings' domain (its DNS must point here too), e.g. node.example.com" "" + fi + valid_domain "$wings_domain" || die "\"$wings_domain\" isn't a domain name like node.example.com." + [[ "$wings_domain" != "$domain" ]] || die "Wings needs its own domain, not the Panel's ($domain)." +else + wings_domain="" +fi + +le_server="$LE_PRODUCTION" +if $staging; then + le_server="$LE_STAGING" +elif [[ -n "$(setting LE_CA_SERVER)" ]]; then + le_server="$(setting LE_CA_SERVER)" +fi + +app_key="$(setting APP_KEY)" +app_key="${app_key:-base64:$(head -c 32 /dev/urandom | base64)}" +db_password="$(setting DB_PASSWORD)" +db_root_password="$(setting DB_ROOT_PASSWORD)" +if [[ "$profile" == production ]]; then + db_password="${db_password:-$(secret 32)}" + db_root_password="${db_root_password:-$(secret 32)}" +fi + +info "Panel: https://$domain ($profile profile)" +[[ "$with_wings" == yes ]] && info "Wings: https://$wings_domain (on this server)" +info "Files: $dir" +$staging && warn "Let's Encrypt staging: browsers won't trust the certificate. Drop --staging for a real one." + +# ---- Checks -------------------------------------------------------------------------------- +if ! $dry_run && [[ $EUID -eq 0 ]]; then + log_file="/var/log/pelican-install-$(date +%Y%m%d-%H%M%S).log" + install -m 600 /dev/null "$log_file" + exec > >(tee -a "$log_file") 2>&1 + info "Log: $log_file" +fi + +step "Checking this server" +if $dry_run; then + info "Skipped in a dry run: root, operating system, virtualization, ports 80/443 and DNS." +else + [[ $EUID -eq 0 ]] || die "Run it as root, or with sudo: curl -fsSL https://pelican.dev/install.sh | sudo bash" + [[ "$(uname -s)" == Linux ]] || die "Pelican runs on Linux; this is $(uname -s)." + + case "$(uname -m)" in + x86_64 | amd64) arch=amd64 ;; + aarch64 | arm64) arch=arm64 ;; + *) die "Unsupported processor: $(uname -m) (x86_64 and arm64 are)." ;; + esac + ok "Linux on $arch" + + if [[ -r /etc/os-release ]]; then + # shellcheck disable=SC1091 + os_name="$(. /etc/os-release && echo "${PRETTY_NAME:-$ID}")" + ok "$os_name" + fi + + virt="$(systemd-detect-virt 2>/dev/null || true)" + case "$virt" in + openvz | lxc | lxc-libvirt) + die "This server runs under $virt, where Docker usually doesn't work. Use a KVM server or bare metal (see the docs: getting-started)." ;; + *) ok "Virtualization: ${virt:-unknown}" ;; + esac + + # Ports 80 and 443 must be free for Traefik, or already this stack's Traefik (a second run). + for port in 80 443; do + holder="$(ss -ltnpH "sport = :$port" 2>/dev/null | grep -oE 'users:\(\("[^"]+' | head -1 | cut -d'"' -f2 || true)" + [[ -n "$holder" ]] || continue + if [[ "$holder" == docker* ]] && command -v docker >/dev/null 2>&1; then + container="$(docker ps --filter "publish=$port" --format '{{.Names}}' 2>/dev/null | head -1 || true)" + [[ "$container" == "${STACK}_traefik."* ]] && { ports_note=" (already this stack's Traefik)"; continue; } + holder="the container ${container:-$holder}" + fi + die "Port $port is in use by $holder. Traefik needs ports 80 and 443: stop it (an earlier web server or Panel?) and run this again." + done + ok "Ports 80 and 443 are free${ports_note:-}" + + # DNS: Let's Encrypt can only issue a certificate if the domain reaches this server. + $check_dns || info "DNS check skipped (--skip-dns-check)." + $check_dns && public_ip="$(curl -4 -fsS --max-time 5 https://ipv4.icanhazip.com 2>/dev/null | tr -d '[:space:]' || true)" + for name in "$domain" ${wings_domain:+"$wings_domain"}; do + $check_dns || break + resolved="$(getent ahostsv4 "$name" 2>/dev/null | awk '{print $1; exit}' || true)" + if [[ -z "$resolved" ]]; then + warn "$name doesn't resolve yet. Point an A record at ${public_ip:-this server} first, or the certificate can't be issued." + confirm "Continue anyway?" "n" || die "Stopped: set up DNS for $name and run this again (or pass --skip-dns-check)." + elif [[ -n "$public_ip" && "$resolved" != "$public_ip" ]]; then + warn "$name points at $resolved, but this server's public address is $public_ip." + warn "Behind a proxy or NAT that can be fine; a CDN proxy (Cloudflare's orange cloud) breaks the certificate." + confirm "Continue anyway?" "n" || die "Stopped: point $name at $public_ip and run this again (or pass --skip-dns-check)." + else + ok "$name points at this server" + fi + done +fi + +# ---- Docker -------------------------------------------------------------------------------- +step "Docker" +if command -v docker >/dev/null 2>&1 && ! $dry_run; then + ok "Docker $(docker version --format '{{.Server.Version}}' 2>/dev/null || echo '(not running)') is installed" +else + if $dry_run; then + info "If Docker is missing, it's installed with Docker's script (see the docs: getting-started)." + else + info "Installing Docker CE with Docker's script (see the docs: getting-started)." + fi + if $dry_run; then + printf ' %s$ curl -fsSL https://get.docker.com | CHANNEL=stable sh%s\n' "$dim" "$reset" + else + curl -fsSL https://get.docker.com | CHANNEL=stable sh + fi +fi +quietly systemctl enable --now docker + +# ---- Swarm --------------------------------------------------------------------------------- +step "Docker Swarm" +swarm_state="inactive" +$dry_run || swarm_state="$(docker info --format '{{.Swarm.LocalNodeState}}' 2>/dev/null || echo inactive)" +if [[ "$swarm_state" == active ]]; then + ok "This server is already in a swarm: using it" + gw_subnet="$(docker network inspect docker_gwbridge --format '{{(index .IPAM.Config 0).Subnet}}' 2>/dev/null || true)" + if [[ "$with_wings" == yes && "$gw_subnet" == 172.18.* ]]; then + warn "docker_gwbridge uses $gw_subnet, which Wings' network (pelican_nw, 172.18.0.0/16) also wants." + warn "Give Wings another subnet in /etc/pelican/config.yml (docker.network.interface and subnet) before starting it." + fi +else + # docker_gwbridge has to exist before "swarm init", or Docker gives it 172.18.0.0/16 (Wings'). + if $dry_run || ! docker network inspect docker_gwbridge >/dev/null 2>&1; then + quietly docker network create --subnet "$GWBRIDGE_SUBNET" \ + --opt com.docker.network.bridge.name=docker_gwbridge \ + --opt com.docker.network.bridge.enable_icc=false \ + --opt com.docker.network.bridge.enable_ip_masquerade=true \ + docker_gwbridge + fi + advertise="" + $dry_run || advertise="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for (i = 1; i < NF; i++) if ($i == "src") print $(i + 1)}' | head -1)" + # Quietly: its output holds the swarm's join token, which doesn't belong in a log. + quietly docker swarm init --advertise-addr "${advertise:-127.0.0.1}" \ + --default-addr-pool "$SWARM_POOL" --default-addr-pool-mask-length 24 + $dry_run || ok "Swarm started" +fi + +# Everything runs on this node, next to its data (the volumes are local), even in a bigger swarm. +node_id="this-node" +$dry_run || node_id="$(docker info --format '{{.Swarm.NodeID}}')" + +gw_ip="${GWBRIDGE_SUBNET%.*}.1" +if ! $dry_run; then + gw_ip="$(docker network inspect docker_gwbridge --format '{{(index .IPAM.Config 0).Gateway}}' 2>/dev/null || echo "$gw_ip")" +fi + +# ---- Files --------------------------------------------------------------------------------- +step "Writing $dir" +umask 077 +mkdir -p "$dir/traefik" + +{ + echo "# Pelican stack settings, written by pelican.dev/install.sh (v$VERSION)." + echo "# Change a value, then run ./deploy.sh to apply it. Keep this file private and backed" + echo "# up: APP_KEY decrypts your Panel's data, and nothing can recover it if it's lost." + echo "PROFILE='$profile'" + echo "PANEL_DOMAIN='$domain'" + echo "LE_EMAIL='$email'" + echo "LE_CA_SERVER='$le_server'" + echo "PANEL_IMAGE='$panel_image'" + echo "TRAEFIK_IMAGE='$(setting TRAEFIK_IMAGE | grep . || echo "$TRAEFIK_IMAGE_DEFAULT")'" + echo "PUBLIC_SUBNET='$PUBLIC_SUBNET'" + echo "SWARM_NODE_ID='$node_id'" + echo "APP_KEY='$app_key'" + if [[ "$profile" == production ]]; then + echo "DB_PASSWORD='$db_password'" + echo "DB_ROOT_PASSWORD='$db_root_password'" + fi + echo "WINGS_DOMAIN='$wings_domain'" + echo "WINGS_UPSTREAM='$(setting WINGS_UPSTREAM | grep . || echo "http://$gw_ip:8080")'" +} >"$env_file" +chmod 600 "$env_file" +ok "pelican.env (settings, keys and passwords; readable by root only)" + +# The stack. Values come from pelican.env through deploy.sh, so it never holds a secret itself. +cat >"$dir/stack.yml" <<'YAML' +# The Pelican stack, written by pelican.dev/install.sh. Deploy it with ./deploy.sh, which reads +# the ${...} values from pelican.env. Docs: https://pelican.dev/docs/panel/install/ +services: + traefik: + image: ${TRAEFIK_IMAGE} + command: + - --providers.swarm.endpoint=unix:///var/run/docker.sock + - --providers.swarm.exposedByDefault=false + - --providers.swarm.network=pelican_public + - --providers.file.directory=/etc/traefik/dynamic + - --providers.file.watch=true + - --entryPoints.web.address=:80 + - --entryPoints.web.http.redirections.entryPoint.to=websecure + - --entryPoints.web.http.redirections.entryPoint.scheme=https + - --entryPoints.websecure.address=:443 + - --entryPoints.websecure.http.tls.certResolver=letsencrypt + # Uploads to the Panel and to Wings can take longer than Traefik's 60 second default. + - --entryPoints.websecure.transport.respondingTimeouts.readTimeout=600s + - --certificatesResolvers.letsencrypt.acme.email=${LE_EMAIL} + - --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/acme.json + - --certificatesResolvers.letsencrypt.acme.caServer=${LE_CA_SERVER} + - --certificatesResolvers.letsencrypt.acme.httpChallenge.entryPoint=web + - --ping=true + - --log.level=INFO + ports: + # "host" mode keeps visitors' real IP addresses (Swarm's routing mesh would hide them). + - { target: 80, published: 80, protocol: tcp, mode: host } + - { target: 443, published: 443, protocol: tcp, mode: host } + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - letsencrypt:/letsencrypt + - ${PELICAN_DIR}/traefik:/etc/traefik/dynamic:ro + networks: + - public + healthcheck: + test: ["CMD", "traefik", "healthcheck", "--ping"] + interval: 30s + timeout: 5s + retries: 3 + deploy: + placement: + constraints: + - node.role == manager + - "node.id == ${SWARM_NODE_ID}" + restart_policy: + condition: any + + panel: + image: ${PANEL_IMAGE} + environment: + APP_URL: "https://${PANEL_DOMAIN}" + APP_KEY: "${APP_KEY}" + APP_ENV: production + APP_DEBUG: "false" + XDG_DATA_HOME: /pelican-data + # Traefik terminates HTTPS and forwards from the public network. + BEHIND_PROXY: "true" + TRUSTED_PROXIES: "${PUBLIC_SUBNET}" +#PRODUCTION_ENV + volumes: + - pelican-data:/pelican-data + - pelican-logs:/var/www/html/storage/logs + - pelican-plugins:/var/www/html/plugins + networks: + - public +#PRODUCTION_NETWORK + deploy: + replicas: 1 + placement: + constraints: + - "node.id == ${SWARM_NODE_ID}" + update_config: + order: stop-first + restart_policy: + condition: any + labels: + traefik.enable: "true" + traefik.http.routers.pelican-panel.rule: "Host(`${PANEL_DOMAIN}`)" + traefik.http.routers.pelican-panel.entrypoints: websecure + traefik.http.routers.pelican-panel.tls.certresolver: letsencrypt + traefik.http.services.pelican-panel.loadbalancer.server.port: "80" +#PRODUCTION_SERVICES + +volumes: + letsencrypt: + pelican-data: + pelican-logs: + pelican-plugins: +#PRODUCTION_VOLUMES + +networks: + public: + driver: overlay + ipam: + config: + - subnet: ${PUBLIC_SUBNET} +#PRODUCTION_NETWORKS +YAML + +# The production profile's parts, put in where the markers are (or the markers dropped). +# The ${...} in them are for docker stack deploy to fill in, not the shell. +# shellcheck disable=SC2016 +production_env=' DB_CONNECTION: mariadb + DB_HOST: database + DB_PORT: "3306" + DB_DATABASE: panel + DB_USERNAME: pelican + DB_PASSWORD: "${DB_PASSWORD}" + CACHE_STORE: redis + SESSION_DRIVER: redis + QUEUE_CONNECTION: redis + REDIS_HOST: cache' +production_network=' - internal' +# shellcheck disable=SC2016 +production_services=' + database: + image: mariadb:11.4 + environment: + MARIADB_DATABASE: panel + MARIADB_USER: pelican + MARIADB_PASSWORD: "${DB_PASSWORD}" + MARIADB_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}" + MARIADB_AUTO_UPGRADE: "1" + volumes: + - pelican-db:/var/lib/mysql + networks: + - internal + healthcheck: + test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + interval: 10s + timeout: 5s + retries: 10 + deploy: + placement: + constraints: + - "node.id == ${SWARM_NODE_ID}" + restart_policy: + condition: any + + cache: + image: redis:7-alpine + command: ["redis-server", "--appendonly", "yes"] + volumes: + - pelican-redis:/data + networks: + - internal + deploy: + placement: + constraints: + - "node.id == ${SWARM_NODE_ID}" + restart_policy: + condition: any' +production_volumes=' pelican-db: + pelican-redis:' +production_networks=' internal: + driver: overlay + internal: true' + +fill() { + local marker="$1" text="$2" file="$dir/stack.yml" out="" + local line + while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" == "#$marker" ]]; then + [[ "$profile" == production ]] && out+="$text"$'\n' + else + out+="$line"$'\n' + fi + done <"$file" + printf '%s' "$out" >"$file" +} +fill PRODUCTION_ENV "$production_env" +fill PRODUCTION_NETWORK "$production_network" +fill PRODUCTION_SERVICES "$production_services" +fill PRODUCTION_VOLUMES "$production_volumes" +fill PRODUCTION_NETWORKS "$production_networks" +chmod 644 "$dir/stack.yml" +ok "stack.yml (the services: Traefik, the Panel$([[ "$profile" == production ]] && echo ", MariaDB, Redis"))" + +cat >"$dir/deploy.sh" <<'DEPLOY' +#!/bin/bash +# Applies pelican.env and stack.yml to the running stack: run it after changing either. +# Written by pelican.dev/install.sh. It also updates the Panel when a new image is out +# (docker stack deploy checks the registry for each image tag). +set -Eeuo pipefail +cd "$(dirname "$0")" + +set -a +# shellcheck disable=SC1091 +. ./pelican.env +set +a +export PELICAN_DIR="$PWD" + +# Wings on this server: Traefik routes its domain to Wings on the host (file provider). +if [[ -n "${WINGS_DOMAIN:-}" ]]; then + cat >traefik/wings.yml </dev/null | grep -q -- '--detach'; then detach=(--detach=true); fi +docker stack deploy "${detach[@]}" --compose-file stack.yml pelican +DEPLOY +chmod 700 "$dir/deploy.sh" +ok "deploy.sh (applies changes; run it after editing pelican.env)" + +# ---- Wings --------------------------------------------------------------------------------- +if [[ "$with_wings" == yes ]]; then + step "Wings" + wings_arch="${arch:-amd64}" + run mkdir -p /etc/pelican /var/run/wings + run curl -fsSL -o /usr/local/bin/wings "$WINGS_RELEASES/wings_linux_$wings_arch" + run chmod u+x /usr/local/bin/wings + if $dry_run; then + info "Would write /etc/systemd/system/wings.service (the unit from the docs: wings/install)." + else + cat >/etc/systemd/system/wings.service <<'UNIT' +[Unit] +Description=Wings Daemon +After=docker.service +Requires=docker.service +PartOf=docker.service + +[Service] +User=root +WorkingDirectory=/etc/pelican +LimitNOFILE=4096 +PIDFile=/var/run/wings/daemon.pid +ExecStart=/usr/local/bin/wings +Restart=on-failure +StartLimitInterval=180 +StartLimitBurst=30 +RestartSec=5s + +[Install] +WantedBy=multi-user.target +UNIT + ok "$(/usr/local/bin/wings version 2>/dev/null | head -1 | grep . || echo Wings) and its service are installed" + fi + # Started once it has a configuration from the Panel (see the summary below). + quietly systemctl daemon-reload + quietly systemctl enable wings +fi + +# ---- Firewall ------------------------------------------------------------------------------ +if ! $dry_run && command -v ufw >/dev/null 2>&1 && ufw status 2>/dev/null | grep -q '^Status: active'; then + step "Firewall (ufw)" + ufw allow 80/tcp >/dev/null + ufw allow 443/tcp >/dev/null + if [[ "$with_wings" == yes ]]; then + ufw allow 2022/tcp >/dev/null # SFTP + # Traefik reaches Wings over docker_gwbridge. + ufw allow in on docker_gwbridge to any port 8080 proto tcp >/dev/null + fi + ok "Allowed 80 and 443$([[ "$with_wings" == yes ]] && echo ", 2022 (SFTP) and Traefik to Wings on 8080")" +fi + +# ---- Deploy -------------------------------------------------------------------------------- +step "Starting the stack" +run "$dir/deploy.sh" + +if ! $dry_run; then + info "Waiting for the Panel and its certificate (the first start runs for a minute or two)..." + ready=false + check=(curl -fsS --max-time 5 -o /dev/null) + $staging && check+=(-k) # the staging certificate isn't trusted, by design + for _ in $(seq 1 60); do + if "${check[@]}" "https://$domain/up" 2>/dev/null; then + ready=true + break + fi + sleep 5 + done + if $ready; then + ok "https://$domain answers$($staging || echo ", with a valid certificate")" + elif curl -kfsS --max-time 5 -o /dev/null --resolve "$domain:443:127.0.0.1" "https://$domain/up" 2>/dev/null; then + warn "The Panel runs, but the certificate isn't there yet. Check: docker service logs ${STACK}_traefik 2>&1 | grep -i acme" + else + warn "The Panel hasn't answered yet. Check: docker service ps ${STACK}_panel --no-trunc and docker service logs ${STACK}_panel" + fi +fi + +# ---- Summary ------------------------------------------------------------------------------- +step "Done" +info "Finish the setup in your browser: https://$domain/installer" +[[ "$profile" == production ]] && info "(The database and cache are ready: MariaDB and Redis.)" +cat < Nodes > Create, with FQDN $wings_domain, SSL (HTTPS), + "Behind Proxy", port 443 for the Panel to connect to and 8080 for Wings to listen on. + 2. Copy the node's configuration to /etc/pelican/config.yml (or run its Auto Deploy + command). Traefik handles HTTPS, so in that file api.port is 8080 and + api.ssl.enabled is false. Then: systemctl start wings + 3. Players' SFTP uses port 2022, and game servers the ports you allocate: open them + in your provider's firewall too. +EOF +fi +if $dry_run; then + printf '\n %sDry run: nothing changed. The files are in %s.%s\n' "$bold" "$dir" "$reset" +fi diff --git a/router/README.md b/router/README.md index 54bb62a1..0b55f4c9 100644 --- a/router/README.md +++ b/router/README.md @@ -41,7 +41,7 @@ resolved (`/docs/%2e%2e/x` is `/x`), but not decoded (`/docs%2Fx` is one segment | `/docs/_next/*` | `out/_next/*` (assetPrefix `/docs`; the export still writes to `out/_next/`) | | `/docs/.md` | `out/docs/md/.md`, only when no file matched first | | `/llms.txt`, `/llms-full.txt` | `out/` | -| `/update-panel.sh`, `/migrate-panel.sh`, `/migrate-wings.sh` | `out/` (the docs tell people to `curl` them) | +| `/install.sh`, `/update-panel.sh`, `/migrate-panel.sh`, `/migrate-wings.sh` | `out/` (the docs tell people to `curl` them) | Everything else goes to the Hub. `scripts/check-paths.mjs` checks the build against this list after every build. It fails when a file lands outside `out/docs/` diff --git a/router/paths.mjs b/router/paths.mjs index 3c826f86..5377680c 100644 --- a/router/paths.mjs +++ b/router/paths.mjs @@ -11,7 +11,7 @@ */ /** Files served at pelican.dev's root from this build (out/). The Hub has the same list. */ -export const ROOT_FILES = ['llms.txt', 'llms-full.txt', 'update-panel.sh', 'migrate-panel.sh', 'migrate-wings.sh']; +export const ROOT_FILES = ['llms.txt', 'llms-full.txt', 'install.sh', 'update-panel.sh', 'migrate-panel.sh', 'migrate-wings.sh']; /** * Whether a URL path is this build's to answer. Pass `new URL(...).pathname`: already free of diff --git a/scripts/README.md b/scripts/README.md index 93545009..09570d74 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -29,6 +29,7 @@ run and change one without reading the others first: | `sync-eggs.mjs` | Refreshes the egg data for the interim `/eggs` page and the homepage games strip. Uses the network and rewrites `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/` | Before every build (`--if-online`: no network keeps the saved data; a bug still fails); by hand | `bun run sync:eggs` | `sync-eggs.test.mjs` | | `check-paths.mjs` | Fails if the build puts a file where pelican.dev won't serve it from this build, misses a root file, or a docs page loads something from outside `/docs/` | After every build, and in CI | `bun run check:paths` | `check-paths.test.mjs` | | `pack-docs.mjs` | Packs `out/` into the folder the Hub serves on pelican.dev (docs, root files, 404 page, redirects) | Before every publish, in CI ("Publish docs build"); by hand to look at the result | `bun run pack:docs` | `pack-docs.test.mjs` | +| `../public/install.sh` | pelican.dev/install.sh: installs Docker, a one-node Swarm, Traefik (Let's Encrypt) and the Panel, optionally Wings. A bash script for servers, not a Bun one; the tests run it in `--dry-run` | Run by people on their servers (`curl … \| sudo bash`) | `bash public/install.sh --dry-run --help` | `install-sh.test.mjs` | | `../router/paths.mjs` | Which paths are this build's: `/docs/*` and the root files | Imported by the scripts above and the router | (nothing to run) | `router/paths.test.mjs` | | `../router/dev-server.mjs` | Shows pelican.dev as one site on your machine (docs from `out/`, the rest from a local Hub) | By hand | `bun run dev:site` | `router/dev-server.test.mjs` | | `../router/worker.mjs` | The Cloudflare Worker option for later (not deployed) | Not deployed | see `router/README.md` | `router/worker.test.mjs` | diff --git a/scripts/install-sh.test.mjs b/scripts/install-sh.test.mjs new file mode 100644 index 00000000..9c1700e3 --- /dev/null +++ b/scripts/install-sh.test.mjs @@ -0,0 +1,251 @@ +// bun test scripts/install-sh.test.mjs +// public/install.sh (pelican.dev/install.sh), run for real in --dry-run: the options and their +// errors, the files it writes (pelican.env, stack.yml, deploy.sh) for each profile, that a second +// run keeps the keys and passwords, and what deploy.sh hands to `docker stack deploy` (with a +// stub docker). Also shellcheck, when it's installed. The script lives in public/ (served as it +// is), so its test lives here. +import { describe, expect, test } from 'bun:test'; +import { chmodSync, existsSync, mkdtempSync, readFileSync, statSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { parse } from 'yaml'; + +const SCRIPT = join(import.meta.dir, '..', 'public', 'install.sh'); + +/** A bash of version 4 or newer (the script's servers have 5; macOS ships 3.2 as /bin/bash). */ +function findBash() { + for (const bash of ['/opt/homebrew/bin/bash', '/usr/local/bin/bash', '/usr/bin/bash', '/bin/bash', Bun.which('bash')]) { + if (!bash || !existsSync(bash)) continue; + const { stdout } = Bun.spawnSync([bash, '-c', 'echo ${BASH_VERSINFO[0]}']); + if (Number(stdout.toString().trim()) >= 4) return bash; + } + return null; +} + +const BASH = findBash(); +const suite = BASH ? describe : describe.skip; + +function install(args, env = {}) { + const result = Bun.spawnSync([BASH, SCRIPT, ...args], { + env: { PATH: process.env.PATH, HOME: process.env.HOME, ...env }, + stdin: 'ignore', + }); + return { code: result.exitCode, out: result.stdout.toString() + result.stderr.toString() }; +} + +function dryRun(extra = [], dir = mkdtempSync(join(tmpdir(), 'pelican-install-'))) { + const result = install(['--dry-run', '--yes', '--dir', dir, ...extra]); + return { ...result, dir }; +} + +const BASE = ['--domain', 'panel.example.com', '--email', 'admin@pelican.test']; + +/** pelican.env as an object (KEY='value' lines). */ +function settings(dir) { + const values = {}; + for (const line of readFileSync(join(dir, 'pelican.env'), 'utf8').split('\n')) { + const match = line.match(/^([A-Z_][A-Z0-9_]*)='(.*)'$/); + if (match) values[match[1]] = match[2]; + } + return values; +} + +const stack = (dir) => parse(readFileSync(join(dir, 'stack.yml'), 'utf8')); + +suite('install.sh options', () => { + test('--help lists the options and exits 0', () => { + const { code, out } = install(['--help']); + expect(code).toBe(0); + for (const flag of ['--domain', '--email', '--profile', '--wings', '--wings-domain', '--dry-run', '--yes', '--staging']) { + expect(out).toContain(flag); + } + }); + + test('an unknown option fails with exit 2', () => { + expect(install(['--nope']).code).toBe(2); + }); + + test('--yes needs --domain and --email, and says so', () => { + expect(dryRun(['--email', 'admin@pelican.test']).out).toContain('--domain is needed with --yes'); + expect(dryRun(['--domain', 'panel.example.com']).out).toContain('--email is needed with --yes'); + }); + + test('bad values are refused before anything is written', () => { + const domain = dryRun(['--domain', 'not a domain', '--email', 'admin@pelican.test']); + expect(domain.code).not.toBe(0); + expect(domain.out).toContain("isn't a domain name"); + expect(existsSync(join(domain.dir, 'pelican.env'))).toBe(false); + + expect(dryRun(['--domain', 'panel.example.com', '--email', "o'brien@example.com"]).out).toContain("isn't an email"); + expect(dryRun([...BASE, '--profile', 'enterprise']).out).toContain('--profile is quick or production'); + // Let's Encrypt refuses contacts at example.com (seen on a real run), so it's caught up front. + expect(dryRun(['--domain', 'panel.example.com', '--email', 'admin@example.com']).out).toContain("Let's Encrypt refuses addresses at example.com"); + }); + + test('--wings needs its own --wings-domain', () => { + expect(dryRun([...BASE, '--wings']).out).toContain('--wings-domain is needed'); + expect(dryRun([...BASE, '--wings', '--wings-domain', 'panel.example.com']).out).toContain('Wings needs its own domain'); + }); + + test('without a terminal and without --yes it asks for --yes instead of guessing', () => { + const { code, out } = install(['--dry-run', ...BASE]); + expect(code).not.toBe(0); + expect(out).toContain('No terminal for questions'); + }); +}); + +suite('install.sh files', () => { + test('quick: Traefik and the Panel, nothing else; secrets stay in pelican.env', () => { + const { code, out, dir } = dryRun(BASE); + expect(code).toBe(0); + expect(out).toContain('Dry run: nothing changed'); + + const env = settings(dir); + expect(env.PROFILE).toBe('quick'); + expect(env.PANEL_DOMAIN).toBe('panel.example.com'); + expect(env.APP_KEY).toMatch(/^base64:[A-Za-z0-9+/]{43}=$/); + expect(env.DB_PASSWORD).toBeUndefined(); + expect(statSync(join(dir, 'pelican.env')).mode & 0o777).toBe(0o600); + expect(out).not.toContain(env.APP_KEY); + + const file = stack(dir); + expect(Object.keys(file.services).sort()).toEqual(['panel', 'traefik']); + expect(readFileSync(join(dir, 'stack.yml'), 'utf8')).not.toContain('#PRODUCTION'); + + // Traefik: real client IPs (host mode), redirect to HTTPS, Let's Encrypt from pelican.env. + const traefik = file.services.traefik; + expect(traefik.ports).toEqual([ + { target: 80, published: 80, protocol: 'tcp', mode: 'host' }, + { target: 443, published: 443, protocol: 'tcp', mode: 'host' }, + ]); + expect(traefik.command).toContain('--providers.swarm.network=pelican_public'); + expect(traefik.command).toContain('--entryPoints.web.http.redirections.entryPoint.to=websecure'); + expect(traefik.command).toContain('--certificatesResolvers.letsencrypt.acme.caServer=${LE_CA_SERVER}'); + expect(traefik.deploy.placement.constraints).toContain('node.id == ${SWARM_NODE_ID}'); + + // The Panel: behind Traefik, trusting only the public network it shares with Traefik. + const panel = file.services.panel; + expect(panel.environment).toMatchObject({ + APP_URL: 'https://${PANEL_DOMAIN}', + APP_KEY: '${APP_KEY}', + BEHIND_PROXY: 'true', + TRUSTED_PROXIES: '${PUBLIC_SUBNET}', + }); + expect(panel.environment.DB_CONNECTION).toBeUndefined(); + expect(panel.volumes).toContain('pelican-plugins:/var/www/html/plugins'); + expect(panel.deploy.labels['traefik.http.routers.pelican-panel.rule']).toBe('Host(`${PANEL_DOMAIN}`)'); + expect(panel.deploy.labels['traefik.http.services.pelican-panel.loadbalancer.server.port']).toBe('80'); + expect(file.networks.public.ipam.config[0].subnet).toBe('${PUBLIC_SUBNET}'); + expect(env.PUBLIC_SUBNET).toBe('10.203.250.0/24'); + }); + + test('production: MariaDB and Redis on an internal network, with generated passwords', () => { + const { code, dir } = dryRun([...BASE, '--profile', 'production']); + expect(code).toBe(0); + const env = settings(dir); + expect(env.DB_PASSWORD).toMatch(/^[A-Za-z0-9]{32}$/); + expect(env.DB_ROOT_PASSWORD).toMatch(/^[A-Za-z0-9]{32}$/); + expect(env.DB_PASSWORD).not.toBe(env.DB_ROOT_PASSWORD); + + const file = stack(dir); + expect(Object.keys(file.services).sort()).toEqual(['cache', 'database', 'panel', 'traefik']); + expect(file.services.panel.environment).toMatchObject({ + DB_CONNECTION: 'mariadb', + DB_HOST: 'database', + DB_PASSWORD: '${DB_PASSWORD}', + CACHE_STORE: 'redis', + SESSION_DRIVER: 'redis', + QUEUE_CONNECTION: 'redis', + REDIS_HOST: 'cache', + }); + expect(file.services.panel.networks).toEqual(['public', 'internal']); + expect(file.services.database.networks).toEqual(['internal']); + expect(file.services.database.environment.MARIADB_PASSWORD).toBe('${DB_PASSWORD}'); + expect(file.networks.internal).toEqual({ driver: 'overlay', internal: true }); + expect(Object.keys(file.volumes)).toEqual(expect.arrayContaining(['pelican-db', 'pelican-redis'])); + }); + + test('a second run keeps APP_KEY and the passwords, and refuses to switch profiles', () => { + const first = dryRun([...BASE, '--profile', 'production']); + const before = settings(first.dir); + const again = dryRun([], first.dir); // everything comes from pelican.env + expect(again.code).toBe(0); + expect(again.out).toContain('keeping its keys and passwords'); + const after = settings(first.dir); + expect(after.APP_KEY).toBe(before.APP_KEY); + expect(after.DB_PASSWORD).toBe(before.DB_PASSWORD); + expect(after.DB_ROOT_PASSWORD).toBe(before.DB_ROOT_PASSWORD); + + const switched = dryRun(['--profile', 'quick'], first.dir); + expect(switched.code).not.toBe(0); + expect(switched.out).toContain('uses the production profile'); + }); + + test("--staging uses Let's Encrypt staging", () => { + const { dir } = dryRun([...BASE, '--staging']); + expect(settings(dir).LE_CA_SERVER).toBe('https://acme-staging-v02.api.letsencrypt.org/directory'); + }); + + test('the address ranges can be changed for networks that clash', () => { + const dir = mkdtempSync(join(tmpdir(), 'pelican-install-')); + const result = install(['--dry-run', '--yes', '--dir', dir, ...BASE], { + PELICAN_PUBLIC_SUBNET: '10.99.1.0/24', + PELICAN_GWBRIDGE_SUBNET: '10.99.2.0/24', + }); + expect(result.code).toBe(0); + expect(settings(dir).PUBLIC_SUBNET).toBe('10.99.1.0/24'); + expect(settings(dir).WINGS_UPSTREAM).toBe('http://10.99.2.1:8080'); + expect(result.out).toContain('--subnet 10.99.2.0/24'); + }); +}); + +suite('deploy.sh', () => { + /** Runs deploy.sh with a stub docker that records its arguments and environment. */ + function deploy(dir) { + const bin = mkdtempSync(join(tmpdir(), 'pelican-bin-')); + const record = join(bin, 'calls'); + writeFileSync( + join(bin, 'docker'), + `#!/bin/sh\n{ echo "ARGS $*"; echo "PANEL_DOMAIN=$PANEL_DOMAIN"; echo "PELICAN_DIR=$PELICAN_DIR"; echo "APP_KEY_SET=\${APP_KEY:+yes}"; } >> "${record}"\n`, + ); + chmodSync(join(bin, 'docker'), 0o755); + const result = Bun.spawnSync([BASH, join(dir, 'deploy.sh')], { env: { PATH: `${bin}:${process.env.PATH}` } }); + return { code: result.exitCode, calls: existsSync(record) ? readFileSync(record, 'utf8') : '' }; + } + + test('deploys the stack with pelican.env exported, and no Wings route without Wings', () => { + const { dir } = dryRun(BASE); + const { code, calls } = deploy(dir); + expect(code).toBe(0); + expect(calls).toMatch(/ARGS stack deploy (--detach=true )?--compose-file stack\.yml pelican/); + expect(calls).toContain('PANEL_DOMAIN=panel.example.com'); + expect(calls).toContain(`PELICAN_DIR=${dir}`); + expect(calls).toContain('APP_KEY_SET=yes'); + expect(existsSync(join(dir, 'traefik', 'wings.yml'))).toBe(false); + }); + + test('with Wings, it writes the Traefik route to Wings on the host', () => { + const { dir } = dryRun([...BASE, '--wings', '--wings-domain', 'node.example.com']); + expect(settings(dir).WINGS_DOMAIN).toBe('node.example.com'); + expect(deploy(dir).code).toBe(0); + + const route = parse(readFileSync(join(dir, 'traefik', 'wings.yml'), 'utf8')); + expect(route.http.routers['pelican-wings']).toEqual({ + rule: 'Host(`node.example.com`)', + entryPoints: ['websecure'], + service: 'pelican-wings', + tls: { certResolver: 'letsencrypt' }, + }); + expect(route.http.services['pelican-wings'].loadBalancer.servers).toEqual([{ url: 'http://10.204.0.1:8080' }]); + }); +}); + +const shellcheck = Bun.which('shellcheck'); +(shellcheck && BASH ? test : test.skip)('shellcheck finds nothing in install.sh or the deploy.sh it writes', () => { + const { dir } = dryRun(BASE); + for (const file of [SCRIPT, join(dir, 'deploy.sh')]) { + const result = Bun.spawnSync([shellcheck, '-s', 'bash', file]); + expect(result.stdout.toString()).toBe(''); + expect(result.exitCode).toBe(0); + } +}); From 5cde266553803d16c600d9da2f21f5c34881a227 Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:07:10 +0200 Subject: [PATCH 2/5] docs: Docker first, as in #226, with the install script Ports pelican/docs#226 (Lance) to the Fumadocs site: - guides/docker becomes the top-level Getting Started (requirements, the virtualization check, Docker, swap), now opening with the one-command install. - panel/advanced/docker becomes panel/install, the recommended install: the install script (profiles, options, files, changing settings, updating, Wings on the same server, troubleshooting, backups) and then Docker Compose by hand, with #226's plugins volume and the note on the old ghcr.io/pelican-dev path. - The install without Docker moves to panel/standalone/*. - Redirects for the six old paths (netlify.toml, which the Hub's redirects.json is built from), inbound links, the sidebar, the OG motifs, ui/nav.json. - The AI guide's recommended prompt now drives the install script (asks the questions, writes the command, dry run first); the old prompt becomes the "Standalone install" tab. --- content/docs/getting-started.mdx | 90 ++++ content/docs/guides/ai-assistant.mdx | 107 +++-- content/docs/guides/docker.mdx | 43 -- content/docs/guides/meta.json | 1 - .../guides/migrating-from-pterodactyl.mdx | 10 +- content/docs/guides/ssl.mdx | 2 +- content/docs/guides/troubleshooting.mdx | 2 +- content/docs/meta.json | 1 + .../docs/panel/advanced/cloudflare-tunnel.mdx | 8 +- content/docs/panel/advanced/docker.mdx | 237 ----------- content/docs/panel/advanced/meta.json | 10 +- content/docs/panel/advanced/podman.mdx | 6 +- content/docs/panel/install.mdx | 392 ++++++++++++++++++ content/docs/panel/meta.json | 6 +- .../{ => standalone}/getting-started.mdx | 10 +- content/docs/panel/standalone/meta.json | 9 + .../{ => standalone}/optional-config.mdx | 0 .../panel/{ => standalone}/panel-setup.mdx | 4 +- .../{ => standalone}/webserver-config.mdx | 0 content/docs/panel/update.mdx | 4 +- content/docs/versioning.mdx | 2 +- content/docs/wings/install.mdx | 2 +- lib/og-motifs.ts | 23 +- netlify.toml | 41 +- ui/nav.json | 4 +- 25 files changed, 660 insertions(+), 354 deletions(-) create mode 100644 content/docs/getting-started.mdx delete mode 100644 content/docs/guides/docker.mdx delete mode 100644 content/docs/panel/advanced/docker.mdx create mode 100644 content/docs/panel/install.mdx rename content/docs/panel/{ => standalone}/getting-started.mdx (87%) create mode 100644 content/docs/panel/standalone/meta.json rename content/docs/panel/{ => standalone}/optional-config.mdx (100%) rename content/docs/panel/{ => standalone}/panel-setup.mdx (93%) rename content/docs/panel/{ => standalone}/webserver-config.mdx (100%) diff --git a/content/docs/getting-started.mdx b/content/docs/getting-started.mdx new file mode 100644 index 00000000..29c7e17d --- /dev/null +++ b/content/docs/getting-started.mdx @@ -0,0 +1,90 @@ +--- +title: "Getting Started" +description: "What a Pelican server needs, the one-command install, and getting Docker ready: requirements, the virtualization check, installing Docker, starting it on boot and enabling swap." +--- + +Pelican runs on a dedicated Linux server, and the recommended way to install it is with **Docker**. +The quickest way there is the install script below; this page also covers getting Docker ready yourself, if you'd rather [install the Panel](./panel/install) step by step. + + + **You should have some basic familiarity with Linux before you proceed!** + + + + You don't need a fresh install. Follow [Migrating from Pterodactyl](./guides/migrating-from-pterodactyl) to upgrade your existing Panel and keep all your data. + + +## Requirements + +Pelican runs on a wide range of operating systems, so pick whichever you are most comfortable using, +as long as it supports [Docker Engine](https://docs.docker.com/engine/install/). + +Docker may not work under `OpenVZ`, `Virtuozzo` or `LXC` virtualization unless your provider has configured it for nested containers. +`kvm` and bare metal (`none`) work without issues. To check what your server uses, run: + +```sh +systemd-detect-virt +``` + +If that command isn't available, `sudo dmidecode -s system-manufacturer` usually tells you as well. + +You also need a domain (or subdomain) for the Panel, such as `panel.example.com`, with an `A` record pointing at your server, so it can get an HTTPS certificate. + +## The quick way: one command + +On a fresh server, this installs Docker, sets up HTTPS with Let's Encrypt and starts the Panel. It asks for your domain and email, and whether you want the simple setup or the production one: + +```sh +curl -fsSL https://pelican.dev/install.sh | sudo bash +``` + +When it's done, open `https:///installer` to finish. [Installing the Panel](./panel/install#the-install-script) explains every option, what the script sets up and how to change it later. Want an AI assistant to walk you through it? See [Installing with an AI Assistant](./guides/ai-assistant). + +The rest of this page sets up Docker by hand, for the [Docker Compose install](./panel/install#docker-compose) or for [Wings](./wings/install). The script does all of it for you. + +## Installing Docker + +For a quick install of Docker CE, you can use the command below: + +```sh +curl -sSL https://get.docker.com/ | CHANNEL=stable sudo sh +``` + + + If the above command does not work, please refer to the [official Docker documentation](https://docs.docker.com/engine/install/) on how to install Docker CE on your server. + + +## Start Docker on Boot + +If you are on an operating system with systemd (Ubuntu 16+, Debian 8+, CentOS 7+) run the command below to have Docker start when you boot your machine. + +```sh +sudo systemctl enable --now docker +``` + +## Enabling Swap + +On most systems, Docker will be unable to setup swap space by default. You can confirm this by running `docker info` and looking for the output of `WARNING: No swap limit support` near the bottom. + +Enabling swap is entirely optional, but we recommended doing it if you will be hosting for others and to prevent OOM errors. + +To enable swap, open `/etc/default/grub` as a root user and find the line starting with `GRUB_CMDLINE_LINUX_DEFAULT`. Make +sure the line includes `swapaccount=1` somewhere inside the double-quotes. + +After that, run `sudo update-grub` followed by `sudo reboot` to restart the server and have swap enabled. +Below is an example of what the line should look like, _do not copy this line verbatim. It often has additional OS-specific parameters._ + +```text +GRUB_CMDLINE_LINUX_DEFAULT="swapaccount=1" +``` + + + Some Linux distros may ignore `GRUB_CMDLINE_LINUX_DEFAULT`. + Therefore you might have to use `GRUB_CMDLINE_LINUX` instead should the above variable not work for you. + + +## Next Steps + +Docker is ready. Continue to [Installing the Panel](./panel/install). + +Prefer to run the Panel directly on your server without Docker? Follow the [standalone install](./panel/standalone/getting-started) instead. diff --git a/content/docs/guides/ai-assistant.mdx b/content/docs/guides/ai-assistant.mdx index c2047ad4..f2575153 100644 --- a/content/docs/guides/ai-assistant.mdx +++ b/content/docs/guides/ai-assistant.mdx @@ -26,44 +26,46 @@ Assistants that can read the web can fetch these themselves: |:-----|:-----------| | `https://pelican.dev/llms.txt` | An index of every docs page, with links to their Markdown versions | | `https://pelican.dev/llms-full.txt` | Every docs page in one Markdown file | -| `https://pelican.dev/docs/.md` | One page as Markdown, e.g. `https://pelican.dev/docs/panel/getting-started.md` | +| `https://pelican.dev/docs/.md` | One page as Markdown, e.g. `https://pelican.dev/docs/getting-started.md` | ## Recommended prompt: a production install -Copy this into a new conversation. It makes the assistant ask about your server first, go one step at a time and finish with the things a production panel needs. +Copy this into a new conversation. The assistant asks what your install needs, picks the options for the [install script](/docs/panel/install#the-install-script), shows you the plan with a dry run and then walks you through the real run and the checks a production panel needs. -```text title="Prompt: install the Pelican Panel for production" wrap -You are helping me install the Pelican Panel (https://pelican.dev) on a production server. -Pelican is a fork of Pterodactyl, but its paths, commands and requirements are different: -follow only the Pelican documentation, never Pterodactyl's. +```text title="Prompt: install the Pelican Panel with the install script" wrap +You are helping me install the Pelican Panel (https://pelican.dev) on a production server, with its +official install script (Docker Swarm, Traefik with Let's Encrypt, the Panel). Pelican is a fork of +Pterodactyl, but its paths, commands and requirements are different: follow only the Pelican +documentation, never Pterodactyl's. Read these pages first and follow them exactly: - https://pelican.dev/llms.txt (an index of every docs page as Markdown) -- https://pelican.dev/docs/panel/getting-started.md -- https://pelican.dev/docs/panel/webserver-config.md -- https://pelican.dev/docs/panel/panel-setup.md -- https://pelican.dev/docs/guides/ssl.md - -Before any command, ask me: -1. The operating system and version (the output of `cat /etc/os-release`). -2. The panel's domain, and whether its DNS already points at this server. -3. Which web server I want: NGINX, Apache or Caddy. -4. Which database: SQLite (the default), MySQL/MariaDB or PostgreSQL. -5. Whether Wings will run on this server too, or on another one. - -Then guide me one step at a time: -- Give me one short block of commands, say what each line does, and wait for me to paste the output before you continue. -- Use the versions and commands from the docs: PHP 8.5 or 8.4 with the listed extensions, the panel in /var/www/pelican. -- Never ask me for passwords, API keys, the APP_KEY or other secrets. Tell me where to enter them myself. -- If something fails, ask for the exact error and the relevant log instead of guessing. +- https://pelican.dev/docs/getting-started.md +- https://pelican.dev/docs/panel/install.md (the section "The install script" lists every option) + +Before any command, ask me, one question at a time, and explain the choice in plain words: +1. The output of `cat /etc/os-release` and `systemd-detect-virt`, to check the server can run Docker. +2. The panel's domain, and whether its DNS A record already points at this server. +3. The email for Let's Encrypt (a real address: example.com addresses are refused). +4. Which profile: "quick" (SQLite, the least to run: one server, a small community) or "production" + (MariaDB and Redis: more users, servers and nodes). Recommend one from my answers. +5. Whether Wings should run on this same server, and if so its own domain (e.g. node.example.com). + +Then: +- Write the exact command with my answers as options and --yes, and explain each option. +- Have me run it with --dry-run first and paste the output, so we both see the plan. Only then the real run. +- Wait for me to paste the output of each step. If something fails, ask for the exact error and the + logs the docs name (docker service ls, docker service logs pelican_panel, pelican_traefik) instead of guessing. +- Never ask me for passwords, API keys, the APP_KEY or other secrets, and don't ask me to paste + /opt/pelican/pelican.env. Tell me where to look at them myself. This is a production server. Before we finish, check with me that: -- The panel is served over HTTPS, and the certificate renews automatically. -- The firewall only opens what is needed: SSH, 80 and 443 for the panel, and if Wings runs here, its port (8080), SFTP (2022) and the game server ports I plan to allocate. -- The queue worker (systemctl status pelican-queue) is running and the schedule:run cron entry from the docs is installed for the web server user. -- File permissions match the Panel Setup page. -- I have stored the APP_KEY from /var/www/pelican/.env somewhere safe, off the server. -- I know how to back up the panel and its database, and how to update it (https://pelican.dev/docs/panel/update.md). +- https:///installer opens with a valid certificate, and I created the admin account there. +- I copied /opt/pelican/pelican.env (it holds the APP_KEY) somewhere safe, off the server. +- My provider's firewall allows 80 and 443 (and 2022 plus my game server ports if Wings runs here). +- If Wings runs here: the node is created in the Panel as the docs describe, /etc/pelican/config.yml + is in place, and `systemctl status wings` is active. +- I know how to change settings (edit pelican.env, run deploy.sh), update and back up, as the page says. End with a short summary of what we installed and where each part lives. ``` @@ -71,10 +73,48 @@ End with a short summary of what we installed and where each part lives. ## More prompts + + ```text title="Prompt: install the Pelican Panel without Docker" wrap + You are helping me install the Pelican Panel (https://pelican.dev) on a production server, + directly on the server (the standalone install, without Docker). + Pelican is a fork of Pterodactyl, but its paths, commands and requirements are different: + follow only the Pelican documentation, never Pterodactyl's. + + Read these pages first and follow them exactly: + - https://pelican.dev/llms.txt (an index of every docs page as Markdown) + - https://pelican.dev/docs/panel/standalone/getting-started.md + - https://pelican.dev/docs/panel/standalone/webserver-config.md + - https://pelican.dev/docs/panel/standalone/panel-setup.md + - https://pelican.dev/docs/guides/ssl.md + + Before any command, ask me: + 1. The operating system and version (the output of `cat /etc/os-release`). + 2. The panel's domain, and whether its DNS already points at this server. + 3. Which web server I want: NGINX, Apache or Caddy. + 4. Which database: SQLite (the default), MySQL/MariaDB or PostgreSQL. + 5. Whether Wings will run on this server too, or on another one. + + Then guide me one step at a time: + - Give me one short block of commands, say what each line does, and wait for me to paste the output before you continue. + - Use the versions and commands from the docs: PHP 8.5 or 8.4 with the listed extensions, the panel in /var/www/pelican. + - Never ask me for passwords, API keys, the APP_KEY or other secrets. Tell me where to enter them myself. + - If something fails, ask for the exact error and the relevant log instead of guessing. + + This is a production server. Before we finish, check with me that: + - The panel is served over HTTPS, and the certificate renews automatically. + - The firewall only opens what is needed: SSH, 80 and 443 for the panel, and if Wings runs here, its port (8080), SFTP (2022) and the game server ports I plan to allocate. + - The queue worker (systemctl status pelican-queue) is running and the schedule:run cron entry from the docs is installed for the web server user. + - File permissions match the Panel Setup page. + - I have stored the APP_KEY from /var/www/pelican/.env somewhere safe, off the server. + - I know how to back up the panel and its database, and how to update it (https://pelican.dev/docs/panel/update.md). + + End with a short summary of what we installed and where each part lives. + ``` + ```text title="Prompt: install Wings and connect it to the panel" wrap Help me install Wings for the Pelican Panel, following only - https://pelican.dev/docs/wings/install.md and https://pelican.dev/docs/guides/docker.md. + https://pelican.dev/docs/wings/install.md and https://pelican.dev/docs/getting-started.md. First check with me that this server can run Docker: ask for the output of `systemd-detect-virt` and `uname -r` and compare them with the System Requirements section. @@ -94,7 +134,9 @@ End with a short summary of what we installed and where each part lives. What happens: Ask me for the output you need, one command at a time, from this list first: - - tail -n 100 /var/www/pelican/storage/logs/laravel-$(date +%F).log + - installed with the install script: docker service ls, then docker service logs pelican_panel + (and pelican_traefik for certificate problems) + - installed directly on the server: tail -n 100 /var/www/pelican/storage/logs/laravel-$(date +%F).log - systemctl status pelican-queue - systemctl status wings, or sudo wings --debug on the node - php -v @@ -105,7 +147,8 @@ End with a short summary of what we installed and where each part lives. ```text title="Prompt: update the panel safely" wrap Help me update my Pelican Panel, following https://pelican.dev/docs/panel/update.md. - Ask me how it was installed (Docker, or directly on the server) and which version runs now. + Ask me how it was installed (the install script, Docker Compose, or directly on the server) + and which version runs now. An install-script install updates with: sudo /opt/pelican/deploy.sh Before anything else, have me back up the panel folder, the database and the APP_KEY. Check the Version Requirements on that page for the PHP and Wings versions the new release needs. Prefer the update script the docs recommend, and go one step at a time, waiting for my output. diff --git a/content/docs/guides/docker.mdx b/content/docs/guides/docker.mdx deleted file mode 100644 index b53d8ac2..00000000 --- a/content/docs/guides/docker.mdx +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "Installing Docker" -description: "Install Docker CE with the official script, start it on boot with systemd and enable swap accounting through GRUB." ---- - -For a quick install of Docker CE, you can use the command below: - -```sh -curl -sSL https://get.docker.com/ | CHANNEL=stable sudo sh -``` - - - If the above command does not work, please refer to the [official Docker documentation](https://docs.docker.com/engine/install/) on how to install Docker CE on your server. - - -## Start Docker on Boot - -If you are on an operating system with systemd (Ubuntu 16+, Debian 8+, CentOS 7+) run the command below to have Docker start when you boot your machine. - -```sh -sudo systemctl enable --now docker -``` - -## Enabling Swap - -On most systems, Docker will be unable to setup swap space by default. You can confirm this by running `docker info` and looking for the output of `WARNING: No swap limit support` near the bottom. - -Enabling swap is entirely optional, but we recommended doing it if you will be hosting for others and to prevent OOM errors. - -To enable swap, open `/etc/default/grub` as a root user and find the line starting with `GRUB_CMDLINE_LINUX_DEFAULT`. Make -sure the line includes `swapaccount=1` somewhere inside the double-quotes. - -After that, run `sudo update-grub` followed by `sudo reboot` to restart the server and have swap enabled. -Below is an example of what the line should look like, _do not copy this line verbatim. It often has additional OS-specific parameters._ - -```text -GRUB_CMDLINE_LINUX_DEFAULT="swapaccount=1" -``` - - - Some Linux distros may ignore `GRUB_CMDLINE_LINUX_DEFAULT`. - Therefore you might have to use `GRUB_CMDLINE_LINUX` instead should the above variable not work for you. - \ No newline at end of file diff --git a/content/docs/guides/meta.json b/content/docs/guides/meta.json index cbe67833..fbaed9a5 100644 --- a/content/docs/guides/meta.json +++ b/content/docs/guides/meta.json @@ -2,7 +2,6 @@ "title": "Guides", "pages": [ "ai-assistant", - "docker", "mounts", "ssl", "php-upgrade", diff --git a/content/docs/guides/migrating-from-pterodactyl.mdx b/content/docs/guides/migrating-from-pterodactyl.mdx index a8e2366d..daeac678 100644 --- a/content/docs/guides/migrating-from-pterodactyl.mdx +++ b/content/docs/guides/migrating-from-pterodactyl.mdx @@ -14,7 +14,7 @@ Your game servers keep running and keep their files. ## Requirements - Pterodactyl 1.11.4 or newer. [Update Pterodactyl](https://docs.pterodactyl.io/v1/panel/updating) first if needed. -- The [Panel dependencies](../panel/getting-started#dependencies), including PHP 8.4 or newer with PHP-FPM. +- The [Panel dependencies](../panel/standalone/getting-started#dependencies), including PHP 8.4 or newer with PHP-FPM. ## Migrate the Panel @@ -35,7 +35,7 @@ Your game servers keep running and keep their files. It installs Pelican in `/var/www/pelican`, copies your `.env` and upgrades the database. It also sets up the queue worker and cron job. Your old install stays untouched in `/var/www/pterodactyl`. - Last, [point your webserver](../panel/webserver-config) at `/var/www/pelican/public` and disable the Pterodactyl site. + Last, [point your webserver](../panel/standalone/webserver-config) at `/var/www/pelican/public` and disable the Pterodactyl site. Take Pterodactyl offline first, so nothing writes to the database: @@ -48,7 +48,7 @@ Your game servers keep running and keep their files. Then remove the Pterodactyl `schedule:run` line from `sudo crontab -e`. - Create the `compose.yml` from the [Docker guide](../panel/advanced/docker#create-composeyml) and add these to its `environment`: + Create the `compose.yml` from the [Docker guide](../panel/install#create-composeyml) and add these to its `environment`: ```yml APP_INSTALLED: "true" # upgrade the database instead of opening the web installer @@ -113,7 +113,7 @@ grep '^DB_' .env mysqldump -h -P -u -p --single-transaction --no-tablespaces > ~/pterodactyl-backup.sql ``` -**Install Pelican.** Follow [Getting Started](../panel/getting-started) up to (and including) **Install Composer**, but don't run the web installer. Then copy your `.env` and upgrade the database. Make sure `.env` has `DB_CONNECTION=mysql`, or `DB_CONNECTION=mariadb` on MariaDB: Pterodactyl didn't need it, but without it Pelican falls back to SQLite. +**Install Pelican.** Follow the [Standalone Install](../panel/standalone/getting-started) up to (and including) **Install Composer**, but don't run the web installer. Then copy your `.env` and upgrade the database. Make sure `.env` has `DB_CONNECTION=mysql`, or `DB_CONNECTION=mariadb` on MariaDB: Pterodactyl didn't need it, but without it Pelican falls back to SQLite. ```sh sudo cp /var/www/pterodactyl/.env /var/www/pelican/.env @@ -124,7 +124,7 @@ sudo php artisan migrate --seed --force `HASHIDS_SALT`, `HASHIDS_LENGTH`, `APP_THEME` and `APP_ENVIRONMENT_ONLY` are no longer used and can be removed from `.env`. -**Finish the setup.** [Set permissions](../panel/panel-setup#setting-permissions) and [configure your webserver](../panel/webserver-config). Then set up the queue worker and cron job, and bring the Panel up: +**Finish the setup.** [Set permissions](../panel/standalone/panel-setup#setting-permissions) and [configure your webserver](../panel/standalone/webserver-config). Then set up the queue worker and cron job, and bring the Panel up: ```sh sudo php artisan p:environment:queue-service diff --git a/content/docs/guides/ssl.mdx b/content/docs/guides/ssl.mdx index 77079825..4f19a629 100644 --- a/content/docs/guides/ssl.mdx +++ b/content/docs/guides/ssl.mdx @@ -46,7 +46,7 @@ These tutorials briefly cover creating a new SSL certificates for your panel and command. You can also look into generating a wildcard certificate but that is not covered in this tutorial. When you are using certbot's Nginx/Apache plugin, you won't need to restart your webserver to have the certificate - applied assuming that you've already configured the webservers to use SSL as instructed in the [web server configuration step](../panel/webserver-config). + applied assuming that you've already configured the webservers to use SSL as instructed in the [web server configuration step](../panel/standalone/webserver-config). ### HTTP challenge diff --git a/content/docs/guides/troubleshooting.mdx b/content/docs/guides/troubleshooting.mdx index a963963a..a6e6a507 100644 --- a/content/docs/guides/troubleshooting.mdx +++ b/content/docs/guides/troubleshooting.mdx @@ -20,7 +20,7 @@ tail -n 1000 /var/www/pelican/storage/logs/laravel-$(date +%F).log | grep "\[$(d * `Connection refused [tcp://_______:6379]`: Redis isn't running or isn't reachable for some other reason. (start by checking the status of the redis service: `systemctl status redis-server`) * `SSL: no alternative certificate subject name matches target host name '_______'`: The used SSL certificate for your panel isn't valid for your panel domain, see [this guide](./ssl) for creating a new SSL certificate. * `General error: 8 attempt to write a readonly database`: Your `database.sqlite` has wrong file permissions and is read-only. Make sure the file is writable and owned by the correct user. - * `Class '_____' not found`: This usually means you are missing php extensions. Make sure [all needed extensions](../panel/getting-started#dependencies) are installed and that you are using the correct php version. + * `Class '_____' not found`: This usually means you are missing php extensions. Make sure [all needed extensions](../panel/standalone/getting-started#dependencies) are installed and that you are using the correct php version. * `Connection timed out after 5001 milliseconds for _______:8080`: Your panel can't reach wings, see the wings connection issues steps below. diff --git a/content/docs/meta.json b/content/docs/meta.json index fd95ca08..6be567db 100644 --- a/content/docs/meta.json +++ b/content/docs/meta.json @@ -2,6 +2,7 @@ "title": "Documentation", "pages": [ "index", + "getting-started", "panel", "wings", "eggs", diff --git a/content/docs/panel/advanced/cloudflare-tunnel.mdx b/content/docs/panel/advanced/cloudflare-tunnel.mdx index 5b767456..fc6471c0 100644 --- a/content/docs/panel/advanced/cloudflare-tunnel.mdx +++ b/content/docs/panel/advanced/cloudflare-tunnel.mdx @@ -5,7 +5,7 @@ description: "Run the Docker panel behind a Cloudflare Tunnel without opening an A [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) lets you serve the panel over HTTPS without opening any inbound ports on your host. A small `cloudflared` container makes an outbound connection to Cloudflare, and Cloudflare forwards requests for your hostname down that connection to the panel. -This guide builds on the [Docker](/docs/panel/advanced/docker) installation. Read that page first, as the steps for backing up your encryption key, installing, and stopping the panel are the same. +This guide builds on the [Docker](/docs/panel/install) installation. Read that page first, as the steps for backing up your encryption key, installing, and stopping the panel are the same. :::info This page only covers the panel. Wings still needs to be reachable by your users' browsers and by the panel, see [Wings](#wings) below. @@ -13,7 +13,7 @@ This page only covers the panel. Wings still needs to be reachable by your users ## Prerequisites -- Docker CE with Docker Compose v2 (see the [Docker installation guide](/docs/guides/docker)) +- Docker CE with Docker Compose v2 (see the [Docker installation guide](/docs/getting-started)) - A domain whose DNS is managed by Cloudflare - A Cloudflare Zero Trust account (the free plan is enough) @@ -82,7 +82,7 @@ Compared to the standard Docker setup: - There is no `ports:` section. Nothing is published on the host, all traffic arrives through the tunnel. - `APP_URL` is the public `https://` hostname from the tunnel. -- `BEHIND_PROXY` makes the panel listen on plain HTTP port 80 and skip Let's Encrypt, since Cloudflare handles TLS (SSL). See [Reverse Proxy Configuration](/docs/panel/advanced/docker#reverse-proxy-configuration). +- `BEHIND_PROXY` makes the panel listen on plain HTTP port 80 and skip Let's Encrypt, since Cloudflare handles TLS (SSL). See [Reverse Proxy Configuration](/docs/panel/install#reverse-proxy-configuration). - `TRUSTED_PROXIES` is the Docker network's subnet, so the panel trusts the forwarded headers from the `cloudflared` container. If you change the subnet, change both. ## Start the Panel @@ -99,7 +99,7 @@ docker compose logs cloudflared You should see `Registered tunnel connection`, and the tunnel should show as **Healthy** in the Cloudflare dashboard. -Now [back up your encryption key](/docs/panel/advanced/docker#back-up-your-encryption-key) and open `https://panel.example.com/installer` to [finish installing](/docs/panel/advanced/docker#installing). +Now [back up your encryption key](/docs/panel/install#back-up-your-encryption-key) and open `https://panel.example.com/installer` to [finish installing](/docs/panel/install#installing). ## Wings diff --git a/content/docs/panel/advanced/docker.mdx b/content/docs/panel/advanced/docker.mdx deleted file mode 100644 index f4716274..00000000 --- a/content/docs/panel/advanced/docker.mdx +++ /dev/null @@ -1,237 +0,0 @@ ---- -title: "Docker" -description: "Deploy the Pelican Panel with Docker Compose using the official image, set the required environment variables and configure a custom Caddyfile or reverse proxy." ---- - -Pelican provides pre-built Docker images via GitHub Packages. `ghcr.io/pelican/panel:latest` is the current latest release, and `ghcr.io/pelican/panel:main` is built automatically from the current `main` branch. Deploying the panel in Docker is still a work in progress. While the plan is to make Docker the preferred installation method, we currently recommend the [standard deployment instructions](/docs/panel/getting-started) - -This guide requires Docker CE. (Docker Compose has been included in the Docker CLI since v2. Docker Compose v1 is unsupported.) For instructions on installing and configuring Docker, see the [installation guide](/docs/guides/docker). - -## Basics - -The easiest deployment method is using the standard `compose.yml` file. - -This configuration includes an integrated web server that will automatically obtain SSL certificates if you are serving over HTTPS. For the database, it assumes you want to use SQLite (or you have an external database server to configure using the installer.) It also assumes you intend to use the Filesystem driver for cache, filesystem or database driver for session, and database driver for queue (or you have an external Redis server to configure using the installer.) If you want to use other options built into Docker, see [Advanced Options](#advanced-options). - -### Create compose.yml - -```yml {17,18} title="compose.yml" -services: - panel: - image: ghcr.io/pelican/panel:latest - restart: always - networks: - - default - ports: - - "80:80" - - "443:443" - extra_hosts: - - "host.docker.internal:host-gateway" - volumes: - - pelican-data:/pelican-data - - pelican-logs:/var/www/html/storage/logs - environment: - XDG_DATA_HOME: /pelican-data - APP_URL: "http://localhost" - ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" - -volumes: - pelican-data: - pelican-logs: - -networks: - default: - ipam: - config: - - subnet: 172.20.0.0/16 -``` - -### Set Required Environment Variables - -1. Set `APP_URL` to the base URL your panel will be reachable on, including the protocol (https:// or http://) and port. - - Note that Caddy, the integrated webserver, will serve a 308 redirect to any requests on port 80 if the `APP_URL` begins with `https://`. If your final site will be reachable over HTTPS but TLS (SSL) will be handled and terminated by an upstream server, such as a reverse proxy, see [Reverse Proxy Configuration](#reverse-proxy-configuration). -2. Set the `ADMIN_EMAIL` to your email address. Caddy will use this email address to generate a LetsEncrypt SSL certificate if you are serving via HTTPS. - -Now, close and save changes to `compose.yml`. - -### Starting - -From the directory in which the compose file is located, run: - -```sh -docker compose up -d -``` - -### Back Up Your Encryption Key - -The first time the container starts, it will generate an `APP_KEY` which is used as an encryption key. This will be saved automatically, but you should save a copy in a secure place in case you need it later. - -```sh -docker compose logs panel | grep 'Generated app key:' -``` - -### Installing - -Open the installer in your browser at `APP_URL/installer` to finish setting up the panel. - -:::note -The first time the container starts after installing or updating, it will apply database migrations, which may take a few minutes. The panel will not be accessible during this process. -::: - -#### Sensible Driver Defaults: - -* Cache Driver: Filesystem -* Database Driver: SQLite -* Queue Driver: Database -* Session Driver: Filesystem - -For other configuration, such as UI options, CAPTCHA, email, backups and OAuth, head to the settings menu in the admin panel. - -### Stopping - -The panel will automatically restart if the container crashes or the host restarts. If you need to non-destructively stop the panel for any reason, navigate back to the directory containing `compose.yml` and run: - -```sh -docker compose down -``` - -### Uninstalling - -To uninstall the panel, navigate to the directory containing `compose.yml` and run: - -```sh -docker compose down -v -``` - -:::danger - **This will permanently delete the panel and all associated data including the SQLite database and your encryption key.** -::: - -## Advanced Options - -### Custom Caddyfile - -The default Caddyfile will work for standard installations. If you need to edit the configuration of the integrated webserver, such as to place it behind a reverse proxy that terminates TLS, you can do so by bind-mounting a Caddyfile on the host to `/etc/caddy/Caddyfile` inside the container. - -This example assumes there is a Caddyfile in the same directory as the `compose.yml` file. - -```yml {15} title="compose.yml" -services: - panel: - image: ghcr.io/pelican/panel:latest - restart: always - networks: - - default - ports: - - "80:80" - - "443:443" - extra_hosts: - - "host.docker.internal:host-gateway" - volumes: - - pelican-data:/pelican-data - - pelican-logs:/var/www/html/storage/logs - - ./Caddyfile:/etc/caddy/Caddyfile - environment: - XDG_DATA_HOME: /pelican-data - APP_URL: "http://localhost" - ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" - -volumes: - pelican-data: - pelican-logs: - -networks: - default: - ipam: - config: - - subnet: 172.20.0.0/16 -``` - -An example Caddyfile for hosting the panel behind a reverse proxy is shown below. It exposes the panel on port 80 regardless of the Host header, and will not attempt to obtain a TLS certificate. `[UPSTREAM IP]` must be replaced with the IP address of the reverse proxy. - -```caddyfile title="Caddyfile" -{ - admin off - servers { - trusted_proxies static [UPSTREAM IP] - } -} - -:80 { - root * /var/www/html/public - encode gzip - - php_fastcgi 127.0.0.1:9000 - file_server -} -``` - -:::info - **Note:** If the trusted directive is not set or improperly configured, file uploads will fail. Commonly, when the reverse proxy is running outside of Docker, the IP address will not match `127.0.0.1`, but will instead match a Docker bridge interface or `docker0`. -::: - -#### Raising file upload limits - -The default file upload limit is 2MB. To raise this limit, modify the `Caddyfile` file as such: - -```caddyfile {6-9} title="Caddyfile" - { - ... - - encode gzip - - php_fastcgi 127.0.0.1:9000 { - env PHP_VALUE "upload_max_filesize = 256M - post_max_size = 256M" - } - file_server -} -``` - -### Reverse Proxy Configuration - -When running the panel behind a reverse proxy that handles TLS (SSL), set the following environment variables: - -1. Set `APP_URL` to the URL users will visit, e.g. `https://panel.example.com`. -2. Set `BEHIND_PROXY` to `"true"`. This does 2 things: - 1. The panel listens on port `80` inside the container, regardless of the `APP_URL`. Map whichever host port your proxy forwards to onto container port `80`. - 2. The panel will not attempt to obtain a certificate from Let's Encrypt. Without this, an `https://` `APP_URL` requires the `LE_EMAIL` environment variable and the panel will exit if it is missing. -3. Set `TRUSTED_PROXIES` to a comma-separated list of the IP addresses (or CIDR ranges) of your reverse proxy, so the panel trusts its forwarded headers. - -No custom Caddyfile is needed for this setup. An example `compose.yml` for hosting the panel behind a reverse proxy is shown below. - -```yml {8,16-18} title="compose.yml" -services: - panel: - image: ghcr.io/pelican/panel:latest - restart: always - networks: - - default - ports: - - "81:80" # Change 81 to the host port your reverse proxy forwards to - extra_hosts: - - "host.docker.internal:host-gateway" - volumes: - - pelican-data:/pelican-data - - pelican-logs:/var/www/html/storage/logs - environment: - XDG_DATA_HOME: /pelican-data - APP_URL: "https://panel.example.com" - BEHIND_PROXY: "true" - TRUSTED_PROXIES: "127.0.0.1,172.17.0.1,172.20.0.1" # Change to the IP(s) of your proxy. These defaults cover a proxy on the same host - ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" - -volumes: - pelican-data: - pelican-logs: - -networks: - default: - ipam: - config: - - subnet: 172.20.0.0/16 -``` - -:::info - **Note:** If `TRUSTED_PROXIES` is not set or does not match your proxy, file uploads will fail. When the reverse proxy runs outside of Docker, its requests usually come from a Docker bridge interface (such as `docker0`, commonly `172.17.0.1`) rather than `127.0.0.1`. -::: diff --git a/content/docs/panel/advanced/meta.json b/content/docs/panel/advanced/meta.json index 9861af2f..fa0c8204 100644 --- a/content/docs/panel/advanced/meta.json +++ b/content/docs/panel/advanced/meta.json @@ -1,4 +1,12 @@ { "title": "Advanced", - "pages": ["redis", "mysql", "artisan", "docker", "podman", "cloudflare-tunnel", "api-docs", "plugins"] + "pages": [ + "redis", + "mysql", + "artisan", + "podman", + "cloudflare-tunnel", + "api-docs", + "plugins" + ] } diff --git a/content/docs/panel/advanced/podman.mdx b/content/docs/panel/advanced/podman.mdx index d2512459..3dcec383 100644 --- a/content/docs/panel/advanced/podman.mdx +++ b/content/docs/panel/advanced/podman.mdx @@ -3,7 +3,7 @@ title: "Deploying with Podman" description: "Deploy Pelican Panel using rootless Podman and Quadlets." --- -This guide runs the panel's [Docker image](./docker) with **rootless Podman** on Fedora, RHEL, or Alma/Rocky Linux, using a **Quadlet** so systemd manages the container. Like the Docker guide, it uses SQLite and serves the panel over plain HTTP on port 80. +This guide runs the panel's [Docker image](../install) with **rootless Podman** on Fedora, RHEL, or Alma/Rocky Linux, using a **Quadlet** so systemd manages the container. Like the Docker guide, it uses SQLite and serves the panel over plain HTTP on port 80. ## Prerequisites @@ -127,11 +127,11 @@ Open the installer in your browser at `http://YOUR_SERVER_IP/installer` to finis ### HTTPS and Reverse Proxies -The image supports the same `BEHIND_PROXY`, `LE_EMAIL` and `TRUSTED_PROXIES` environment variables as the [Docker deployment](./docker#reverse-proxy-configuration). Add them under `env:` in `pelican.yaml`. If the panel serves HTTPS itself, also publish port 443 (`containerPort: 443`, `hostPort: 443`). +The image supports the same `BEHIND_PROXY`, `LE_EMAIL` and `TRUSTED_PROXIES` environment variables as the [Docker deployment](../install#reverse-proxy-configuration). Add them under `env:` in `pelican.yaml`. If the panel serves HTTPS itself, also publish port 443 (`containerPort: 443`, `hostPort: 443`). ### Upload Limit -The default file upload limit is 2MB. To raise it, copy the image's Caddyfile and edit it as shown in the [Docker guide](./docker): +The default file upload limit is 2MB. To raise it, copy the image's Caddyfile and edit it as shown in the [Docker guide](../install): ```sh podman run --rm --entrypoint cat ghcr.io/pelican/panel:latest /etc/caddy/Caddyfile > ~/pelican/Caddyfile diff --git a/content/docs/panel/install.mdx b/content/docs/panel/install.mdx new file mode 100644 index 00000000..93ab13d1 --- /dev/null +++ b/content/docs/panel/install.mdx @@ -0,0 +1,392 @@ +--- +title: "Installing the Panel" +description: "Install the Pelican Panel with Docker: the one-command install script (Docker Swarm, Traefik and automatic HTTPS, optionally MariaDB, Redis and Wings), or Docker Compose by hand." +--- + +Pelican provides pre-built Docker images via GitHub Packages. `ghcr.io/pelican/panel:latest` is the current latest release, and `ghcr.io/pelican/panel:main` is built automatically from the current `main` branch. Docker is the recommended way to install the Panel. If you'd rather run it directly on your server, see the [standalone install](/docs/panel/standalone/getting-started). + +:::note +The images used to be published as `ghcr.io/pelican-dev/panel`. That path no longer gets updates, so if your `compose.yml` still uses it, change `image:` to `ghcr.io/pelican/panel:latest`. +::: + +There are two ways to install it with Docker: + +- **[The install script](#the-install-script)** does everything with one command, HTTPS included, and is the quickest way to a working Panel. +- **[Docker Compose](#docker-compose)** is the same Panel set up by hand, if you want to see and own every step. + +## The install script + +On a fresh Linux server (see [Getting Started](/docs/getting-started) for the requirements), run: + +```sh +curl -fsSL https://pelican.dev/install.sh | sudo bash +``` + +It asks for the Panel's domain, your email, a profile and whether to install Wings on the same server, then: + +1. checks the server: Linux on x86_64 or arm64, a virtualization Docker works on, ports 80 and 443 free, and the domain pointing at this server; +2. installs Docker if it's missing; +3. starts a one-node [Docker Swarm](https://docs.docker.com/engine/swarm/), on address ranges that leave room for Wings' network; +4. deploys a stack named `pelican` from `/opt/pelican`: + - **Traefik** on ports 80 and 443. It sends HTTP to HTTPS and gets a Let's Encrypt certificate for your domain on the first visit, then renews it on its own. + - **The Panel** behind it, in the `ghcr.io/pelican/panel` image. + - With the production profile, **MariaDB** and **Redis** as well. +5. with Wings, installs it [as in the Wings guide](/docs/wings/install) and routes its domain through Traefik, so Wings gets a certificate too. + +When it finishes, open `https:///installer` to create your admin account. + + + - Point an `A` record for the Panel's domain (and Wings' domain, if you install Wings) at the server, and wait until it resolves. + - With Cloudflare, keep the record **DNS only** (grey cloud) so Let's Encrypt can reach the server. You can turn the proxy on once the certificate is there. + - Nothing else may use ports 80 or 443 (an earlier NGINX or Apache, or a Panel installed with Docker Compose). + + +### Profiles + +| Profile | What it runs | For | +|:--------|:-------------|:----| +| `quick` | Traefik and the Panel, with SQLite, file sessions and a database queue | One server and a small community; the least to run and back up | +| `production` | Traefik, the Panel, MariaDB 11.4 and Redis 7 (cache, sessions and queue) | More users, servers and nodes; the database and passwords are set up for you | + +You can't switch an install from one profile to the other by running the script again: the other profile starts with an empty database. + +### Options + +Everything the script asks can be given as an option, so it runs without questions. That's also how to hand it to automation or to an [AI assistant](/docs/guides/ai-assistant): + +```sh +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- \ + --domain panel.example.com --email you@example.com --profile production --yes +``` + +| Option | What it does | +|:-------|:-------------| +| `--domain DOMAIN` | The Panel's address, e.g. `panel.example.com` | +| `--email EMAIL` | Your email, for Let's Encrypt's certificate notices | +| `--profile quick\|production` | Which [profile](#profiles) to run (asks, `quick` by default) | +| `--wings`, `--wings-domain DOMAIN` | Also install Wings on this server, at its own domain such as `node.example.com` | +| `--no-wings` | Don't install Wings, without asking | +| `--dir PATH` | Where the stack's files go (default `/opt/pelican`) | +| `--image IMAGE` | Another Panel image, e.g. a fixed version | +| `--staging` | Use Let's Encrypt's staging server: test certificates, without its rate limits | +| `--skip-dns-check` | Don't check the domains point here (behind NAT, or DNS set up afterwards) | +| `--dry-run` | Show what it would do and write the files to a temp folder, changing nothing. Needs no root, so you can try it anywhere | +| `--yes` | Don't ask anything: use the options given and the defaults for the rest | + +To read the script before running it, download it first: + +```sh +curl -fsSL -o install.sh https://pelican.dev/install.sh +less install.sh +bash install.sh --dry-run --domain panel.example.com --email you@example.com --yes +sudo bash install.sh +``` + +### Your files + +Everything the script sets up is in `/opt/pelican`: + +| File | What it is | +|:-----|:-----------| +| `pelican.env` | Your settings, the `APP_KEY` and the database passwords. Readable by root only. | +| `stack.yml` | The services, with every value taken from `pelican.env` | +| `deploy.sh` | Applies `pelican.env` and `stack.yml` to the running stack | +| `traefik/` | Extra Traefik routes (Wings' route goes here) | + + + `APP_KEY` encrypts parts of your Panel's data. Copy `pelican.env` somewhere safe, off the server: if it's lost, that data can't be recovered, **even with database backups**. + + +### Changing settings later + +Change a value in `pelican.env` and apply it: + +```sh +sudo nano /opt/pelican/pelican.env +sudo /opt/pelican/deploy.sh +``` + +For example, a new `PANEL_DOMAIN` gets its certificate as soon as its DNS points at the server, and `PANEL_IMAGE=ghcr.io/pelican/panel:` keeps the Panel on one version. Running the install script again also works: it keeps your keys and passwords and updates the stack. + +### Updating + +`deploy.sh` checks the registry for each image, so running it again pulls a newer Panel when there is one: + +```sh +sudo /opt/pelican/deploy.sh +``` + +Database migrations run when the new Panel starts. See [Updating the Panel](/docs/panel/update) for the versions each release needs. + +### Wings on the same server + +With `--wings`, the script installs Wings and enables its service, and Traefik serves Wings' domain over HTTPS. Wings itself starts once it has a configuration from the Panel: + +1. In the Panel, go to **Admin → Nodes → Create**. Use Wings' domain as the FQDN, choose **HTTPS** and **Behind Proxy**, and set the port the Panel connects to as `443` and the port Wings listens on as `8080`. +2. Copy the node's configuration to `/etc/pelican/config.yml`, or run its **Auto Deploy** command. Traefik handles HTTPS, so in that file `api.port` is `8080` and `api.ssl.enabled` is `false`. +3. Start Wings: `sudo systemctl start wings`. +4. Open SFTP (port `2022`) and the ports you allocate to game servers in your provider's firewall. When `ufw` is active the script opens 80, 443 and 2022 in it; game server ports are yours to open. + +Wings on other servers is installed [the usual way](/docs/wings/install). + +### When something doesn't work + +```sh +docker service ls # each service should show 1/1 +docker service ps pelican_panel --no-trunc # why a service doesn't start +docker service logs -f pelican_panel # the Panel's logs +docker service logs pelican_traefik 2>&1 | grep -i acme # certificate problems +``` + +No certificate? Check that the domain points at the server, ports 80 and 443 are reachable from the internet and the record isn't proxied by a CDN. Let's Encrypt limits how often it issues certificates for one domain: test with `--staging`, then run the script again without it. + +Docker's address ranges can clash with a network your server is already on. The script uses `10.203.0.0/16` for Swarm and `10.204.0.0/24` for `docker_gwbridge`; set `PELICAN_SWARM_POOL`, `PELICAN_GWBRIDGE_SUBNET` and `PELICAN_PUBLIC_SUBNET` before running it to use others. + +### Backups and removing it + +The Panel's data lives in Docker volumes: `pelican_pelican-data` (the Panel's `.env`, SQLite database and uploads), `pelican_pelican-plugins`, and with the production profile `pelican_pelican-db` (MariaDB). Back them up together with `pelican.env`. For example, for the Panel's data: + +```sh +docker run --rm -v pelican_pelican-data:/data -v "$PWD":/backup alpine tar czf /backup/pelican-data.tar.gz -C /data . +``` + +To remove the stack, keeping its data: `docker stack rm pelican`. Removing the volumes as well (`docker volume rm pelican_pelican-data ...`) **deletes the Panel and all of its data**. + +## Docker Compose + +This guide requires Docker CE. (Docker Compose has been included in the Docker CLI since v2. Docker Compose v1 is unsupported.) For instructions on installing and configuring Docker, see [Getting Started](/docs/getting-started). + +### Basics + +The easiest deployment method is using the standard `compose.yml` file. + +This configuration includes an integrated web server that will automatically obtain SSL certificates if you are serving over HTTPS. For the database, it assumes you want to use SQLite (or you have an external database server to configure using the installer.) It also assumes you intend to use the Filesystem driver for cache, filesystem or database driver for session, and database driver for queue (or you have an external Redis server to configure using the installer.) If you want to use other options built into Docker, see [Advanced Options](#advanced-options). + +### Create compose.yml + +```yml {18,19} title="compose.yml" +services: + panel: + image: ghcr.io/pelican/panel:latest + restart: always + networks: + - default + ports: + - "80:80" + - "443:443" + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - pelican-data:/pelican-data + - pelican-logs:/var/www/html/storage/logs + - pelican-plugins:/var/www/html/plugins + environment: + XDG_DATA_HOME: /pelican-data + APP_URL: "http://localhost" + ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" + +volumes: + pelican-data: + pelican-logs: + pelican-plugins: + +networks: + default: + ipam: + config: + - subnet: 172.20.0.0/16 +``` + +### Set Required Environment Variables + +1. Set `APP_URL` to the base URL your panel will be reachable on, including the protocol (https:// or http://) and port. + - Note that Caddy, the integrated webserver, will serve a 308 redirect to any requests on port 80 if the `APP_URL` begins with `https://`. If your final site will be reachable over HTTPS but TLS (SSL) will be handled and terminated by an upstream server, such as a reverse proxy, see [Reverse Proxy Configuration](#reverse-proxy-configuration). +2. Set the `ADMIN_EMAIL` to your email address. Caddy will use this email address to generate a LetsEncrypt SSL certificate if you are serving via HTTPS. + +Now, close and save changes to `compose.yml`. + +### Starting + +From the directory in which the compose file is located, run: + +```sh +docker compose up -d +``` + +### Back Up Your Encryption Key + +The first time the container starts, it will generate an `APP_KEY` which is used as an encryption key. This will be saved automatically, but you should save a copy in a secure place in case you need it later. + +```sh +docker compose logs panel | grep 'Generated app key:' +``` + +### Installing + +Open the installer in your browser at `APP_URL/installer` to finish setting up the panel. + +:::note +The first time the container starts after installing or updating, it will apply database migrations, which may take a few minutes. The panel will not be accessible during this process. +::: + +#### Sensible Driver Defaults: + +* Cache Driver: Filesystem +* Database Driver: SQLite +* Queue Driver: Database +* Session Driver: Filesystem + +For other configuration, such as UI options, CAPTCHA, email, backups and OAuth, head to the settings menu in the admin panel. + +### Stopping + +The panel will automatically restart if the container crashes or the host restarts. If you need to non-destructively stop the panel for any reason, navigate back to the directory containing `compose.yml` and run: + +```sh +docker compose down +``` + +### Uninstalling + +To uninstall the panel, navigate to the directory containing `compose.yml` and run: + +```sh +docker compose down -v +``` + +:::danger + **This will permanently delete the panel and all associated data including the SQLite database and your encryption key.** +::: + +## Advanced Options + +### Custom Caddyfile + +The default Caddyfile will work for standard installations. If you need to edit the configuration of the integrated webserver, such as to place it behind a reverse proxy that terminates TLS, you can do so by bind-mounting a Caddyfile on the host to `/etc/caddy/Caddyfile` inside the container. + +This example assumes there is a Caddyfile in the same directory as the `compose.yml` file. + +```yml {16} title="compose.yml" +services: + panel: + image: ghcr.io/pelican/panel:latest + restart: always + networks: + - default + ports: + - "80:80" + - "443:443" + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - pelican-data:/pelican-data + - pelican-logs:/var/www/html/storage/logs + - pelican-plugins:/var/www/html/plugins + - ./Caddyfile:/etc/caddy/Caddyfile + environment: + XDG_DATA_HOME: /pelican-data + APP_URL: "http://localhost" + ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" + +volumes: + pelican-data: + pelican-logs: + pelican-plugins: + +networks: + default: + ipam: + config: + - subnet: 172.20.0.0/16 +``` + +An example Caddyfile for hosting the panel behind a reverse proxy is shown below. It exposes the panel on port 80 regardless of the Host header, and will not attempt to obtain a TLS certificate. `[UPSTREAM IP]` must be replaced with the IP address of the reverse proxy. + +```caddyfile title="Caddyfile" +{ + admin off + servers { + trusted_proxies static [UPSTREAM IP] + } +} + +:80 { + root * /var/www/html/public + encode gzip + + php_fastcgi 127.0.0.1:9000 + file_server +} +``` + +:::info + **Note:** If the trusted directive is not set or improperly configured, file uploads will fail. Commonly, when the reverse proxy is running outside of Docker, the IP address will not match `127.0.0.1`, but will instead match a Docker bridge interface or `docker0`. +::: + +#### Raising file upload limits + +The default file upload limit is 2MB. To raise this limit, modify the `Caddyfile` file as such: + +```caddyfile {6-9} title="Caddyfile" + { + ... + + encode gzip + + php_fastcgi 127.0.0.1:9000 { + env PHP_VALUE "upload_max_filesize = 256M + post_max_size = 256M" + } + file_server +} +``` + +### Reverse Proxy Configuration + +When running the panel behind a reverse proxy that handles TLS (SSL), set the following environment variables: + +1. Set `APP_URL` to the URL users will visit, e.g. `https://panel.example.com`. +2. Set `BEHIND_PROXY` to `"true"`. This does 2 things: + 1. The panel listens on port `80` inside the container, regardless of the `APP_URL`. Map whichever host port your proxy forwards to onto container port `80`. + 2. The panel will not attempt to obtain a certificate from Let's Encrypt. Without this, an `https://` `APP_URL` requires the `LE_EMAIL` environment variable and the panel will exit if it is missing. +3. Set `TRUSTED_PROXIES` to a comma-separated list of the IP addresses (or CIDR ranges) of your reverse proxy, so the panel trusts its forwarded headers. + +No custom Caddyfile is needed for this setup. An example `compose.yml` for hosting the panel behind a reverse proxy is shown below. + +```yml {8,17-19} title="compose.yml" +services: + panel: + image: ghcr.io/pelican/panel:latest + restart: always + networks: + - default + ports: + - "81:80" # Change 81 to the host port your reverse proxy forwards to + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - pelican-data:/pelican-data + - pelican-logs:/var/www/html/storage/logs + - pelican-plugins:/var/www/html/plugins + environment: + XDG_DATA_HOME: /pelican-data + APP_URL: "https://panel.example.com" + BEHIND_PROXY: "true" + TRUSTED_PROXIES: "127.0.0.1,172.17.0.1,172.20.0.1" # Change to the IP(s) of your proxy. These defaults cover a proxy on the same host + ADMIN_EMAIL: "USEYOUROWNEMAILHERE@example.com" + +volumes: + pelican-data: + pelican-logs: + pelican-plugins: + +networks: + default: + ipam: + config: + - subnet: 172.20.0.0/16 +``` + +:::info + **Note:** If `TRUSTED_PROXIES` is not set or does not match your proxy, file uploads will fail. When the reverse proxy runs outside of Docker, its requests usually come from a Docker bridge interface (such as `docker0`, commonly `172.17.0.1`) rather than `127.0.0.1`. +::: diff --git a/content/docs/panel/meta.json b/content/docs/panel/meta.json index dee77b62..62f09384 100644 --- a/content/docs/panel/meta.json +++ b/content/docs/panel/meta.json @@ -2,10 +2,8 @@ "title": "Panel", "defaultOpen": true, "pages": [ - "getting-started", - "webserver-config", - "panel-setup", - "optional-config", + "install", + "standalone", "update", "advanced" ] diff --git a/content/docs/panel/getting-started.mdx b/content/docs/panel/standalone/getting-started.mdx similarity index 87% rename from content/docs/panel/getting-started.mdx rename to content/docs/panel/standalone/getting-started.mdx index 227a1381..374c9ed1 100644 --- a/content/docs/panel/getting-started.mdx +++ b/content/docs/panel/standalone/getting-started.mdx @@ -1,6 +1,6 @@ --- -title: "Getting Started" -description: "Start a Pelican Panel install: supported operating systems, PHP and webserver dependencies, downloading the panel files and installing Composer." +title: "Standalone Install" +description: "Install the Pelican Panel directly on your server, without Docker: supported operating systems, PHP and webserver dependencies, downloading the panel files and installing Composer." --- Pelican Panel is designed to run on your webserver. @@ -14,14 +14,14 @@ so please take some time to read through them before asking for help on the foru - You don't need a fresh install. Follow [Migrating from Pterodactyl](../guides/migrating-from-pterodactyl) to upgrade your existing Panel and keep all your data. + You don't need a fresh install. Follow [Migrating from Pterodactyl](../../guides/migrating-from-pterodactyl) to upgrade your existing Panel and keep all your data. - Give it these docs and a tested prompt for a production install: see [Installing with an AI Assistant](../guides/ai-assistant). The **Copy page** button above copies any page for it. + Give it these docs and a tested prompt for a production install: see [Installing with an AI Assistant](../../guides/ai-assistant). The **Copy page** button above copies any page for it. -Pelican can be installed directly on your server (this guide) or with [Docker](./advanced/docker). Both are fully supported. +This guide installs Pelican directly on your server. The recommended method is [Docker](../install), with a one-command install script; use this guide if you'd rather not run the Panel in a container. ### Picking an Operating System (OS) diff --git a/content/docs/panel/standalone/meta.json b/content/docs/panel/standalone/meta.json new file mode 100644 index 00000000..68b99521 --- /dev/null +++ b/content/docs/panel/standalone/meta.json @@ -0,0 +1,9 @@ +{ + "title": "Standalone", + "pages": [ + "getting-started", + "webserver-config", + "panel-setup", + "optional-config" + ] +} diff --git a/content/docs/panel/optional-config.mdx b/content/docs/panel/standalone/optional-config.mdx similarity index 100% rename from content/docs/panel/optional-config.mdx rename to content/docs/panel/standalone/optional-config.mdx diff --git a/content/docs/panel/panel-setup.mdx b/content/docs/panel/standalone/panel-setup.mdx similarity index 93% rename from content/docs/panel/panel-setup.mdx rename to content/docs/panel/standalone/panel-setup.mdx index b96b54d6..0cac9a5a 100644 --- a/content/docs/panel/panel-setup.mdx +++ b/content/docs/panel/standalone/panel-setup.mdx @@ -50,6 +50,6 @@ Once you've set the proper permissions, continue the Panel install on the web in The web installer is located at `/installer` or `/installer`. - Make sure to read the [MySQL guide](./advanced/mysql) first if you want to use MySQL/ MariaDB instead of SQLite! - If you want to use Redis make sure to read the [Redis guide](./advanced/redis) first. + Make sure to read the [MySQL guide](../advanced/mysql) first if you want to use MySQL/ MariaDB instead of SQLite! + If you want to use Redis make sure to read the [Redis guide](../advanced/redis) first. diff --git a/content/docs/panel/webserver-config.mdx b/content/docs/panel/standalone/webserver-config.mdx similarity index 100% rename from content/docs/panel/webserver-config.mdx rename to content/docs/panel/standalone/webserver-config.mdx diff --git a/content/docs/panel/update.mdx b/content/docs/panel/update.mdx index 9c2f5635..9b9fa7c1 100644 --- a/content/docs/panel/update.mdx +++ b/content/docs/panel/update.mdx @@ -27,7 +27,9 @@ You have two options for updating: use the automatic update script (recommended) - A [Docker install](./advanced/docker) updates by pulling the new image. From the directory containing your `compose.yml`, run: + Installed with the [install script](./install#the-install-script)? Run `sudo /opt/pelican/deploy.sh`: it pulls the new image and restarts the Panel. + + A [Docker Compose install](./install#docker-compose) updates by pulling the new image. From the directory containing your `compose.yml`, run: ```sh docker compose pull diff --git a/content/docs/versioning.mdx b/content/docs/versioning.mdx index 54bebb24..3b55f56f 100644 --- a/content/docs/versioning.mdx +++ b/content/docs/versioning.mdx @@ -101,4 +101,4 @@ Install a plugin that provides the Discord webhook type to edit them or create n ### Passkeys -If passkey sign-in fails after updating and the Panel runs behind a reverse proxy, set `TRUSTED_PROXIES` (see [Reverse Proxy Setup](./panel/optional-config#reverse-proxy-setup)) so the Panel sees the correct host. +If passkey sign-in fails after updating and the Panel runs behind a reverse proxy, set `TRUSTED_PROXIES` (see [Reverse Proxy Setup](./panel/standalone/optional-config#reverse-proxy-setup)) so the Panel sees the correct host. diff --git a/content/docs/wings/install.mdx b/content/docs/wings/install.mdx index 4e7763ba..d42e2a54 100644 --- a/content/docs/wings/install.mdx +++ b/content/docs/wings/install.mdx @@ -62,7 +62,7 @@ sudo dmidecode -s system-manufacturer ``` ### Installing Docker -Wings requires Docker CE. For full instructions on installing and configuring Docker, see the [installation guide](/docs/guides/docker). +Wings requires Docker CE. For full instructions on installing and configuring Docker, see [Getting Started](/docs/getting-started). For a quick install of Docker CE, you can use the command below: diff --git a/lib/og-motifs.ts b/lib/og-motifs.ts index da24e354..0842f253 100644 --- a/lib/og-motifs.ts +++ b/lib/og-motifs.ts @@ -35,7 +35,7 @@ export const DOCS_MOTIFS: Record = { }, /* ---- Panel ---- */ - 'panel/getting-started': { + 'panel/standalone/getting-started': { kind: 'code', label: 'sh', lang: 'sh', @@ -45,13 +45,13 @@ export const DOCS_MOTIFS: Record = { 'curl -L https://github.com/pelican/panel/releases/latest/download/panel.tar.gz | sudo tar -xzv', ], }, - 'panel/webserver-config': { + 'panel/standalone/webserver-config': { kind: 'code', label: 'pelican.conf', lang: 'file', lines: ['server {', ' listen 443 ssl;', ' http2 on;', ' server_name ;', ' root /var/www/pelican/public;', ' index index.php;'], }, - 'panel/panel-setup': { + 'panel/standalone/panel-setup': { kind: 'code', label: 'sh', lang: 'sh', @@ -61,7 +61,7 @@ export const DOCS_MOTIFS: Record = { 'sudo chown -R www-data:www-data /var/www/pelican', ], }, - 'panel/optional-config': { + 'panel/standalone/optional-config': { kind: 'code', label: '.env', lang: 'file', @@ -94,12 +94,17 @@ export const DOCS_MOTIFS: Record = { lang: 'sh', lines: ['php artisan p:info', 'php artisan p:user:make [options]', 'php artisan p:node:make [options]'], }, - 'panel/advanced/docker': { + 'panel/install': { kind: 'code', - label: 'compose.yml', - lang: 'file', - lines: ['services:', ' panel:', ' image: ghcr.io/pelican/panel:latest', ' restart: always'], + label: 'sh', + lang: 'sh', + lines: [ + 'curl -fsSL https://pelican.dev/install.sh | sudo bash', + '==> Docker Swarm, Traefik (HTTPS) and the Panel', + 'Finish the setup: https://panel.example.com/installer', + ], }, + 'panel/advanced/podman': { kind: 'code', label: 'pelican.yaml', @@ -168,7 +173,7 @@ export const DOCS_MOTIFS: Record = { }, /* ---- Guides ---- */ - 'guides/docker': { + 'getting-started': { kind: 'code', label: 'sh', lang: 'sh', diff --git a/netlify.toml b/netlify.toml index 12c14c3a..d91f0771 100644 --- a/netlify.toml +++ b/netlify.toml @@ -13,7 +13,7 @@ # ---- pelican.dev/docs next to the Hub ------------------------------------ # After the switch a Cloudflare route sends only /docs/*, /llms.txt, -# /llms-full.txt and the three install scripts here; the Hub serves the rest. +# /llms-full.txt and the four install scripts here; the Hub serves the rest. # So everything the docs load is under /docs/ (see scripts/check-paths.mjs). # The JS, CSS and fonts. next.config.mjs sets assetPrefix '/docs', so pages ask @@ -153,6 +153,45 @@ status = 301 force = true +# Docker became the recommended install (pelican/docs#226): the Docker guide is now +# panel/install, guides/docker is the top-level Getting Started, and the install without +# Docker moved under panel/standalone/. +[[redirects]] + from = "/docs/guides/docker" + to = "/docs/getting-started/" + status = 301 + force = true + +[[redirects]] + from = "/docs/panel/advanced/docker" + to = "/docs/panel/install/" + status = 301 + force = true + +[[redirects]] + from = "/docs/panel/getting-started" + to = "/docs/panel/standalone/getting-started/" + status = 301 + force = true + +[[redirects]] + from = "/docs/panel/webserver-config" + to = "/docs/panel/standalone/webserver-config/" + status = 301 + force = true + +[[redirects]] + from = "/docs/panel/panel-setup" + to = "/docs/panel/standalone/panel-setup/" + status = 301 + force = true + +[[redirects]] + from = "/docs/panel/optional-config" + to = "/docs/panel/standalone/optional-config/" + status = 301 + force = true + # ---- Markdown for AI tools (lib/llms.ts) --------------------------------- # /docs/panel/update.md is built to out/docs/md/panel/update.md (app/docs/md; # the docs page route owns the other paths under /docs). Not forced, so it only diff --git a/ui/nav.json b/ui/nav.json index 093f65fa..852567c4 100644 --- a/ui/nav.json +++ b/ui/nav.json @@ -11,7 +11,7 @@ "title": "Product", "items": [ { "label": "Documentation", "href": "/docs/" }, - { "label": "Install guide", "href": "/docs/panel/getting-started/" }, + { "label": "Install guide", "href": "/docs/getting-started/" }, { "label": "Live demo", "href": "https://demo.pelican.dev" }, { "label": "Plugin Hub", "href": "/plugins" } ] @@ -35,5 +35,5 @@ ] } ], - "cta": { "label": "Get started", "href": "/docs/panel/getting-started/" } + "cta": { "label": "Get started", "href": "/docs/getting-started/" } } From 4638a672dee7f4b58e549dc2bee925b91b4eb00d Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:29:19 +0200 Subject: [PATCH 3/5] feat(install): serve the Panel on the server's external IP by default, no domain needed Without --domain (or an empty answer), the Panel is served on http:// (found automatically, or --ip), with the quick profile and no other questions under --yes. A domain is still the way to HTTPS: give it at install, or later by running the script again with --domain/--email (keys, passwords and data kept) or setting PANEL_DOMAIN and LE_EMAIL and running deploy.sh. After the switch, plain HTTP to the old IP lands on the domain. - Traefik's routes now live in traefik/pelican.yml, written by deploy.sh from pelican.env (IP: the Panel on port 80 at any address; domain: HTTPS with Let's Encrypt, HTTP to HTTPS, Wings' domain). The Panel's APP_URL follows (PANEL_URL). Traefik no longer needs the Docker socket. - Wings without a domain is reached on http://:8080 (ufw opens it); with a panel domain it needs its own, as before. - The install waits for Swarm to finish rolling the services out before checking the Panel: a changed setting replaces the Panel, and the check used to reach the old one. - Traefik's healthcheck runs every 10s, so it counts as 1/1 sooner. Verified in the Ubuntu 24.04 VM: a fresh install with no domain, then adding a domain (and Wings on one), then back, checking the new Panel right after each. --- content/docs/getting-started.mdx | 6 +- content/docs/guides/ai-assistant.mdx | 10 +- content/docs/panel/install.mdx | 49 +++-- public/install.sh | 297 ++++++++++++++++++++------- scripts/install-sh.test.mjs | 117 ++++++++--- 5 files changed, 361 insertions(+), 118 deletions(-) diff --git a/content/docs/getting-started.mdx b/content/docs/getting-started.mdx index 29c7e17d..24080e97 100644 --- a/content/docs/getting-started.mdx +++ b/content/docs/getting-started.mdx @@ -28,17 +28,17 @@ systemd-detect-virt If that command isn't available, `sudo dmidecode -s system-manufacturer` usually tells you as well. -You also need a domain (or subdomain) for the Panel, such as `panel.example.com`, with an `A` record pointing at your server, so it can get an HTTPS certificate. +A domain (or subdomain) for the Panel, such as `panel.example.com` with an `A` record pointing at your server, gives it HTTPS. It's optional to start with: without one the Panel is served on your server's IP address, and you can add the domain later. ## The quick way: one command -On a fresh server, this installs Docker, sets up HTTPS with Let's Encrypt and starts the Panel. It asks for your domain and email, and whether you want the simple setup or the production one: +On a fresh server, this installs Docker and starts the Panel on your server's IP address. Give it a domain and it sets up HTTPS with Let's Encrypt too. It asks whether you have one, and whether you want the simple setup or the production one: ```sh curl -fsSL https://pelican.dev/install.sh | sudo bash ``` -When it's done, open `https:///installer` to finish. [Installing the Panel](./panel/install#the-install-script) explains every option, what the script sets up and how to change it later. Want an AI assistant to walk you through it? See [Installing with an AI Assistant](./guides/ai-assistant). +When it's done, open the address it shows (`http:///installer`, or `https:///installer`) to finish. [Installing the Panel](./panel/install#the-install-script) explains every option, what the script sets up and how to change it later. Want an AI assistant to walk you through it? See [Installing with an AI Assistant](./guides/ai-assistant). The rest of this page sets up Docker by hand, for the [Docker Compose install](./panel/install#docker-compose) or for [Wings](./wings/install). The script does all of it for you. diff --git a/content/docs/guides/ai-assistant.mdx b/content/docs/guides/ai-assistant.mdx index f2575153..4d5eb108 100644 --- a/content/docs/guides/ai-assistant.mdx +++ b/content/docs/guides/ai-assistant.mdx @@ -45,11 +45,13 @@ Read these pages first and follow them exactly: Before any command, ask me, one question at a time, and explain the choice in plain words: 1. The output of `cat /etc/os-release` and `systemd-detect-virt`, to check the server can run Docker. -2. The panel's domain, and whether its DNS A record already points at this server. -3. The email for Let's Encrypt (a real address: example.com addresses are refused). +2. Whether I have a domain for the panel with its DNS A record pointing at this server. Without one, + the panel is served over plain HTTP on the server's IP: fine to try it, but recommend adding a + domain (HTTPS) before real use. A domain can be added later by running the script again. +3. If I use a domain: the email for Let's Encrypt (a real address: example.com addresses are refused). 4. Which profile: "quick" (SQLite, the least to run: one server, a small community) or "production" (MariaDB and Redis: more users, servers and nodes). Recommend one from my answers. -5. Whether Wings should run on this same server, and if so its own domain (e.g. node.example.com). +5. Whether Wings should run on this same server, and with a panel domain, Wings' own domain (e.g. node.example.com). Then: - Write the exact command with my answers as options and --yes, and explain each option. @@ -60,7 +62,7 @@ Then: /opt/pelican/pelican.env. Tell me where to look at them myself. This is a production server. Before we finish, check with me that: -- https:///installer opens with a valid certificate, and I created the admin account there. +- The installer page the script printed opens (with a valid certificate if I used a domain), and I created the admin account there. - I copied /opt/pelican/pelican.env (it holds the APP_KEY) somewhere safe, off the server. - My provider's firewall allows 80 and 443 (and 2022 plus my game server ports if Wings runs here). - If Wings runs here: the node is created in the Panel as the docs describe, /etc/pelican/config.yml diff --git a/content/docs/panel/install.mdx b/content/docs/panel/install.mdx index 93ab13d1..be54db27 100644 --- a/content/docs/panel/install.mdx +++ b/content/docs/panel/install.mdx @@ -11,7 +11,7 @@ The images used to be published as `ghcr.io/pelican-dev/panel`. That path no lon There are two ways to install it with Docker: -- **[The install script](#the-install-script)** does everything with one command, HTTPS included, and is the quickest way to a working Panel. +- **[The install script](#the-install-script)** does everything with one command, HTTPS included once you give it a domain, and is the quickest way to a working Panel. - **[Docker Compose](#docker-compose)** is the same Panel set up by hand, if you want to see and own every step. ## The install script @@ -22,25 +22,37 @@ On a fresh Linux server (see [Getting Started](/docs/getting-started) for the re curl -fsSL https://pelican.dev/install.sh | sudo bash ``` -It asks for the Panel's domain, your email, a profile and whether to install Wings on the same server, then: +It asks whether you have a domain for the Panel (and your email, if so), a profile and whether to install Wings on the same server, then: -1. checks the server: Linux on x86_64 or arm64, a virtualization Docker works on, ports 80 and 443 free, and the domain pointing at this server; +1. checks the server: Linux on x86_64 or arm64, a virtualization Docker works on, ports 80 and 443 free, and the domain pointing at this server if you gave one; 2. installs Docker if it's missing; 3. starts a one-node [Docker Swarm](https://docs.docker.com/engine/swarm/), on address ranges that leave room for Wings' network; 4. deploys a stack named `pelican` from `/opt/pelican`: - - **Traefik** on ports 80 and 443. It sends HTTP to HTTPS and gets a Let's Encrypt certificate for your domain on the first visit, then renews it on its own. + - **Traefik** on ports 80 and 443. Without a domain it serves the Panel on `http://`. With one, it sends HTTP to HTTPS and gets a Let's Encrypt certificate for the domain on the first visit, then renews it on its own. - **The Panel** behind it, in the `ghcr.io/pelican/panel` image. - With the production profile, **MariaDB** and **Redis** as well. -5. with Wings, installs it [as in the Wings guide](/docs/wings/install) and routes its domain through Traefik, so Wings gets a certificate too. +5. with Wings, installs it [as in the Wings guide](/docs/wings/install). With a domain, Traefik also serves Wings' own domain, so Wings gets a certificate too. -When it finishes, open `https:///installer` to create your admin account. +When it finishes, open the address it shows (`http:///installer`, or `https:///installer`) to create your admin account. - - Point an `A` record for the Panel's domain (and Wings' domain, if you install Wings) at the server, and wait until it resolves. - - With Cloudflare, keep the record **DNS only** (grey cloud) so Let's Encrypt can reach the server. You can turn the proxy on once the certificate is there. - Nothing else may use ports 80 or 443 (an earlier NGINX or Apache, or a Panel installed with Docker Compose). + - Using a domain? Point its `A` record (and Wings' domain's, if you install Wings) at the server, and wait until it resolves. + - With Cloudflare, keep the record **DNS only** (grey cloud) so Let's Encrypt can reach the server. You can turn the proxy on once the certificate is there. +### Without a domain + +Run the script without `--domain` (or leave the question empty) and the Panel is served on `http://`, the external IPv4 address the script finds (pass `--ip` to choose another, such as a server behind NAT). It's the quickest way to try Pelican, but it's plain HTTP: logins and data cross the network unencrypted. Add a domain before you rely on it. + +To add one later, point its `A` record at the server and run the script again with the domain. It keeps your keys, passwords and data, switches the Panel to HTTPS and sends visitors of the old address to the new one: + +```sh +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com --email you@example.com --yes +``` + +Or set `PANEL_DOMAIN` and `LE_EMAIL` in `/opt/pelican/pelican.env` and run `sudo /opt/pelican/deploy.sh`. + ### Profiles | Profile | What it runs | For | @@ -55,16 +67,21 @@ You can't switch an install from one profile to the other by running the script Everything the script asks can be given as an option, so it runs without questions. That's also how to hand it to automation or to an [AI assistant](/docs/guides/ai-assistant): ```sh +# On the server's IP, with the defaults (the quick profile, no Wings) +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --yes + +# With a domain and HTTPS, MariaDB and Redis curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- \ --domain panel.example.com --email you@example.com --profile production --yes ``` | Option | What it does | |:-------|:-------------| -| `--domain DOMAIN` | The Panel's address, e.g. `panel.example.com` | -| `--email EMAIL` | Your email, for Let's Encrypt's certificate notices | +| `--domain DOMAIN` | Serve the Panel at this domain with HTTPS, e.g. `panel.example.com`. Without it, the Panel is on `http://` | +| `--email EMAIL` | Your email, for Let's Encrypt's certificate notices (needed with `--domain`) | +| `--ip IP` | The address the Panel is served on without a domain (default: the server's external IPv4 address) | | `--profile quick\|production` | Which [profile](#profiles) to run (asks, `quick` by default) | -| `--wings`, `--wings-domain DOMAIN` | Also install Wings on this server, at its own domain such as `node.example.com` | +| `--wings`, `--wings-domain DOMAIN` | Also install Wings on this server. With `--domain`, Wings needs its own domain such as `node.example.com`; without one, it's on `http://:8080` | | `--no-wings` | Don't install Wings, without asking | | `--dir PATH` | Where the stack's files go (default `/opt/pelican`) | | `--image IMAGE` | Another Panel image, e.g. a fixed version | @@ -91,7 +108,7 @@ Everything the script sets up is in `/opt/pelican`: | `pelican.env` | Your settings, the `APP_KEY` and the database passwords. Readable by root only. | | `stack.yml` | The services, with every value taken from `pelican.env` | | `deploy.sh` | Applies `pelican.env` and `stack.yml` to the running stack | -| `traefik/` | Extra Traefik routes (Wings' route goes here) | +| `traefik/pelican.yml` | Traefik's routes, written by `deploy.sh` from `pelican.env` (add your own files next to it) | `APP_KEY` encrypts parts of your Panel's data. Copy `pelican.env` somewhere safe, off the server: if it's lost, that data can't be recovered, **even with database backups**. @@ -106,7 +123,7 @@ sudo nano /opt/pelican/pelican.env sudo /opt/pelican/deploy.sh ``` -For example, a new `PANEL_DOMAIN` gets its certificate as soon as its DNS points at the server, and `PANEL_IMAGE=ghcr.io/pelican/panel:` keeps the Panel on one version. Running the install script again also works: it keeps your keys and passwords and updates the stack. +For example, a new `PANEL_DOMAIN` (with `LE_EMAIL`) switches the Panel to HTTPS and gets its certificate as soon as its DNS points at the server, and `PANEL_IMAGE=ghcr.io/pelican/panel:` keeps the Panel on one version. Running the install script again also works: it keeps your keys and passwords and updates the stack. ### Updating @@ -120,7 +137,11 @@ Database migrations run when the new Panel starts. See [Updating the Panel](/doc ### Wings on the same server -With `--wings`, the script installs Wings and enables its service, and Traefik serves Wings' domain over HTTPS. Wings itself starts once it has a configuration from the Panel: +With `--wings`, the script installs Wings and enables its service. Wings itself starts once it has a configuration from the Panel. + +Without a domain, Wings is reached directly on `http://:8080`. In the Panel, create the node with the server's IP as the FQDN, **HTTP**, **Not Behind Proxy** and port `8080`; then copy its configuration to `/etc/pelican/config.yml` and start Wings. When you add a domain for the Panel later, Wings needs one too (HTTPS on the Panel means HTTPS on Wings): run the script again with `--wings-domain` and update the node. + +With a domain, Traefik serves Wings' domain over HTTPS: 1. In the Panel, go to **Admin → Nodes → Create**. Use Wings' domain as the FQDN, choose **HTTPS** and **Behind Proxy**, and set the port the Panel connects to as `443` and the port Wings listens on as `8080`. 2. Copy the node's configuration to `/etc/pelican/config.yml`, or run its **Auto Deploy** command. Traefik handles HTTPS, so in that file `api.port` is `8080` and `api.ssl.enabled` is `false`. diff --git a/public/install.sh b/public/install.sh index 314898b8..db7b629c 100644 --- a/public/install.sh +++ b/public/install.sh @@ -3,16 +3,18 @@ # on the same server if you want it. # # curl -fsSL https://pelican.dev/install.sh | sudo bash +# curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --yes # on this server's IP # curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com \ -# --email you@example.com --profile production --yes +# --email you@example.com --profile production --yes # HTTPS on a domain # # Docs: https://pelican.dev/docs/panel/install/ (every option, and how to change things later) # # What it does: checks the server, installs Docker if it's missing, starts a one-node Docker -# Swarm, and deploys a stack named "pelican" from /opt/pelican: Traefik on ports 80 and 443, -# which gets a Let's Encrypt certificate for your domain on the first request, and the Panel -# behind it. "production" adds MariaDB and Redis. With --wings it also installs Wings (the -# binary and systemd service, as in the docs) and routes its domain through Traefik. +# Swarm, and deploys a stack named "pelican" from /opt/pelican: Traefik on ports 80 and 443 and +# the Panel behind it. Without a domain the Panel is served on http://; with +# --domain, Traefik gets a Let's Encrypt certificate on the first request and serves HTTPS (add +# the domain later and it switches). "production" adds MariaDB and Redis. With --wings it also +# installs Wings (the binary and systemd service, as in the docs). # # Settings live in /opt/pelican/pelican.env; change one and run /opt/pelican/deploy.sh. Running # this script again keeps your keys and passwords, and updates the stack. @@ -38,6 +40,7 @@ PUBLIC_SUBNET="${PELICAN_PUBLIC_SUBNET:-10.203.250.0/24}" # Traefik <-> Panel # ---- Options ------------------------------------------------------------------------------- domain="" email="" +ip="" profile="" with_wings="" wings_domain="" @@ -52,13 +55,18 @@ usage() { cat <, and you can add a domain later. + --email EMAIL Email for Let's Encrypt's notices (needed with --domain) + --ip IP The IP the Panel is served on without a domain (default: this + server's external IPv4 address, found automatically) --profile NAME quick: SQLite, the least to run (one server, small installs) production: MariaDB and Redis (more servers and users) --wings Also install Wings on this server --no-wings Don't install Wings on this server - --wings-domain DOMAIN Wings' address, e.g. node.example.com (needs --wings) + --wings-domain DOMAIN Wings' address with HTTPS, e.g. node.example.com (needs --wings and + --domain; without them Wings is on http://:8080) --dir PATH Where the stack's files go (default $DEFAULT_DIR) --image IMAGE Panel image (default $PANEL_IMAGE_DEFAULT) --staging Use Let's Encrypt's staging server (test certificates, no rate limits) @@ -69,7 +77,8 @@ Usage: install.sh [options] -y, --yes Don't ask: use the options given (and the defaults for the rest) -h, --help Show this help -Without --yes it asks for anything you didn't pass. With --yes, --domain and --email are needed. +Without --yes it asks for anything you didn't pass. With --yes nothing else is needed: the Panel +is served on this server's IP, with the quick profile. EOF } @@ -77,6 +86,7 @@ while [[ $# -gt 0 ]]; do case "$1" in --domain) domain="${2:?--domain needs a value}"; shift 2 ;; --email) email="${2:?--email needs a value}"; shift 2 ;; + --ip) ip="${2:?--ip needs a value}"; shift 2 ;; --profile) profile="${2:?--profile needs a value}"; shift 2 ;; --wings) with_wings=yes; shift ;; --no-wings) with_wings=no; shift ;; @@ -153,6 +163,21 @@ confirm() { } valid_domain() { [[ "$1" =~ ^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$ ]]; } +valid_ip() { + local IFS=. part + [[ "$1" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]] || return 1 + for part in $1; do (( part <= 255 )) || return 1; done +} + +# This server's external IPv4 address: what the internet sees (an outside service says), else +# the address of the interface that has the default route. +detect_ip() { + local found + found="$(curl -4 -fsS --max-time 5 https://ipv4.icanhazip.com 2>/dev/null | tr -d '[:space:]' || true)" + valid_ip "$found" || found="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for (i = 1; i < NF; i++) if ($i == "src") print $(i + 1)}' | head -1 || true)" + valid_ip "$found" && printf '%s' "$found" +} + valid_email() { [[ "$1" =~ ^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+[A-Za-z]{2,63}$ ]]; } # secret LENGTH: letters and digits only, so it is safe in YAML, .env files and URLs. @@ -204,21 +229,36 @@ wings_domain="${wings_domain:-$(setting WINGS_DOMAIN)}" panel_image="${panel_image:-$(setting PANEL_IMAGE)}" panel_image="${panel_image:-$PANEL_IMAGE_DEFAULT}" -if [[ -z "$domain" ]]; then - $assume_yes && die "--domain is needed with --yes (the Panel's address, e.g. panel.example.com)." - ask domain "The Panel's domain (its DNS must point at this server), e.g. panel.example.com" "" +if [[ -z "$domain" && -z "$(setting PANEL_IP)" ]]; then + if can_ask; then + info "With a domain (its DNS pointing here) the Panel gets HTTPS right away. Without one it's" + info "served on http://, and you can add a domain later." + fi + ask domain "Domain for the Panel, e.g. panel.example.com (empty: use this server's IP)" "" +fi +if [[ -n "$domain" ]]; then + valid_domain "$domain" || die "\"$domain\" isn't a domain name like panel.example.com." + if [[ -z "$email" ]]; then + $assume_yes && die "--email is needed with --domain (Let's Encrypt sends certificate notices to it)." + ask email "Your email, for Let's Encrypt" "" + fi + valid_email "$email" || die "\"$email\" isn't an email address." + case "${email##*@}" in + example.com | example.net | example.org | localhost) + die "Let's Encrypt refuses addresses at ${email##*@}: use a real email (it only sends certificate notices)." ;; + esac fi -valid_domain "$domain" || die "\"$domain\" isn't a domain name like panel.example.com." -if [[ -z "$email" ]]; then - $assume_yes && die "--email is needed with --yes (Let's Encrypt sends certificate notices to it)." - ask email "Your email, for Let's Encrypt" "" +# The IP the Panel is served on without a domain (kept, so adding a domain later is a small step). +ip="${ip:-$(setting PANEL_IP)}" +if [[ -z "$ip" ]] && ! $dry_run; then + ip="$(detect_ip || true)" +fi +if [[ -n "$ip" ]]; then + valid_ip "$ip" || die "\"$ip\" isn't an IPv4 address." +elif [[ -z "$domain" ]]; then + $dry_run || die "Couldn't find this server's IP address: pass it with --ip." fi -valid_email "$email" || die "\"$email\" isn't an email address." -case "${email##*@}" in - example.com | example.net | example.org | localhost) - die "Let's Encrypt refuses addresses at ${email##*@}: use a real email (it only sends certificate notices)." ;; -esac if [[ -z "$profile" ]]; then if can_ask; then @@ -235,15 +275,18 @@ fi if [[ -z "$with_wings" ]]; then if confirm "Install Wings on this server too, to run game servers here?" "n"; then with_wings=yes; else with_wings=no; fi fi -if [[ "$with_wings" == yes ]]; then +if [[ "$with_wings" == yes && -n "$domain" ]]; then + # The Panel uses HTTPS, so Wings must too: it gets its own domain, through Traefik. if [[ -z "$wings_domain" ]]; then - $assume_yes && die "--wings-domain is needed with --wings and --yes (e.g. node.example.com)." + $assume_yes && die "--wings-domain is needed with --wings and --domain (e.g. node.example.com): with HTTPS, Wings needs its own domain." ask wings_domain "Wings' domain (its DNS must point here too), e.g. node.example.com" "" fi valid_domain "$wings_domain" || die "\"$wings_domain\" isn't a domain name like node.example.com." [[ "$wings_domain" != "$domain" ]] || die "Wings needs its own domain, not the Panel's ($domain)." +elif [[ -n "$wings_domain" && -z "$domain" ]]; then + die "--wings-domain needs --domain: without a domain the Panel uses HTTP, and Wings is reached at http://:8080." else - wings_domain="" + [[ "$with_wings" == yes ]] || wings_domain="" fi le_server="$LE_PRODUCTION" @@ -262,8 +305,16 @@ if [[ "$profile" == production ]]; then db_root_password="${db_root_password:-$(secret 32)}" fi -info "Panel: https://$domain ($profile profile)" -[[ "$with_wings" == yes ]] && info "Wings: https://$wings_domain (on this server)" +if [[ -n "$domain" ]]; then + panel_url="https://$domain" +else + panel_url="http://${ip:-}" +fi +info "Panel: $panel_url ($profile profile)" +[[ -z "$domain" ]] && warn "No domain: the Panel is served over plain HTTP. Add a domain for HTTPS before you rely on it (see the summary)." +if [[ "$with_wings" == yes ]]; then + if [[ -n "$wings_domain" ]]; then info "Wings: https://$wings_domain (on this server)"; else info "Wings: http://${ip:-}:8080 (on this server)"; fi +fi info "Files: $dir" $staging && warn "Let's Encrypt staging: browsers won't trust the certificate. Drop --staging for a real one." @@ -318,7 +369,7 @@ else # DNS: Let's Encrypt can only issue a certificate if the domain reaches this server. $check_dns || info "DNS check skipped (--skip-dns-check)." $check_dns && public_ip="$(curl -4 -fsS --max-time 5 https://ipv4.icanhazip.com 2>/dev/null | tr -d '[:space:]' || true)" - for name in "$domain" ${wings_domain:+"$wings_domain"}; do + for name in ${domain:+"$domain"} ${wings_domain:+"$wings_domain"}; do $check_dns || break resolved="$(getent ahostsv4 "$name" 2>/dev/null | awk '{print $1; exit}' || true)" if [[ -z "$resolved" ]]; then @@ -399,7 +450,10 @@ mkdir -p "$dir/traefik" echo "# Change a value, then run ./deploy.sh to apply it. Keep this file private and backed" echo "# up: APP_KEY decrypts your Panel's data, and nothing can recover it if it's lost." echo "PROFILE='$profile'" + echo "# PANEL_DOMAIN empty: the Panel is served on http://PANEL_IP. Set a domain (and LE_EMAIL)" + echo "# and run ./deploy.sh to switch to HTTPS." echo "PANEL_DOMAIN='$domain'" + echo "PANEL_IP='$ip'" echo "LE_EMAIL='$email'" echo "LE_CA_SERVER='$le_server'" echo "PANEL_IMAGE='$panel_image'" @@ -425,17 +479,14 @@ services: traefik: image: ${TRAEFIK_IMAGE} command: - - --providers.swarm.endpoint=unix:///var/run/docker.sock - - --providers.swarm.exposedByDefault=false - - --providers.swarm.network=pelican_public + # The routes are in traefik/pelican.yml, which deploy.sh writes from pelican.env: the + # Panel on its domain with HTTPS, or on the server's IP over HTTP. No Docker socket needed. - --providers.file.directory=/etc/traefik/dynamic - --providers.file.watch=true - --entryPoints.web.address=:80 - - --entryPoints.web.http.redirections.entryPoint.to=websecure - - --entryPoints.web.http.redirections.entryPoint.scheme=https - --entryPoints.websecure.address=:443 - - --entryPoints.websecure.http.tls.certResolver=letsencrypt # Uploads to the Panel and to Wings can take longer than Traefik's 60 second default. + - --entryPoints.web.transport.respondingTimeouts.readTimeout=600s - --entryPoints.websecure.transport.respondingTimeouts.readTimeout=600s - --certificatesResolvers.letsencrypt.acme.email=${LE_EMAIL} - --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/acme.json @@ -448,20 +499,18 @@ services: - { target: 80, published: 80, protocol: tcp, mode: host } - { target: 443, published: 443, protocol: tcp, mode: host } volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - letsencrypt:/letsencrypt - ${PELICAN_DIR}/traefik:/etc/traefik/dynamic:ro networks: - public healthcheck: test: ["CMD", "traefik", "healthcheck", "--ping"] - interval: 30s + interval: 10s # counted as running once healthy: check often, so `docker service ls` says 1/1 soon timeout: 5s retries: 3 deploy: placement: constraints: - - node.role == manager - "node.id == ${SWARM_NODE_ID}" restart_policy: condition: any @@ -469,12 +518,12 @@ services: panel: image: ${PANEL_IMAGE} environment: - APP_URL: "https://${PANEL_DOMAIN}" + APP_URL: "${PANEL_URL}" # https://PANEL_DOMAIN, or http://PANEL_IP without one (deploy.sh) APP_KEY: "${APP_KEY}" APP_ENV: production APP_DEBUG: "false" XDG_DATA_HOME: /pelican-data - # Traefik terminates HTTPS and forwards from the public network. + # Traefik takes the requests (and terminates HTTPS) and forwards them over the public network. BEHIND_PROXY: "true" TRUSTED_PROXIES: "${PUBLIC_SUBNET}" #PRODUCTION_ENV @@ -494,12 +543,6 @@ services: order: stop-first restart_policy: condition: any - labels: - traefik.enable: "true" - traefik.http.routers.pelican-panel.rule: "Host(`${PANEL_DOMAIN}`)" - traefik.http.routers.pelican-panel.entrypoints: websecure - traefik.http.routers.pelican-panel.tls.certresolver: letsencrypt - traefik.http.services.pelican-panel.loadbalancer.server.port: "80" #PRODUCTION_SERVICES volumes: @@ -611,28 +654,88 @@ set -a set +a export PELICAN_DIR="$PWD" -# Wings on this server: Traefik routes its domain to Wings on the host (file provider). -if [[ -n "${WINGS_DOMAIN:-}" ]]; then - cat >traefik/wings.yml <&2 + exit 1 + fi + export PANEL_URL="https://$PANEL_DOMAIN" +elif [[ -n "${PANEL_IP:-}" ]]; then + export PANEL_URL="http://$PANEL_IP" else - rm -f traefik/wings.yml + echo "Set PANEL_DOMAIN (or PANEL_IP) in pelican.env." >&2 + exit 1 fi +# Traefik's routes (file provider, watched): rewritten from pelican.env on every deploy. +mkdir -p traefik +rm -f traefik/wings.yml # an older name of this file +{ + echo "# Written by deploy.sh from pelican.env: change the settings there, not here." + echo "http:" + echo " routers:" + if [[ -n "${PANEL_DOMAIN:-}" ]]; then + echo " pelican-panel:" + echo " rule: \"Host(\`$PANEL_DOMAIN\`)\"" + echo " entryPoints: [websecure]" + echo " service: pelican-panel" + echo " tls:" + echo " certResolver: letsencrypt" + if [[ -n "${WINGS_DOMAIN:-}" ]]; then + echo " pelican-wings:" + echo " rule: \"Host(\`$WINGS_DOMAIN\`)\"" + echo " entryPoints: [websecure]" + echo " service: pelican-wings" + echo " tls:" + echo " certResolver: letsencrypt" + fi + # Plain HTTP goes to HTTPS (Let's Encrypt's own checks on port 80 still get through): the + # Panel's and Wings' names to themselves, anything else (the server's IP) to the Panel. + hosts="Host(\`$PANEL_DOMAIN\`)" + [[ -n "${WINGS_DOMAIN:-}" ]] && hosts+=" || Host(\`$WINGS_DOMAIN\`)" + echo " pelican-to-https:" + echo " rule: \"$hosts\"" + echo " entryPoints: [web]" + echo " middlewares: [pelican-to-https]" + echo " service: noop@internal" + echo " pelican-to-domain:" + echo " rule: \"PathPrefix(\`/\`)\"" + echo " priority: 1" + echo " entryPoints: [web]" + echo " middlewares: [pelican-to-domain]" + echo " service: noop@internal" + echo " middlewares:" + echo " pelican-to-https:" + echo " redirectScheme:" + echo " scheme: https" + echo " permanent: true" + echo " pelican-to-domain:" + echo " redirectRegex:" + echo " regex: \"^https?://[^/]+(.*)\"" + # shellcheck disable=SC2016 # ${1} is the regex group, for Traefik + echo " replacement: \"https://$PANEL_DOMAIN"'${1}'"\"" + else + # No domain yet: the Panel answers on port 80, whatever the address used. + echo " pelican-panel:" + echo " rule: \"PathPrefix(\`/\`)\"" + echo " priority: 1" + echo " entryPoints: [web]" + echo " service: pelican-panel" + fi + echo " services:" + echo " pelican-panel:" + echo " loadBalancer:" + echo " servers:" + echo " - url: \"http://panel:80\"" + if [[ -n "${PANEL_DOMAIN:-}" && -n "${WINGS_DOMAIN:-}" ]]; then + echo " pelican-wings:" + echo " loadBalancer:" + echo " servers:" + echo " - url: \"$WINGS_UPSTREAM\"" + fi +} >traefik/pelican.yml + # --detach=true: start the update and return (newer Docker asks for it to be explicit). detach=() if docker stack deploy --help 2>/dev/null | grep -q -- '--detach'; then detach=(--detach=true); fi @@ -686,10 +789,14 @@ if ! $dry_run && command -v ufw >/dev/null 2>&1 && ufw status 2>/dev/null | grep ufw allow 443/tcp >/dev/null if [[ "$with_wings" == yes ]]; then ufw allow 2022/tcp >/dev/null # SFTP - # Traefik reaches Wings over docker_gwbridge. - ufw allow in on docker_gwbridge to any port 8080 proto tcp >/dev/null + if [[ -n "$wings_domain" ]]; then + # Traefik reaches Wings over docker_gwbridge; nothing else needs 8080. + ufw allow in on docker_gwbridge to any port 8080 proto tcp >/dev/null + else + ufw allow 8080/tcp >/dev/null # browsers and the Panel reach Wings directly + fi fi - ok "Allowed 80 and 443$([[ "$with_wings" == yes ]] && echo ", 2022 (SFTP) and Traefik to Wings on 8080")" + ok "Allowed 80 and 443$([[ "$with_wings" == yes ]] && echo ", 2022 (SFTP) and 8080 (Wings)")" fi # ---- Deploy -------------------------------------------------------------------------------- @@ -697,20 +804,44 @@ step "Starting the stack" run "$dir/deploy.sh" if ! $dry_run; then - info "Waiting for the Panel and its certificate (the first start runs for a minute or two)..." + # Wait for Swarm to start (or replace) every service first, so the check below reaches the new + # Panel, not the one being replaced (a changed setting restarts it). + info "Waiting for the services to start..." + sleep 3 + for _ in $(seq 1 60); do + services="$(docker service ls --filter "label=com.docker.stack.namespace=$STACK" --format '{{.Name}} {{.Replicas}}')" + starting="$(awk '{ split($2, r, "/"); if (r[1] != r[2]) print $1 }' <<<"$services")" + updating="$(while read -r svc _; do + [[ -n "$svc" ]] && docker service inspect "$svc" --format '{{if .UpdateStatus}}{{.UpdateStatus.State}}{{end}}' + done <<<"$services" | grep -c updating || true)" + [[ -z "$starting" && "$updating" == 0 ]] && break + sleep 5 + done + ready=false check=(curl -fsS --max-time 5 -o /dev/null) - $staging && check+=(-k) # the staging certificate isn't trusted, by design + if [[ -n "$domain" ]]; then + info "Waiting for the Panel and its certificate (the first start runs for a minute or two)..." + target="https://$domain/up" + $staging && check+=(-k) # the staging certificate isn't trusted, by design + else + info "Waiting for the Panel (the first start runs for a minute or two)..." + target="http://127.0.0.1/up" # Traefik serves the Panel on port 80 at any address + fi for _ in $(seq 1 60); do - if "${check[@]}" "https://$domain/up" 2>/dev/null; then + if "${check[@]}" "$target" 2>/dev/null; then ready=true break fi sleep 5 done if $ready; then - ok "https://$domain answers$($staging || echo ", with a valid certificate")" - elif curl -kfsS --max-time 5 -o /dev/null --resolve "$domain:443:127.0.0.1" "https://$domain/up" 2>/dev/null; then + if [[ -n "$domain" ]]; then + ok "$panel_url answers$($staging || echo ", with a valid certificate")" + else + ok "$panel_url answers" + fi + elif [[ -n "$domain" ]] && curl -kfsS --max-time 5 -o /dev/null --resolve "$domain:443:127.0.0.1" "https://$domain/up" 2>/dev/null; then warn "The Panel runs, but the certificate isn't there yet. Check: docker service logs ${STACK}_traefik 2>&1 | grep -i acme" else warn "The Panel hasn't answered yet. Check: docker service ps ${STACK}_panel --no-trunc and docker service logs ${STACK}_panel" @@ -719,7 +850,7 @@ fi # ---- Summary ------------------------------------------------------------------------------- step "Done" -info "Finish the setup in your browser: https://$domain/installer" +info "Finish the setup in your browser: $panel_url/installer" [[ "$profile" == production ]] && info "(The database and cache are ready: MariaDB and Redis.)" cat < Nodes > Create, with FQDN ${ip:-}, HTTP (no SSL), + "Not Behind Proxy" and port 8080. + 2. Copy the node's configuration to /etc/pelican/config.yml (or run its Auto Deploy + command), then: systemctl start wings + 3. Wings (8080), SFTP (2022) and the ports you allocate to game servers must be open in + your provider's firewall too. When you add a domain for HTTPS, Wings needs one too. +EOF +elif [[ "$with_wings" == yes ]]; then cat < { expect(install(['--nope']).code).toBe(2); }); - test('--yes needs --domain and --email, and says so', () => { - expect(dryRun(['--email', 'admin@pelican.test']).out).toContain('--domain is needed with --yes'); - expect(dryRun(['--domain', 'panel.example.com']).out).toContain('--email is needed with --yes'); + test('--yes alone is enough: no domain means the Panel on the IP; a domain needs an email', () => { + const { code, dir } = dryRun(IP); + expect(code).toBe(0); + expect(settings(dir)).toMatchObject({ PANEL_DOMAIN: '', PANEL_IP: '203.0.113.10', LE_EMAIL: '', PROFILE: 'quick' }); + expect(dryRun(['--domain', 'panel.example.com']).out).toContain('--email is needed with --domain'); }); test('bad values are refused before anything is written', () => { @@ -78,13 +81,19 @@ suite('install.sh options', () => { expect(dryRun(['--domain', 'panel.example.com', '--email', "o'brien@example.com"]).out).toContain("isn't an email"); expect(dryRun([...BASE, '--profile', 'enterprise']).out).toContain('--profile is quick or production'); + expect(dryRun(['--ip', '300.1.2.3']).out).toContain("isn't an IPv4 address"); // Let's Encrypt refuses contacts at example.com (seen on a real run), so it's caught up front. expect(dryRun(['--domain', 'panel.example.com', '--email', 'admin@example.com']).out).toContain("Let's Encrypt refuses addresses at example.com"); }); - test('--wings needs its own --wings-domain', () => { + test('with a domain, Wings needs its own; without one, it needs none (and may not have one)', () => { expect(dryRun([...BASE, '--wings']).out).toContain('--wings-domain is needed'); expect(dryRun([...BASE, '--wings', '--wings-domain', 'panel.example.com']).out).toContain('Wings needs its own domain'); + const ip = dryRun([...IP, '--wings']); + expect(ip.code).toBe(0); + expect(ip.out).toContain('http://203.0.113.10:8080'); + expect(settings(ip.dir).WINGS_DOMAIN).toBe(''); + expect(dryRun([...IP, '--wings', '--wings-domain', 'node.example.com']).out).toContain('--wings-domain needs --domain'); }); test('without a terminal and without --yes it asks for --yes instead of guessing', () => { @@ -112,29 +121,30 @@ suite('install.sh files', () => { expect(Object.keys(file.services).sort()).toEqual(['panel', 'traefik']); expect(readFileSync(join(dir, 'stack.yml'), 'utf8')).not.toContain('#PRODUCTION'); - // Traefik: real client IPs (host mode), redirect to HTTPS, Let's Encrypt from pelican.env. + // Traefik: real client IPs (host mode), routes from the file deploy.sh writes, Let's Encrypt + // from pelican.env, and no Docker socket (it doesn't need one). const traefik = file.services.traefik; expect(traefik.ports).toEqual([ { target: 80, published: 80, protocol: 'tcp', mode: 'host' }, { target: 443, published: 443, protocol: 'tcp', mode: 'host' }, ]); - expect(traefik.command).toContain('--providers.swarm.network=pelican_public'); - expect(traefik.command).toContain('--entryPoints.web.http.redirections.entryPoint.to=websecure'); + expect(traefik.command).toContain('--providers.file.directory=/etc/traefik/dynamic'); expect(traefik.command).toContain('--certificatesResolvers.letsencrypt.acme.caServer=${LE_CA_SERVER}'); - expect(traefik.deploy.placement.constraints).toContain('node.id == ${SWARM_NODE_ID}'); + expect(traefik.command.join(' ')).not.toContain('providers.swarm'); + expect(traefik.volumes.join(' ')).not.toContain('docker.sock'); + expect(traefik.deploy.placement.constraints).toEqual(['node.id == ${SWARM_NODE_ID}']); // The Panel: behind Traefik, trusting only the public network it shares with Traefik. const panel = file.services.panel; expect(panel.environment).toMatchObject({ - APP_URL: 'https://${PANEL_DOMAIN}', + APP_URL: '${PANEL_URL}', APP_KEY: '${APP_KEY}', BEHIND_PROXY: 'true', TRUSTED_PROXIES: '${PUBLIC_SUBNET}', }); expect(panel.environment.DB_CONNECTION).toBeUndefined(); expect(panel.volumes).toContain('pelican-plugins:/var/www/html/plugins'); - expect(panel.deploy.labels['traefik.http.routers.pelican-panel.rule']).toBe('Host(`${PANEL_DOMAIN}`)'); - expect(panel.deploy.labels['traefik.http.services.pelican-panel.loadbalancer.server.port']).toBe('80'); + expect(panel.deploy.labels).toBeUndefined(); expect(file.networks.public.ipam.config[0].subnet).toBe('${PUBLIC_SUBNET}'); expect(env.PUBLIC_SUBNET).toBe('10.203.250.0/24'); }); @@ -206,37 +216,96 @@ suite('deploy.sh', () => { const record = join(bin, 'calls'); writeFileSync( join(bin, 'docker'), - `#!/bin/sh\n{ echo "ARGS $*"; echo "PANEL_DOMAIN=$PANEL_DOMAIN"; echo "PELICAN_DIR=$PELICAN_DIR"; echo "APP_KEY_SET=\${APP_KEY:+yes}"; } >> "${record}"\n`, + `#!/bin/sh\n{ echo "ARGS $*"; echo "PANEL_URL=$PANEL_URL"; echo "PELICAN_DIR=$PELICAN_DIR"; echo "APP_KEY_SET=\${APP_KEY:+yes}"; } >> "${record}"\n`, ); chmodSync(join(bin, 'docker'), 0o755); const result = Bun.spawnSync([BASH, join(dir, 'deploy.sh')], { env: { PATH: `${bin}:${process.env.PATH}` } }); - return { code: result.exitCode, calls: existsSync(record) ? readFileSync(record, 'utf8') : '' }; + return { + code: result.exitCode, + err: result.stderr.toString(), + calls: existsSync(record) ? readFileSync(record, 'utf8') : '', + }; } - test('deploys the stack with pelican.env exported, and no Wings route without Wings', () => { - const { dir } = dryRun(BASE); + const routes = (dir) => parse(readFileSync(join(dir, 'traefik', 'pelican.yml'), 'utf8')).http; + + test('without a domain: the Panel on http://, on port 80 at any address, no HTTPS', () => { + const { dir } = dryRun(IP); const { code, calls } = deploy(dir); expect(code).toBe(0); expect(calls).toMatch(/ARGS stack deploy (--detach=true )?--compose-file stack\.yml pelican/); - expect(calls).toContain('PANEL_DOMAIN=panel.example.com'); + expect(calls).toContain('PANEL_URL=http://203.0.113.10'); expect(calls).toContain(`PELICAN_DIR=${dir}`); expect(calls).toContain('APP_KEY_SET=yes'); - expect(existsSync(join(dir, 'traefik', 'wings.yml'))).toBe(false); + + const http = routes(dir); + expect(http.routers).toEqual({ + 'pelican-panel': { rule: 'PathPrefix(`/`)', priority: 1, entryPoints: ['web'], service: 'pelican-panel' }, + }); + expect(http.services['pelican-panel'].loadBalancer.servers).toEqual([{ url: 'http://panel:80' }]); + expect(http.middlewares).toBeUndefined(); + }); + + test('with a domain: HTTPS with Let\'s Encrypt, and plain HTTP sent to HTTPS', () => { + const { dir } = dryRun(BASE); + const { code, calls } = deploy(dir); + expect(code).toBe(0); + expect(calls).toContain('PANEL_URL=https://panel.example.com'); + + const http = routes(dir); + expect(http.routers['pelican-panel']).toEqual({ + rule: 'Host(`panel.example.com`)', + entryPoints: ['websecure'], + service: 'pelican-panel', + tls: { certResolver: 'letsencrypt' }, + }); + // HTTP to the Panel's name goes to HTTPS; anything else on port 80 (the bare IP) to the Panel. + expect(http.routers['pelican-to-https']).toMatchObject({ rule: 'Host(`panel.example.com`)', entryPoints: ['web'], middlewares: ['pelican-to-https'] }); + expect(http.middlewares['pelican-to-https']).toEqual({ redirectScheme: { scheme: 'https', permanent: true } }); + expect(http.routers['pelican-to-domain']).toMatchObject({ rule: 'PathPrefix(`/`)', priority: 1, entryPoints: ['web'], middlewares: ['pelican-to-domain'] }); + expect(http.middlewares['pelican-to-domain']).toEqual({ redirectRegex: { regex: '^https?://[^/]+(.*)', replacement: 'https://panel.example.com${1}' } }); + expect(http.routers['pelican-wings']).toBeUndefined(); + }); + + test('adding a domain later: set it in pelican.env and deploy again', () => { + const { dir } = dryRun(IP); + const file = join(dir, 'pelican.env'); + writeFileSync(file, readFileSync(file, 'utf8').replace("PANEL_DOMAIN=''", "PANEL_DOMAIN='panel.example.com'")); + + const missingEmail = deploy(dir); + expect(missingEmail.code).not.toBe(0); + expect(missingEmail.err).toContain('LE_EMAIL is needed'); + + writeFileSync(file, readFileSync(file, 'utf8').replace("LE_EMAIL=''", "LE_EMAIL='admin@pelican.test'")); + const { code, calls } = deploy(dir); + expect(code).toBe(0); + expect(calls).toContain('PANEL_URL=https://panel.example.com'); + expect(routes(dir).routers['pelican-panel'].tls).toEqual({ certResolver: 'letsencrypt' }); + }); + + test('adding a domain later by running the script again keeps everything else', () => { + const first = dryRun(IP); + const before = settings(first.dir); + const again = dryRun(BASE, first.dir); + expect(again.code).toBe(0); + const after = settings(first.dir); + expect(after).toMatchObject({ PANEL_DOMAIN: 'panel.example.com', PANEL_IP: '203.0.113.10', APP_KEY: before.APP_KEY }); }); - test('with Wings, it writes the Traefik route to Wings on the host', () => { + test('with Wings on a domain, Traefik routes it to Wings on the host', () => { const { dir } = dryRun([...BASE, '--wings', '--wings-domain', 'node.example.com']); expect(settings(dir).WINGS_DOMAIN).toBe('node.example.com'); expect(deploy(dir).code).toBe(0); - const route = parse(readFileSync(join(dir, 'traefik', 'wings.yml'), 'utf8')); - expect(route.http.routers['pelican-wings']).toEqual({ + const http = routes(dir); + expect(http.routers['pelican-wings']).toEqual({ rule: 'Host(`node.example.com`)', entryPoints: ['websecure'], service: 'pelican-wings', tls: { certResolver: 'letsencrypt' }, }); - expect(route.http.services['pelican-wings'].loadBalancer.servers).toEqual([{ url: 'http://10.204.0.1:8080' }]); + expect(http.services['pelican-wings'].loadBalancer.servers).toEqual([{ url: 'http://10.204.0.1:8080' }]); + expect(http.routers['pelican-to-https'].rule).toBe('Host(`panel.example.com`) || Host(`node.example.com`)'); }); }); From 76144d3906e294c713e9f2c5aeec7bd682e36773 Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:14:30 +0200 Subject: [PATCH 4/5] feat(install): ask nothing by default, take PELICAN_* variables, pin Traefik The model Coolify and Dokploy use: the installer runs straight through and anything not given takes its default. - No questions unless --interactive (or PELICAN_INTERACTIVE=1), which asks for each choice with explanations and needs a terminal. With no options it installs the Panel on the server's IP, quick profile, no Wings. A domain without an email, or Wings without its domain next to a Panel domain, stops with the option and the variable to set. --yes is still accepted, unused. - Every option can be an environment variable (PELICAN_DOMAIN, PELICAN_EMAIL, PELICAN_PROFILE, PELICAN_WINGS, PELICAN_WINGS_DOMAIN, PELICAN_IP, PELICAN_DIR, PELICAN_IMAGE, PELICAN_STAGING, PELICAN_SKIP_DNS_CHECK, PELICAN_DRY_RUN, PELICAN_INTERACTIVE); the option wins. With sudo they go after it: curl ... | sudo PELICAN_DOMAIN=panel.example.com PELICAN_EMAIL=... bash - Traefik pinned to v3.7.19 (was the moving v3 tag). Running the script again moves an install to the version it pins; PELICAN_TRAEFIK_IMAGE for another. Docs and the AI prompt drop --yes and list the variables. Verified in the VM: the script piped into sudo with variables re-ran an install with no questions and moved Traefik to 3.7.19; --interactive answered through a pseudo-terminal. --- content/docs/getting-started.mdx | 8 ++- content/docs/guides/ai-assistant.mdx | 3 +- content/docs/panel/install.mdx | 55 ++++++++++-------- public/install.sh | 86 ++++++++++++++++++---------- scripts/install-sh.test.mjs | 62 +++++++++++++++----- 5 files changed, 146 insertions(+), 68 deletions(-) diff --git a/content/docs/getting-started.mdx b/content/docs/getting-started.mdx index 24080e97..64fe8395 100644 --- a/content/docs/getting-started.mdx +++ b/content/docs/getting-started.mdx @@ -32,12 +32,18 @@ A domain (or subdomain) for the Panel, such as `panel.example.com` with an `A` r ## The quick way: one command -On a fresh server, this installs Docker and starts the Panel on your server's IP address. Give it a domain and it sets up HTTPS with Let's Encrypt too. It asks whether you have one, and whether you want the simple setup or the production one: +On a fresh server, this installs Docker and starts the Panel on your server's IP address. Give it a domain and it sets up HTTPS with Let's Encrypt too: ```sh +# On your server's IP curl -fsSL https://pelican.dev/install.sh | sudo bash + +# On your domain, with HTTPS +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com --email you@example.com ``` +It asks nothing; add `--interactive` to be asked about each choice (a domain, the simple or the production setup, Wings). + When it's done, open the address it shows (`http:///installer`, or `https:///installer`) to finish. [Installing the Panel](./panel/install#the-install-script) explains every option, what the script sets up and how to change it later. Want an AI assistant to walk you through it? See [Installing with an AI Assistant](./guides/ai-assistant). The rest of this page sets up Docker by hand, for the [Docker Compose install](./panel/install#docker-compose) or for [Wings](./wings/install). The script does all of it for you. diff --git a/content/docs/guides/ai-assistant.mdx b/content/docs/guides/ai-assistant.mdx index 4d5eb108..1634db8f 100644 --- a/content/docs/guides/ai-assistant.mdx +++ b/content/docs/guides/ai-assistant.mdx @@ -54,7 +54,8 @@ Before any command, ask me, one question at a time, and explain the choice in pl 5. Whether Wings should run on this same server, and with a panel domain, Wings' own domain (e.g. node.example.com). Then: -- Write the exact command with my answers as options and --yes, and explain each option. +- Write the exact command with my answers as options (the script asks nothing itself; anything + left out takes its default), and explain each option. - Have me run it with --dry-run first and paste the output, so we both see the plan. Only then the real run. - Wait for me to paste the output of each step. If something fails, ask for the exact error and the logs the docs name (docker service ls, docker service logs pelican_panel, pelican_traefik) instead of guessing. diff --git a/content/docs/panel/install.mdx b/content/docs/panel/install.mdx index be54db27..a89539e0 100644 --- a/content/docs/panel/install.mdx +++ b/content/docs/panel/install.mdx @@ -22,7 +22,7 @@ On a fresh Linux server (see [Getting Started](/docs/getting-started) for the re curl -fsSL https://pelican.dev/install.sh | sudo bash ``` -It asks whether you have a domain for the Panel (and your email, if so), a profile and whether to install Wings on the same server, then: +It asks nothing: with no options it installs the Panel on your server's IP, with the [quick profile](#profiles) and without Wings. To choose, pass [options](#options) (a domain, a profile, Wings), or add `--interactive` to be asked. Then it: 1. checks the server: Linux on x86_64 or arm64, a virtualization Docker works on, ports 80 and 443 free, and the domain pointing at this server if you gave one; 2. installs Docker if it's missing; @@ -43,12 +43,12 @@ When it finishes, open the address it shows (`http:///installe ### Without a domain -Run the script without `--domain` (or leave the question empty) and the Panel is served on `http://`, the external IPv4 address the script finds (pass `--ip` to choose another, such as a server behind NAT). It's the quickest way to try Pelican, but it's plain HTTP: logins and data cross the network unencrypted. Add a domain before you rely on it. +Run the script without `--domain` and the Panel is served on `http://`, the external IPv4 address the script finds (pass `--ip` to choose another, such as a server behind NAT). It's the quickest way to try Pelican, but it's plain HTTP: logins and data cross the network unencrypted. Add a domain before you rely on it. To add one later, point its `A` record at the server and run the script again with the domain. It keeps your keys, passwords and data, switches the Panel to HTTPS and sends visitors of the old address to the new one: ```sh -curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com --email you@example.com --yes +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com --email you@example.com ``` Or set `PANEL_DOMAIN` and `LE_EMAIL` in `/opt/pelican/pelican.env` and run `sudo /opt/pelican/deploy.sh`. @@ -64,39 +64,48 @@ You can't switch an install from one profile to the other by running the script ### Options -Everything the script asks can be given as an option, so it runs without questions. That's also how to hand it to automation or to an [AI assistant](/docs/guides/ai-assistant): +The script never asks unless you pass `--interactive`: anything you don't give takes its default. Give your choices as options after `bash -s --`, or as environment variables, which suits cloud-init and other provisioning tools. That's also how to hand it to an [AI assistant](/docs/guides/ai-assistant): ```sh # On the server's IP, with the defaults (the quick profile, no Wings) -curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --yes +curl -fsSL https://pelican.dev/install.sh | sudo bash # With a domain and HTTPS, MariaDB and Redis curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- \ - --domain panel.example.com --email you@example.com --profile production --yes + --domain panel.example.com --email you@example.com --profile production + +# The same with environment variables (with sudo, put them after it) +curl -fsSL https://pelican.dev/install.sh | sudo PELICAN_DOMAIN=panel.example.com \ + PELICAN_EMAIL=you@example.com PELICAN_PROFILE=production bash + +# Asked one question at a time, with explanations +curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --interactive ``` -| Option | What it does | -|:-------|:-------------| -| `--domain DOMAIN` | Serve the Panel at this domain with HTTPS, e.g. `panel.example.com`. Without it, the Panel is on `http://` | -| `--email EMAIL` | Your email, for Let's Encrypt's certificate notices (needed with `--domain`) | -| `--ip IP` | The address the Panel is served on without a domain (default: the server's external IPv4 address) | -| `--profile quick\|production` | Which [profile](#profiles) to run (asks, `quick` by default) | -| `--wings`, `--wings-domain DOMAIN` | Also install Wings on this server. With `--domain`, Wings needs its own domain such as `node.example.com`; without one, it's on `http://:8080` | -| `--no-wings` | Don't install Wings, without asking | -| `--dir PATH` | Where the stack's files go (default `/opt/pelican`) | -| `--image IMAGE` | Another Panel image, e.g. a fixed version | -| `--staging` | Use Let's Encrypt's staging server: test certificates, without its rate limits | -| `--skip-dns-check` | Don't check the domains point here (behind NAT, or DNS set up afterwards) | -| `--dry-run` | Show what it would do and write the files to a temp folder, changing nothing. Needs no root, so you can try it anywhere | -| `--yes` | Don't ask anything: use the options given and the defaults for the rest | +| Option | Variable | What it does | +|:-------|:---------|:-------------| +| `--domain DOMAIN` | `PELICAN_DOMAIN` | Serve the Panel at this domain with HTTPS, e.g. `panel.example.com`. Without it, the Panel is on `http://` | +| `--email EMAIL` | `PELICAN_EMAIL` | Your email, for Let's Encrypt's certificate notices (needed with a domain) | +| `--ip IP` | `PELICAN_IP` | The address the Panel is served on without a domain (default: the server's external IPv4 address) | +| `--profile quick\|production` | `PELICAN_PROFILE` | Which [profile](#profiles) to run (default `quick`) | +| `--wings`, `--no-wings` | `PELICAN_WINGS=1` or `0` | Also install Wings on this server (default: no). Without a domain it's on `http://:8080` | +| `--wings-domain DOMAIN` | `PELICAN_WINGS_DOMAIN` | Wings' own domain, such as `node.example.com`: needed for Wings when the Panel has a domain | +| `--dir PATH` | `PELICAN_DIR` | Where the stack's files go (default `/opt/pelican`) | +| `--image IMAGE` | `PELICAN_IMAGE` | Another Panel image, e.g. a fixed version | +| `--staging` | `PELICAN_STAGING=1` | Use Let's Encrypt's staging server: test certificates, without its rate limits | +| `--skip-dns-check` | `PELICAN_SKIP_DNS_CHECK=1` | Don't check the domains point here (behind NAT, or DNS set up afterwards). Without it, a domain that doesn't point here stops the install | +| `--dry-run` | `PELICAN_DRY_RUN=1` | Show what it would do and write the files to a temp folder, changing nothing. Needs no root, so you can try it anywhere | +| `--interactive` | `PELICAN_INTERACTIVE=1` | Ask for each choice instead, with explanations | + +When both are set, the option wins. `PELICAN_TRAEFIK_IMAGE` runs another Traefik than the exact version the script pins. To read the script before running it, download it first: ```sh curl -fsSL -o install.sh https://pelican.dev/install.sh less install.sh -bash install.sh --dry-run --domain panel.example.com --email you@example.com --yes -sudo bash install.sh +bash install.sh --dry-run --domain panel.example.com --email you@example.com +sudo bash install.sh --domain panel.example.com --email you@example.com ``` ### Your files @@ -123,7 +132,7 @@ sudo nano /opt/pelican/pelican.env sudo /opt/pelican/deploy.sh ``` -For example, a new `PANEL_DOMAIN` (with `LE_EMAIL`) switches the Panel to HTTPS and gets its certificate as soon as its DNS points at the server, and `PANEL_IMAGE=ghcr.io/pelican/panel:` keeps the Panel on one version. Running the install script again also works: it keeps your keys and passwords and updates the stack. +For example, a new `PANEL_DOMAIN` (with `LE_EMAIL`) switches the Panel to HTTPS and gets its certificate as soon as its DNS points at the server, and `PANEL_IMAGE=ghcr.io/pelican/panel:` keeps the Panel on one version. Running the install script again also works: it keeps your keys and passwords, updates the stack and moves Traefik to the version it pins. ### Updating diff --git a/public/install.sh b/public/install.sh index db7b629c..77576306 100644 --- a/public/install.sh +++ b/public/install.sh @@ -2,10 +2,15 @@ # Pelican one-command install: Docker Swarm, Traefik (automatic HTTPS) and the Panel, and Wings # on the same server if you want it. # -# curl -fsSL https://pelican.dev/install.sh | sudo bash -# curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --yes # on this server's IP +# curl -fsSL https://pelican.dev/install.sh | sudo bash # on this server's IP # curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --domain panel.example.com \ -# --email you@example.com --profile production --yes # HTTPS on a domain +# --email you@example.com --profile production # HTTPS on a domain +# curl -fsSL https://pelican.dev/install.sh | sudo bash -s -- --interactive # asks you +# +# It asks nothing unless you pass --interactive: what you don't pass takes its default. Every +# option can also be an environment variable (PELICAN_DOMAIN, PELICAN_EMAIL, ... see --help), +# e.g. curl -fsSL https://pelican.dev/install.sh | sudo PELICAN_DOMAIN=panel.example.com \ +# PELICAN_EMAIL=you@example.com bash # # Docs: https://pelican.dev/docs/panel/install/ (every option, and how to change things later) # @@ -25,7 +30,7 @@ VERSION="1" STACK="pelican" DEFAULT_DIR="/opt/pelican" PANEL_IMAGE_DEFAULT="ghcr.io/pelican/panel:latest" -TRAEFIK_IMAGE_DEFAULT="traefik:v3" +TRAEFIK_IMAGE_DEFAULT="traefik:v3.7.19" # an exact version: updates are a change to this line LE_PRODUCTION="https://acme-v02.api.letsencrypt.org/directory" LE_STAGING="https://acme-staging-v02.api.letsencrypt.org/directory" WINGS_RELEASES="https://github.com/pelican/wings/releases/latest/download" @@ -38,47 +43,66 @@ GWBRIDGE_SUBNET="${PELICAN_GWBRIDGE_SUBNET:-10.204.0.0/24}" # docker_gwbridge: c PUBLIC_SUBNET="${PELICAN_PUBLIC_SUBNET:-10.203.250.0/24}" # Traefik <-> Panel (TRUSTED_PROXIES) # ---- Options ------------------------------------------------------------------------------- -domain="" -email="" -ip="" -profile="" +# Each starts from its PELICAN_* environment variable (for cloud-init and other tools); the +# command-line option wins over it. +truthy() { [[ "${1,,}" =~ ^(1|true|yes|y|on)$ ]]; } +falsy() { [[ "${1,,}" =~ ^(0|false|no|n|off)$ ]]; } + +domain="${PELICAN_DOMAIN:-}" +email="${PELICAN_EMAIL:-}" +ip="${PELICAN_IP:-}" +profile="${PELICAN_PROFILE:-}" with_wings="" -wings_domain="" -dir="$DEFAULT_DIR" -panel_image="" +truthy "${PELICAN_WINGS:-}" && with_wings=yes +falsy "${PELICAN_WINGS:-}" && with_wings=no +wings_domain="${PELICAN_WINGS_DOMAIN:-}" +dir="${PELICAN_DIR:-$DEFAULT_DIR}" +panel_image="${PELICAN_IMAGE:-}" staging=false +truthy "${PELICAN_STAGING:-}" && staging=true check_dns=true -assume_yes=false +truthy "${PELICAN_SKIP_DNS_CHECK:-}" && check_dns=false +interactive=false +truthy "${PELICAN_INTERACTIVE:-}" && interactive=true dry_run=false +truthy "${PELICAN_DRY_RUN:-}" && dry_run=true usage() { cat <, and you can add a domain later. - --email EMAIL Email for Let's Encrypt's notices (needed with --domain) + [PELICAN_DOMAIN] + --email EMAIL Email for Let's Encrypt's notices (needed with --domain) [PELICAN_EMAIL] --ip IP The IP the Panel is served on without a domain (default: this - server's external IPv4 address, found automatically) + server's external IPv4 address, found automatically) [PELICAN_IP] --profile NAME quick: SQLite, the least to run (one server, small installs) production: MariaDB and Redis (more servers and users) - --wings Also install Wings on this server - --no-wings Don't install Wings on this server + (default quick) [PELICAN_PROFILE] + --wings, --no-wings Install Wings on this server too, or not (default not) + [PELICAN_WINGS=1/0] --wings-domain DOMAIN Wings' address with HTTPS, e.g. node.example.com (needs --wings and --domain; without them Wings is on http://:8080) - --dir PATH Where the stack's files go (default $DEFAULT_DIR) - --image IMAGE Panel image (default $PANEL_IMAGE_DEFAULT) - --staging Use Let's Encrypt's staging server (test certificates, no rate limits) + [PELICAN_WINGS_DOMAIN] + --dir PATH Where the stack's files go (default $DEFAULT_DIR) [PELICAN_DIR] + --image IMAGE Panel image (default $PANEL_IMAGE_DEFAULT) [PELICAN_IMAGE] + --staging Use Let's Encrypt's staging server (test certificates, no rate + limits) [PELICAN_STAGING=1] --skip-dns-check Don't check that the domains point at this server (behind NAT, or DNS that you set up afterwards: the certificate waits for it) + [PELICAN_SKIP_DNS_CHECK=1] --dry-run Write the files to --dir (a temp folder by default) and show the plan; - change nothing on this server. No root needed. - -y, --yes Don't ask: use the options given (and the defaults for the rest) + change nothing on this server. No root needed. [PELICAN_DRY_RUN=1] -h, --help Show this help -Without --yes it asks for anything you didn't pass. With --yes nothing else is needed: the Panel -is served on this server's IP, with the quick profile. +With sudo, put the variables after it: curl ... | sudo PELICAN_DOMAIN=panel.example.com bash EOF } @@ -96,7 +120,8 @@ while [[ $# -gt 0 ]]; do --staging) staging=true; shift ;; --skip-dns-check) check_dns=false; shift ;; --dry-run) dry_run=true; shift ;; - -y|--yes) assume_yes=true; shift ;; + --interactive | -i) interactive=true; shift ;; + -y|--yes) shift ;; # not asking is the default now; still accepted -h|--help) usage; exit 0 ;; *) echo "Unknown option: $1" >&2; usage >&2; exit 2 ;; esac @@ -144,7 +169,7 @@ quietly() { trap 'die "line $LINENO: \"$BASH_COMMAND\" failed. Nothing after this step ran; fix the cause and run the script again (it picks up where it stopped)."' ERR # ---- Asking -------------------------------------------------------------------------------- -can_ask() { ! $assume_yes && { : /dev/null; } +can_ask() { $interactive && { : /dev/null; } # ask VAR "Question" default: prompts on the terminal (also under curl | bash). ask() { @@ -189,8 +214,8 @@ secret() { printf '%s' "${out:0:$1}" } -if ! $assume_yes && ! { : /dev/null; then - die "No terminal for questions: pass the options and --yes (see --help)." +if $interactive && ! { : /dev/null; then + die "--interactive needs a terminal to ask on: pass the options instead (see --help)." fi # ---- Saved settings ------------------------------------------------------------------------ @@ -239,7 +264,7 @@ fi if [[ -n "$domain" ]]; then valid_domain "$domain" || die "\"$domain\" isn't a domain name like panel.example.com." if [[ -z "$email" ]]; then - $assume_yes && die "--email is needed with --domain (Let's Encrypt sends certificate notices to it)." + $interactive || die "--email (or PELICAN_EMAIL) is needed with --domain: Let's Encrypt sends certificate notices to it." ask email "Your email, for Let's Encrypt" "" fi valid_email "$email" || die "\"$email\" isn't an email address." @@ -278,7 +303,7 @@ fi if [[ "$with_wings" == yes && -n "$domain" ]]; then # The Panel uses HTTPS, so Wings must too: it gets its own domain, through Traefik. if [[ -z "$wings_domain" ]]; then - $assume_yes && die "--wings-domain is needed with --wings and --domain (e.g. node.example.com): with HTTPS, Wings needs its own domain." + $interactive || die "--wings-domain (or PELICAN_WINGS_DOMAIN) is needed with --wings and --domain (e.g. node.example.com): with HTTPS, Wings needs its own domain." ask wings_domain "Wings' domain (its DNS must point here too), e.g. node.example.com" "" fi valid_domain "$wings_domain" || die "\"$wings_domain\" isn't a domain name like node.example.com." @@ -457,7 +482,8 @@ mkdir -p "$dir/traefik" echo "LE_EMAIL='$email'" echo "LE_CA_SERVER='$le_server'" echo "PANEL_IMAGE='$panel_image'" - echo "TRAEFIK_IMAGE='$(setting TRAEFIK_IMAGE | grep . || echo "$TRAEFIK_IMAGE_DEFAULT")'" + # The version this script pins (a new script moves Traefik along); PELICAN_TRAEFIK_IMAGE for another. + echo "TRAEFIK_IMAGE='${PELICAN_TRAEFIK_IMAGE:-$TRAEFIK_IMAGE_DEFAULT}'" echo "PUBLIC_SUBNET='$PUBLIC_SUBNET'" echo "SWARM_NODE_ID='$node_id'" echo "APP_KEY='$app_key'" diff --git a/scripts/install-sh.test.mjs b/scripts/install-sh.test.mjs index cc1f43a6..8dbe6555 100644 --- a/scripts/install-sh.test.mjs +++ b/scripts/install-sh.test.mjs @@ -33,8 +33,8 @@ function install(args, env = {}) { return { code: result.exitCode, out: result.stdout.toString() + result.stderr.toString() }; } -function dryRun(extra = [], dir = mkdtempSync(join(tmpdir(), 'pelican-install-'))) { - const result = install(['--dry-run', '--yes', '--dir', dir, ...extra]); +function dryRun(extra = [], dir = mkdtempSync(join(tmpdir(), 'pelican-install-')), env = {}) { + const result = install(['--dry-run', '--dir', dir, ...extra], env); return { ...result, dir }; } @@ -54,23 +54,55 @@ function settings(dir) { const stack = (dir) => parse(readFileSync(join(dir, 'stack.yml'), 'utf8')); suite('install.sh options', () => { - test('--help lists the options and exits 0', () => { + test('--help lists the options and their environment variables, and exits 0', () => { const { code, out } = install(['--help']); expect(code).toBe(0); - for (const flag of ['--domain', '--email', '--profile', '--wings', '--wings-domain', '--dry-run', '--yes', '--staging']) { + for (const flag of ['--interactive', '--domain', '--email', '--ip', '--profile', '--wings', '--wings-domain', '--dry-run', '--staging']) { expect(out).toContain(flag); } + for (const name of ['PELICAN_DOMAIN', 'PELICAN_EMAIL', 'PELICAN_PROFILE', 'PELICAN_WINGS', 'PELICAN_IP', 'PELICAN_INTERACTIVE']) { + expect(out).toContain(name); + } + expect(out).not.toContain('--yes'); // not asking is the default; there's nothing to say yes to }); test('an unknown option fails with exit 2', () => { expect(install(['--nope']).code).toBe(2); }); - test('--yes alone is enough: no domain means the Panel on the IP; a domain needs an email', () => { - const { code, dir } = dryRun(IP); + test('it asks nothing by default: no options means the Panel on the IP, quick, no Wings', () => { + const { code, out, dir } = dryRun(IP); expect(code).toBe(0); - expect(settings(dir)).toMatchObject({ PANEL_DOMAIN: '', PANEL_IP: '203.0.113.10', LE_EMAIL: '', PROFILE: 'quick' }); - expect(dryRun(['--domain', 'panel.example.com']).out).toContain('--email is needed with --domain'); + expect(settings(dir)).toMatchObject({ PANEL_DOMAIN: '', PANEL_IP: '203.0.113.10', LE_EMAIL: '', PROFILE: 'quick', WINGS_DOMAIN: '' }); + expect(out).not.toContain('Wings:'); + // A domain needs an email; without --interactive that's an error naming both ways to give it. + expect(dryRun(['--domain', 'panel.example.com']).out).toContain('--email (or PELICAN_EMAIL) is needed with --domain'); + }); + + test('--yes from older instructions is still accepted', () => { + expect(dryRun([...IP, '--yes']).code).toBe(0); + }); + + test('every option can be an environment variable, and the option wins over it', () => { + const fromEnv = dryRun([], undefined, { + PELICAN_DOMAIN: 'panel.example.com', + PELICAN_EMAIL: 'admin@pelican.test', + PELICAN_PROFILE: 'production', + PELICAN_WINGS: 'yes', + PELICAN_WINGS_DOMAIN: 'node.example.com', + PELICAN_STAGING: '1', + }); + expect(fromEnv.code).toBe(0); + expect(settings(fromEnv.dir)).toMatchObject({ + PANEL_DOMAIN: 'panel.example.com', + LE_EMAIL: 'admin@pelican.test', + PROFILE: 'production', + WINGS_DOMAIN: 'node.example.com', + LE_CA_SERVER: 'https://acme-staging-v02.api.letsencrypt.org/directory', + }); + + const overridden = dryRun(['--profile', 'quick', '--no-wings'], undefined, { PELICAN_PROFILE: 'production', PELICAN_WINGS: '1', PELICAN_IP: '203.0.113.10' }); + expect(settings(overridden.dir)).toMatchObject({ PROFILE: 'quick', WINGS_DOMAIN: '', PANEL_IP: '203.0.113.10' }); }); test('bad values are refused before anything is written', () => { @@ -87,7 +119,7 @@ suite('install.sh options', () => { }); test('with a domain, Wings needs its own; without one, it needs none (and may not have one)', () => { - expect(dryRun([...BASE, '--wings']).out).toContain('--wings-domain is needed'); + expect(dryRun([...BASE, '--wings']).out).toContain('--wings-domain (or PELICAN_WINGS_DOMAIN) is needed'); expect(dryRun([...BASE, '--wings', '--wings-domain', 'panel.example.com']).out).toContain('Wings needs its own domain'); const ip = dryRun([...IP, '--wings']); expect(ip.code).toBe(0); @@ -96,10 +128,11 @@ suite('install.sh options', () => { expect(dryRun([...IP, '--wings', '--wings-domain', 'node.example.com']).out).toContain('--wings-domain needs --domain'); }); - test('without a terminal and without --yes it asks for --yes instead of guessing', () => { - const { code, out } = install(['--dry-run', ...BASE]); + test('--interactive without a terminal stops and says to pass the options instead', () => { + const { code, out } = install(['--dry-run', '--interactive', ...BASE]); expect(code).not.toBe(0); - expect(out).toContain('No terminal for questions'); + expect(out).toContain('--interactive needs a terminal'); + expect(install(['--dry-run', ...BASE], { PELICAN_INTERACTIVE: '1' }).out).toContain('--interactive needs a terminal'); }); }); @@ -147,6 +180,9 @@ suite('install.sh files', () => { expect(panel.deploy.labels).toBeUndefined(); expect(file.networks.public.ipam.config[0].subnet).toBe('${PUBLIC_SUBNET}'); expect(env.PUBLIC_SUBNET).toBe('10.203.250.0/24'); + // Traefik is pinned to an exact version (updates are deliberate), unless asked otherwise. + expect(env.TRAEFIK_IMAGE).toMatch(/^traefik:v\d+\.\d+\.\d+$/); + expect(settings(dryRun(BASE, undefined, { PELICAN_TRAEFIK_IMAGE: 'traefik:v3.6.25' }).dir).TRAEFIK_IMAGE).toBe('traefik:v3.6.25'); }); test('production: MariaDB and Redis on an internal network, with generated passwords', () => { @@ -198,7 +234,7 @@ suite('install.sh files', () => { test('the address ranges can be changed for networks that clash', () => { const dir = mkdtempSync(join(tmpdir(), 'pelican-install-')); - const result = install(['--dry-run', '--yes', '--dir', dir, ...BASE], { + const result = install(['--dry-run', '--dir', dir, ...BASE], { PELICAN_PUBLIC_SUBNET: '10.99.1.0/24', PELICAN_GWBRIDGE_SUBNET: '10.99.2.0/24', }); From 5dde76472562f9ed1c1da56d3f47fc6a3723d6b8 Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:28:03 +0200 Subject: [PATCH 5/5] fix(install): Macroscope's review: staging, Wings re-runs, saved subnet, dry runs, share image - Running again without --staging now moves a staging install to Let's Encrypt production (it kept the saved staging server). A CA set by hand is kept. Each CA gets its own certificate store (deploy.sh names it from LE_CA_SERVER), so staging certificates and the staging account don't carry over. - Re-running with Wings running no longer fails: the binary is downloaded to wings.new and renamed over the running one (writing to it gave "text file busy", curl exit 23, before the stack was deployed). - A second run keeps the PUBLIC_SUBNET saved in pelican.env (it reset it to 10.203.250.0/24, moving TRUSTED_PROXIES and the network) unless PELICAN_PUBLIC_SUBNET asks for another. - A dry run warns about example.com emails instead of stopping, so the docs' dry-run example works; a real run still refuses them. - The panel/install share image quotes lines that are on the page (it was dropped). New lib/og-motifs.test.mjs checks every motif against its page. Verified in the VM: a running /usr/local/bin/wings blocks the old download (curl exit 23) and not the new one; staging, then a run without --staging, switches caServer and the store to production. --- content/docs/panel/install.mdx | 2 +- lib/og-motifs.test.mjs | 28 ++++++++++++++++++ lib/og-motifs.ts | 4 +-- public/install.sh | 44 ++++++++++++++++++++++++---- scripts/install-sh.test.mjs | 52 +++++++++++++++++++++++++++++++--- 5 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 lib/og-motifs.test.mjs diff --git a/content/docs/panel/install.mdx b/content/docs/panel/install.mdx index a89539e0..2f79d991 100644 --- a/content/docs/panel/install.mdx +++ b/content/docs/panel/install.mdx @@ -168,7 +168,7 @@ docker service logs -f pelican_panel # the Panel's logs docker service logs pelican_traefik 2>&1 | grep -i acme # certificate problems ``` -No certificate? Check that the domain points at the server, ports 80 and 443 are reachable from the internet and the record isn't proxied by a CDN. Let's Encrypt limits how often it issues certificates for one domain: test with `--staging`, then run the script again without it. +No certificate? Check that the domain points at the server, ports 80 and 443 are reachable from the internet and the record isn't proxied by a CDN. Let's Encrypt limits how often it issues certificates for one domain: test with `--staging`, then run the script again without it, which moves the install to real certificates (the test ones are kept apart and not used again). Docker's address ranges can clash with a network your server is already on. The script uses `10.203.0.0/16` for Swarm and `10.204.0.0/24` for `docker_gwbridge`; set `PELICAN_SWARM_POOL`, `PELICAN_GWBRIDGE_SUBNET` and `PELICAN_PUBLIC_SUBNET` before running it to use others. diff --git a/lib/og-motifs.test.mjs b/lib/og-motifs.test.mjs new file mode 100644 index 00000000..bd149ee1 --- /dev/null +++ b/lib/og-motifs.test.mjs @@ -0,0 +1,28 @@ +// bun test lib/og-motifs.test.mjs +// Every share-image motif in lib/og-motifs.ts quotes text that is on its page: checkedMotif drops +// one that doesn't (only a warning in the build log), so the card would lose its picture quietly. +import { describe, expect, test } from 'bun:test'; +import { existsSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { checkedMotif, DOCS_MOTIFS } from './og-motifs.ts'; + +const DOCS = join(import.meta.dir, '..', 'content', 'docs'); + +/** The page's MDX for a motif key (the page's slugs joined with "/", "" for the docs index). */ +function pageSource(key) { + for (const file of [key ? `${key}.mdx` : 'index.mdx', join(key, 'index.mdx')]) { + const path = join(DOCS, file); + if (existsSync(path)) return readFileSync(path, 'utf8'); + } + return null; +} + +describe('share image motifs', () => { + for (const key of Object.keys(DOCS_MOTIFS)) { + test(`${key || '(index)'}: its page exists and still has the quoted text`, () => { + const mdx = pageSource(key); + expect(mdx).not.toBeNull(); + expect(checkedMotif(key, mdx)).toBeDefined(); + }); + } +}); diff --git a/lib/og-motifs.ts b/lib/og-motifs.ts index 0842f253..895c4390 100644 --- a/lib/og-motifs.ts +++ b/lib/og-motifs.ts @@ -99,9 +99,9 @@ export const DOCS_MOTIFS: Record = { label: 'sh', lang: 'sh', lines: [ + "# On the server's IP, with the defaults (the quick profile, no Wings)", 'curl -fsSL https://pelican.dev/install.sh | sudo bash', - '==> Docker Swarm, Traefik (HTTPS) and the Panel', - 'Finish the setup: https://panel.example.com/installer', + '# With a domain and HTTPS, MariaDB and Redis', ], }, diff --git a/public/install.sh b/public/install.sh index 77576306..7ab83092 100644 --- a/public/install.sh +++ b/public/install.sh @@ -240,6 +240,12 @@ setting() { printf '%s' "${saved[$1]:-}"; } load_settings +# A subnet chosen on the first run stays (the stack's network and TRUSTED_PROXIES use it), unless +# PELICAN_PUBLIC_SUBNET asks for another. +if [[ -z "${PELICAN_PUBLIC_SUBNET:-}" && -n "$(setting PUBLIC_SUBNET)" ]]; then + PUBLIC_SUBNET="$(setting PUBLIC_SUBNET)" +fi + # ---- Gather the options ---------------------------------------------------------------------- step "Pelican install (script v$VERSION)" $dry_run && info "Dry run: files go to $dir, nothing on this server changes." @@ -270,7 +276,12 @@ if [[ -n "$domain" ]]; then valid_email "$email" || die "\"$email\" isn't an email address." case "${email##*@}" in example.com | example.net | example.org | localhost) - die "Let's Encrypt refuses addresses at ${email##*@}: use a real email (it only sends certificate notices)." ;; + # A dry run only shows the plan, so the docs' placeholder works there; a real run stops. + if $dry_run; then + warn "Let's Encrypt refuses addresses at ${email##*@}: use a real email for the real run." + else + die "Let's Encrypt refuses addresses at ${email##*@}: use a real email (it only sends certificate notices)." + fi ;; esac fi @@ -314,11 +325,16 @@ else [[ "$with_wings" == yes ]] || wings_domain="" fi +# Let's Encrypt's server: staging only while --staging is passed (running again without it moves +# to real certificates); another CA set by hand in pelican.env is kept. le_server="$LE_PRODUCTION" +saved_ca="$(setting LE_CA_SERVER)" if $staging; then le_server="$LE_STAGING" -elif [[ -n "$(setting LE_CA_SERVER)" ]]; then - le_server="$(setting LE_CA_SERVER)" +elif [[ "$saved_ca" == "$LE_STAGING" ]]; then + info "Moving from Let's Encrypt staging to real certificates (no --staging this time)." +elif [[ -n "$saved_ca" ]]; then + le_server="$saved_ca" fi app_key="$(setting APP_KEY)" @@ -515,7 +531,8 @@ services: - --entryPoints.web.transport.respondingTimeouts.readTimeout=600s - --entryPoints.websecure.transport.respondingTimeouts.readTimeout=600s - --certificatesResolvers.letsencrypt.acme.email=${LE_EMAIL} - - --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/acme.json + # One store per CA (deploy.sh names it), so test certificates never outlive --staging. + - --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/${ACME_STORAGE} - --certificatesResolvers.letsencrypt.acme.caServer=${LE_CA_SERVER} - --certificatesResolvers.letsencrypt.acme.httpChallenge.entryPoint=web - --ping=true @@ -680,6 +697,15 @@ set -a set +a export PELICAN_DIR="$PWD" +# Traefik keeps certificates and its account per CA: production in acme.json, any other CA +# (staging) in a file of its own, so switching CAs starts clean. +if [[ "${LE_CA_SERVER:-}" == "https://acme-v02.api.letsencrypt.org/directory" || -z "${LE_CA_SERVER:-}" ]]; then + export ACME_STORAGE="acme.json" +else + ACME_STORAGE="acme-$(sed -E 's#^https?://##; s#[^A-Za-z0-9.-]+#-#g; s#-+$##' <<<"$LE_CA_SERVER").json" + export ACME_STORAGE +fi + # The Panel's address: its domain with HTTPS, or the server's IP over HTTP until it has one. if [[ -n "${PANEL_DOMAIN:-}" ]]; then if [[ -z "${LE_EMAIL:-}" ]]; then @@ -775,8 +801,14 @@ if [[ "$with_wings" == yes ]]; then step "Wings" wings_arch="${arch:-amd64}" run mkdir -p /etc/pelican /var/run/wings - run curl -fsSL -o /usr/local/bin/wings "$WINGS_RELEASES/wings_linux_$wings_arch" - run chmod u+x /usr/local/bin/wings + # Download beside it and rename over it: a running Wings' file can't be written ("text file + # busy"), but it can be replaced. The running Wings keeps its version until it restarts. + run curl -fsSL -o /usr/local/bin/wings.new "$WINGS_RELEASES/wings_linux_$wings_arch" + run chmod u+x /usr/local/bin/wings.new + run mv -f /usr/local/bin/wings.new /usr/local/bin/wings + if ! $dry_run && systemctl is-active --quiet wings 2>/dev/null; then + info "Wings is running: systemctl restart wings starts the version just downloaded." + fi if $dry_run; then info "Would write /etc/systemd/system/wings.service (the unit from the docs: wings/install)." else diff --git a/scripts/install-sh.test.mjs b/scripts/install-sh.test.mjs index 8dbe6555..8f497344 100644 --- a/scripts/install-sh.test.mjs +++ b/scripts/install-sh.test.mjs @@ -114,8 +114,15 @@ suite('install.sh options', () => { expect(dryRun(['--domain', 'panel.example.com', '--email', "o'brien@example.com"]).out).toContain("isn't an email"); expect(dryRun([...BASE, '--profile', 'enterprise']).out).toContain('--profile is quick or production'); expect(dryRun(['--ip', '300.1.2.3']).out).toContain("isn't an IPv4 address"); - // Let's Encrypt refuses contacts at example.com (seen on a real run), so it's caught up front. - expect(dryRun(['--domain', 'panel.example.com', '--email', 'admin@example.com']).out).toContain("Let's Encrypt refuses addresses at example.com"); + // Let's Encrypt refuses contacts at example.com (seen on a real run): a real run stops before + // touching anything (here as non-root, it stops at that check, before the root check)... + const real = install(['--dir', mkdtempSync(join(tmpdir(), 'pelican-install-')), '--domain', 'panel.example.com', '--email', 'admin@example.com']); + expect(real.code).not.toBe(0); + expect(real.out).toContain("Let's Encrypt refuses addresses at example.com"); + // ...while a dry run, which only shows the plan, warns and goes on (the docs' example uses it). + const preview = dryRun(['--domain', 'panel.example.com', '--email', 'you@example.com']); + expect(preview.code).toBe(0); + expect(preview.out).toContain('use a real email for the real run'); }); test('with a domain, Wings needs its own; without one, it needs none (and may not have one)', () => { @@ -227,9 +234,38 @@ suite('install.sh files', () => { expect(switched.out).toContain('uses the production profile'); }); - test("--staging uses Let's Encrypt staging", () => { + test("--staging uses Let's Encrypt staging; running again without it goes back to real certificates", () => { const { dir } = dryRun([...BASE, '--staging']); expect(settings(dir).LE_CA_SERVER).toBe('https://acme-staging-v02.api.letsencrypt.org/directory'); + expect(dryRun([...BASE, '--staging'], dir).code).toBe(0); + expect(settings(dir).LE_CA_SERVER).toBe('https://acme-staging-v02.api.letsencrypt.org/directory'); + + const again = dryRun([], dir); + expect(again.out).toContain('Moving from Let\'s Encrypt staging to real certificates'); + expect(settings(dir).LE_CA_SERVER).toBe('https://acme-v02.api.letsencrypt.org/directory'); + }); + + test('another CA set by hand in pelican.env is kept on a second run', () => { + const { dir } = dryRun(BASE); + const file = join(dir, 'pelican.env'); + writeFileSync(file, readFileSync(file, 'utf8').replace(/^LE_CA_SERVER=.*$/m, "LE_CA_SERVER='https://acme.zerossl.com/v2/DV90'")); + expect(dryRun([], dir).code).toBe(0); + expect(settings(dir).LE_CA_SERVER).toBe('https://acme.zerossl.com/v2/DV90'); + }); + + test('a second run keeps the public subnet chosen on the first, unless PELICAN_PUBLIC_SUBNET says otherwise', () => { + const { dir } = dryRun(IP, undefined, { PELICAN_PUBLIC_SUBNET: '10.99.1.0/24' }); + expect(dryRun([], dir).code).toBe(0); + expect(settings(dir).PUBLIC_SUBNET).toBe('10.99.1.0/24'); + expect(dryRun([], dir, { PELICAN_PUBLIC_SUBNET: '10.99.3.0/24' }).code).toBe(0); + expect(settings(dir).PUBLIC_SUBNET).toBe('10.99.3.0/24'); + }); + + test('Wings is downloaded beside the binary and renamed over it (a running one can be replaced, not written)', () => { + const { out } = dryRun([...IP, '--wings']); + expect(out).toContain('-o /usr/local/bin/wings.new'); + expect(out).toContain('mv -f /usr/local/bin/wings.new /usr/local/bin/wings'); + expect(out).not.toContain('-o /usr/local/bin/wings '); }); test('the address ranges can be changed for networks that clash', () => { @@ -252,7 +288,7 @@ suite('deploy.sh', () => { const record = join(bin, 'calls'); writeFileSync( join(bin, 'docker'), - `#!/bin/sh\n{ echo "ARGS $*"; echo "PANEL_URL=$PANEL_URL"; echo "PELICAN_DIR=$PELICAN_DIR"; echo "APP_KEY_SET=\${APP_KEY:+yes}"; } >> "${record}"\n`, + `#!/bin/sh\n{ echo "ARGS $*"; echo "PANEL_URL=$PANEL_URL"; echo "PELICAN_DIR=$PELICAN_DIR"; echo "ACME_STORAGE=$ACME_STORAGE"; echo "APP_KEY_SET=\${APP_KEY:+yes}"; } >> "${record}"\n`, ); chmodSync(join(bin, 'docker'), 0o755); const result = Bun.spawnSync([BASH, join(dir, 'deploy.sh')], { env: { PATH: `${bin}:${process.env.PATH}` } }); @@ -287,6 +323,7 @@ suite('deploy.sh', () => { const { code, calls } = deploy(dir); expect(code).toBe(0); expect(calls).toContain('PANEL_URL=https://panel.example.com'); + expect(calls).toContain('ACME_STORAGE=acme.json'); const http = routes(dir); expect(http.routers['pelican-panel']).toEqual({ @@ -303,6 +340,13 @@ suite('deploy.sh', () => { expect(http.routers['pelican-wings']).toBeUndefined(); }); + test('certificates are kept per CA: staging gets its own store, so its test certificates go with it', () => { + const { dir } = dryRun([...BASE, '--staging']); + expect(deploy(dir).calls).toContain('ACME_STORAGE=acme-acme-staging-v02.api.letsencrypt.org-directory.json'); + dryRun([], dir); // without --staging: back to Let's Encrypt's production server + expect(deploy(dir).calls).toContain('ACME_STORAGE=acme.json'); + }); + test('adding a domain later: set it in pelican.env and deploy again', () => { const { dir } = dryRun(IP); const file = join(dir, 'pelican.env');