Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

standalone-deploy.sh

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

standalone-deploy.shBlame153 lines · 1 contributor
95e33b0Claude1#!/usr/bin/env bash
2#
3# Standalone single-box deploy for Gluecron on a DEDICATED VPS.
4# Brings up Gluecron + Postgres(pgvector) + Caddy(auto-HTTPS) with one command.
5#
6# Usage (as root on a fresh Ubuntu box):
9de2807Claude7# curl -fsSL https://raw.githubusercontent.com/ccantynz-alt/Gluecron.com/main/scripts/standalone-deploy.sh | bash
95e33b0Claude8# or, after cloning:
9# bash scripts/standalone-deploy.sh
10#
11# To migrate existing data: copy a dump to /root/gluecron.sql.gz BEFORE running
12# (e.g. `scp` it from the old box). The script restores it automatically.
13set -euo pipefail
14
15REPO_URL="https://github.com/ccantynz-alt/Gluecron.com.git"
9de2807Claude16REPO_BRANCH="main"
95e33b0Claude17REPO_DIR="/opt/gluecron"
18COMPOSE="docker compose -f docker-compose.standalone.yml"
19
20echo "== Gluecron standalone deploy =="
21
22# 1. Docker
23if ! command -v docker >/dev/null 2>&1; then
24 echo "-- installing Docker"
25 curl -fsSL https://get.docker.com | sh
26fi
27
6b603a3Claude28# 2. Code (the standalone compose file lives on $REPO_BRANCH)
95e33b0Claude29if [ ! -d "$REPO_DIR/.git" ]; then
6b603a3Claude30 echo "-- cloning $REPO_URL ($REPO_BRANCH)"
31 git clone -b "$REPO_BRANCH" "$REPO_URL" "$REPO_DIR"
95e33b0Claude32fi
33cd "$REPO_DIR"
6b603a3Claude34git fetch origin "$REPO_BRANCH" 2>/dev/null || true
35git checkout "$REPO_BRANCH" 2>/dev/null || true
36git pull --ff-only origin "$REPO_BRANCH" 2>/dev/null || true
95e33b0Claude37
38# 3. Env (random Postgres password on first run)
39if [ ! -f .env ]; then
40 echo "POSTGRES_PASSWORD=$(openssl rand -hex 24)" > .env
41 echo "ANTHROPIC_API_KEY=" >> .env
42 echo "-- generated .env (random Postgres password; add ANTHROPIC_API_KEY later if you want AI features)"
43fi
44
45# 4. Firewall (best-effort; only ports we need)
46if command -v ufw >/dev/null 2>&1; then
47 ufw allow 22/tcp >/dev/null 2>&1 || true
48 ufw allow 80/tcp >/dev/null 2>&1 || true
49 ufw allow 443/tcp >/dev/null 2>&1 || true
50fi
51
52# 5. Database first
53echo "-- starting Postgres"
54$COMPOSE up -d postgres
55echo "-- waiting for Postgres to accept connections"
56until $COMPOSE exec -T postgres pg_isready -U gluecron -d gluecron >/dev/null 2>&1; do sleep 2; done
57
58# 6. Restore prior data if a dump is present
59if [ -f /root/gluecron.sql.gz ]; then
60 echo "-- restoring data from /root/gluecron.sql.gz"
61 gunzip -c /root/gluecron.sql.gz | $COMPOSE exec -T postgres psql -U gluecron -d gluecron >/dev/null
62elif [ -f /root/gluecron.sql ]; then
63 echo "-- restoring data from /root/gluecron.sql"
64 $COMPOSE exec -T postgres psql -U gluecron -d gluecron < /root/gluecron.sql >/dev/null
65else
66 echo "-- no dump found at /root/gluecron.sql(.gz); starting with a fresh database"
67fi
68
69# 7. App + Caddy
70echo "-- building and starting Gluecron + Caddy"
71$COMPOSE up -d --build
72
73# 8. Migrations (idempotent — safe whether restored or fresh)
74echo "-- applying migrations"
75sleep 5
76$COMPOSE exec -T gluecron bun run db:migrate || true
77
f635e2fClaude78# 9. Swap (protects a small box from OOM kills)
79if [ "$(swapon --show --noheadings | wc -l)" -eq 0 ]; then
80 echo "-- creating 1G swap file"
81 fallocate -l 1G /swapfile && chmod 600 /swapfile && mkswap /swapfile >/dev/null && swapon /swapfile
82 grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab
83fi
84
85# 10. Unattended security updates
86echo "-- enabling unattended-upgrades"
87DEBIAN_FRONTEND=noninteractive apt-get install -y unattended-upgrades >/dev/null 2>&1 || true
88dpkg-reconfigure -f noninteractive unattended-upgrades >/dev/null 2>&1 || true
89
90# 11. Self-managing systemd timers: fast auto-deploy (~60s) + daily backup
91chmod +x scripts/auto-update.sh scripts/backup.sh
92
93cat > /etc/systemd/system/gluecron-update.service <<EOF
94[Unit]
95Description=Gluecron auto-deploy (pull + rebuild on new commits)
96After=docker.service
97Requires=docker.service
98[Service]
99Type=oneshot
100WorkingDirectory=$REPO_DIR
101EnvironmentFile=-$REPO_DIR/.env
102ExecStart=$REPO_DIR/scripts/auto-update.sh
103EOF
104
105cat > /etc/systemd/system/gluecron-update.timer <<EOF
106[Unit]
107Description=Run Gluecron auto-deploy every minute
108[Timer]
109OnBootSec=2min
110OnUnitActiveSec=60s
111[Install]
112WantedBy=timers.target
113EOF
114
115cat > /etc/systemd/system/gluecron-backup.service <<EOF
116[Unit]
117Description=Gluecron daily Postgres backup
118After=docker.service
119Requires=docker.service
120[Service]
121Type=oneshot
122WorkingDirectory=$REPO_DIR
123EnvironmentFile=-$REPO_DIR/.env
124ExecStart=$REPO_DIR/scripts/backup.sh
125EOF
126
127cat > /etc/systemd/system/gluecron-backup.timer <<EOF
128[Unit]
129Description=Run Gluecron backup daily
130[Timer]
131OnCalendar=daily
132Persistent=true
133[Install]
134WantedBy=timers.target
135EOF
136
137systemctl daemon-reload
138systemctl enable --now gluecron-update.timer gluecron-backup.timer >/dev/null 2>&1 || true
139
95e33b0Claude140echo
141echo "== status =="
142$COMPOSE ps
f635e2fClaude143echo "-- timers --"
144systemctl list-timers 'gluecron-*' --no-pager 2>/dev/null || true
145echo
146echo "Self-healing active: container auto-restart, autoheal, log rotation,"
147echo "1G swap, unattended security updates, daily DB backups (backups/), and"
148echo "auto-deploy (~60s) from the deploy branch."
95e33b0Claude149echo
150echo "Done. Now point gluecron.com + www.gluecron.com DNS at THIS box's IP"
151echo "(Cloudflare, DNS-only / grey cloud). Caddy issues the cert automatically"
152echo "within ~1 minute of DNS resolving here. Verify with:"
153echo " curl -sI https://gluecron.com/healthz"