Files
news-platform/deploy/scripts/deploy.sh
José AlvesandPaperclip f37d4f7318
Tests / writer-pipeline tests (push) Successful in 40s
Tests / bridge tests (push) Successful in 39s
Tests / frontend lib tests (push) Successful in 38s
Tests / writer-pipeline tests (pull_request) Successful in 47s
Tests / bridge tests (pull_request) Successful in 48s
Tests / frontend lib tests (pull_request) Successful in 49s
fix(devops): wp-login ops-only gate + smoke for branded auth (BIT-26754)
- Nginx: add auth_basic gate on wp-login.php (ops htpasswd, BIT-26754)
- deploy.sh: note htpasswd step 5 in post-deploy manual steps
- smoke-andebol.sh: update /entrar+/registar checks to verify branded
  Astro 200 (no WordPress strings); add wp-login.php 401/403 gate check;
  add /api/homepage latest ≥24 density check (BIT-26752)

Co-Authored-By: Paperclip <[email protected]>
2026-07-17 09:18:47 +00:00

141 lines
5.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
set +e
bash "$APP_DIR/deploy/scripts/wordpress-ensure-public-url.sh"
_wp_pub=$?
set -e
docker compose up -d --remove-orphans
if [ "$_wp_pub" -eq 2 ]; then
log "WORDPRESS_PUBLIC_URL was corrected — recreating wordpress + nginx containers..."
docker compose up -d --force-recreate wordpress nginx
fi
bash "$APP_DIR/deploy/scripts/wordpress-sync-options-url.sh" || log "wordpress-sync-options-url skipped (db not ready or still local URL)"
# --- Environment files ---
log "Checking environment files..."
for svc in frontend bridge healthcheck; 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 news-healthcheck news-alert@; 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
# Install healthcheck timer
if [ -f "$APP_DIR/deploy/systemd/news-healthcheck.timer" ]; then
cp "$APP_DIR/deploy/systemd/news-healthcheck.timer" /etc/systemd/system/news-healthcheck.timer
log " Installed /etc/systemd/system/news-healthcheck.timer"
fi
systemctl daemon-reload
# --- Nginx ---
log "Installing Nginx config..."
mkdir -p /etc/nginx/conf.d
MAP_SRC="$APP_DIR/deploy/nginx/conf.d/99-news-platform-wp-map.conf"
MAP_DST="/etc/nginx/conf.d/99-news-platform-wp-map.conf"
if [ -f "$MAP_SRC" ]; then
cp "$MAP_SRC" "$MAP_DST"
log " Installed $MAP_DST (Host → WordPress port)"
fi
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"
# Debian/Ubuntu default site catches requests when no server_name matches — remove so our default_server vhost wins
rm -f /etc/nginx/sites-enabled/default
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
# --- Health monitoring ---
log "Enabling health-check timer..."
chmod +x "$APP_DIR/deploy/scripts/healthcheck.sh"
systemctl enable news-healthcheck.timer
systemctl start news-healthcheck.timer
systemctl is-active news-healthcheck.timer && log " news-healthcheck.timer: active" || log " WARNING: health-check timer failed to start"
# --- 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
mkdir -p "$APP_DIR/bridge/config/writers"
chown www-data:www-data "$APP_DIR/bridge/config/writers"
mkdir -p "$APP_DIR/writer-pipeline/var"
chown -R www-data:www-data "$APP_DIR/writer-pipeline/var"
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. IP 10.10.50.204 is static (BIT-24053: systemd-networkd + PVE config; MAC BC:24:11:77:5B:E6) — no DHCP reservation needed"
log " 2. Configure NPM proxy host: newsproject.bitreport.pt → http://10.10.50.204 (NPM proxy #20)"
log " 3. Enable HTTPS in NPM (Let's Encrypt)"
log " 4. Review $ENV_DIR/frontend.env and $ENV_DIR/bridge.env"
log " 5. Create /etc/nginx/wp-ops.htpasswd for ops-only wp-login gate (BIT-26754):"
log " htpasswd -c -B /etc/nginx/wp-ops.htpasswd wp-ops"
log " Save the password in the team vault. Never commit it to git."