social-reporting-tool/v2/deploy/deploy-v2.sh
DJP 7024acfdf0 deploy: chown briefs/ to uid 1000 so container can write per-report dirs
The V2 container runs as uid 1000 (Dockerfile.v2:39 USER 1000). When the
pipeline tried to mkdir briefs/<brief-id>/ on the production server, it hit
EACCES because the host directory was owned by root (V1 had a similar fix
in deploy.sh that we never ported).

- cutover-in-place.sh: chown -R 1000:1000 briefs/ before docker up.
- deploy-v2.sh: same chown on every redeploy + use --env-file (was missing).

Immediate manual fix on the running server (until next deploy):
  sudo chown -R 1000:1000 /opt/social-reporting/briefs

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 20:06:56 -04:00

34 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
# Routine V2 redeploy (after `git pull`). Run from anywhere on the server.
BACKEND_DIR_V2="/opt/social-reporting-v2"
GREEN='\033[0;32m'; RED='\033[0;31m'; NC='\033[0m'
log() { echo -e "${GREEN}[+]${NC} $1"; }
err() { echo -e "${RED}[x]${NC} $1"; exit 1; }
cd "$BACKEND_DIR_V2" || err "V2 dir not found: $BACKEND_DIR_V2"
log "Pulling latest..."
git pull origin main
# Fix briefs/ ownership in case sudo/root touched it. The container runs as uid 1000.
log "Refreshing briefs/ ownership..."
sudo mkdir -p "$BACKEND_DIR_V2/briefs"
sudo chown -R 1000:1000 "$BACKEND_DIR_V2/briefs"
log "Rebuilding V2 stack..."
docker compose -f v2/docker-compose.v2.yml -f v2/docker-compose.v2.prod.yml --env-file v2/.env up -d --build
log "Waiting for backend..."
for i in {1..30}; do
curl -sf http://127.0.0.1:3457/api/health >/dev/null 2>&1 && { log "Healthy"; break; }
[ "$i" -eq 30 ] && err "Backend not responding — docker compose -p social-reporting-v2 logs app-v2"
sleep 2
done
log "Reloading Apache..."
sudo systemctl reload apache2
echo -e "${GREEN}Deploy complete.${NC}"