deploy/systemd/: - news-frontend.service (Astro SSR :4321) - news-bridge.service (Fastify :3200) - news-wordpress.service (Docker Compose wrapper) - frontend.env.example + bridge.env.example deploy/nginx/: - newsproject.bitreport.pt.conf (reverse proxy → :4321, /api/ → :3200) - Nginx config validated OK on CT 222 deploy/scripts/: - deploy.sh — full from-scratch deploy (clone, build, install, start) - webhook-deploy.sh — incremental deploy on git push (cron-friendly) Tested on CT 222 (10.10.50.140): - nginx -t → OK - systemd units installed (news-frontend/bridge/wordpress) - news-wordpress enabled; frontend/bridge pending Astro build Remaining manual steps: - DHCP reservation for 10.10.50.140 - NPM proxy host: newsproject.bitreport.pt → http://10.10.50.140 - Run deploy.sh after bridge.env and frontend.env are configured Co-Authored-By: Paperclip <[email protected]> Made-with: Cursor
104 lines
3.0 KiB
Bash
Executable File
104 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Full deployment script for news-platform on CT 222 (news-project-test)
|
|
# Run as root on the LXC: bash deploy/scripts/deploy.sh
|
|
set -euo pipefail
|
|
|
|
APP_DIR="/opt/news-platform"
|
|
REPO_URL="https://git.bitreport.pt/BitReport.pt/news-platform.git"
|
|
ENV_DIR="/etc/news-platform"
|
|
|
|
log() { echo "[deploy] $*"; }
|
|
|
|
# --- Ensure directories ---
|
|
log "Creating directories..."
|
|
mkdir -p "$APP_DIR" "$ENV_DIR"
|
|
|
|
# --- Clone or update repo ---
|
|
if [ -d "$APP_DIR/.git" ]; then
|
|
log "Updating repo..."
|
|
git -C "$APP_DIR" fetch origin main
|
|
git -C "$APP_DIR" reset --hard origin/main
|
|
else
|
|
log "Cloning repo..."
|
|
git clone "$REPO_URL" "$APP_DIR"
|
|
fi
|
|
|
|
# --- Build bridge ---
|
|
log "Installing bridge dependencies..."
|
|
cd "$APP_DIR/bridge"
|
|
npm ci --omit=dev
|
|
npm run build
|
|
|
|
# --- Build frontend ---
|
|
log "Installing frontend dependencies..."
|
|
cd "$APP_DIR/frontend"
|
|
npm ci --omit=dev
|
|
npm run build
|
|
|
|
# --- WordPress (Docker) ---
|
|
log "Starting WordPress stack..."
|
|
cd "$APP_DIR/wordpress"
|
|
if [ ! -f .env ]; then
|
|
echo "ERROR: /opt/news-platform/wordpress/.env not found."
|
|
echo "Copy .env.example to .env and fill in credentials before running this script."
|
|
exit 1
|
|
fi
|
|
docker compose up -d --remove-orphans
|
|
|
|
# --- Environment files ---
|
|
log "Checking environment files..."
|
|
for svc in frontend bridge; do
|
|
target="$ENV_DIR/$svc.env"
|
|
example="$APP_DIR/deploy/systemd/$svc.env.example"
|
|
if [ ! -f "$target" ]; then
|
|
cp "$example" "$target"
|
|
log "Created $target from example — review and update values."
|
|
fi
|
|
done
|
|
|
|
# --- Systemd units ---
|
|
log "Installing systemd units..."
|
|
for unit in news-frontend news-bridge news-wordpress; do
|
|
src="$APP_DIR/deploy/systemd/$unit.service"
|
|
dst="/etc/systemd/system/$unit.service"
|
|
if [ -f "$src" ]; then
|
|
cp "$src" "$dst"
|
|
log " Installed $dst"
|
|
fi
|
|
done
|
|
systemctl daemon-reload
|
|
|
|
# --- Nginx ---
|
|
log "Installing Nginx config..."
|
|
NGINX_CONF="/etc/nginx/sites-available/newsproject.bitreport.pt.conf"
|
|
NGINX_LINK="/etc/nginx/sites-enabled/newsproject.bitreport.pt.conf"
|
|
cp "$APP_DIR/deploy/nginx/newsproject.bitreport.pt.conf" "$NGINX_CONF"
|
|
ln -sf "$NGINX_CONF" "$NGINX_LINK"
|
|
nginx -t
|
|
systemctl reload nginx
|
|
|
|
# --- Enable and start services ---
|
|
log "Enabling and starting services..."
|
|
for svc in news-wordpress news-bridge news-frontend; do
|
|
systemctl enable "$svc"
|
|
systemctl restart "$svc"
|
|
systemctl is-active "$svc" && log " $svc: active" || log " WARNING: $svc failed to start"
|
|
done
|
|
|
|
# --- Ownership ---
|
|
chown -R www-data:www-data "$APP_DIR/frontend/dist" 2>/dev/null || true
|
|
chown -R www-data:www-data "$APP_DIR/bridge/dist" 2>/dev/null || true
|
|
|
|
log ""
|
|
log "=== Deployment complete ==="
|
|
log "Frontend: http://localhost:4321"
|
|
log "Bridge: http://localhost:3200/health"
|
|
log "WordPress: http://localhost:8080/wp-json/wp/v2/"
|
|
log "Nginx: http://localhost/"
|
|
log ""
|
|
log "Remaining manual steps:"
|
|
log " 1. Add DHCP reservation for 10.10.50.140 on the router"
|
|
log " 2. Configure NPM proxy host: newsproject.bitreport.pt → http://10.10.50.140"
|
|
log " 3. Enable HTTPS in NPM (Let's Encrypt)"
|
|
log " 4. Review $ENV_DIR/frontend.env and $ENV_DIR/bridge.env"
|