Update deploy.sh for Cloud Run architecture
Remove stale Redis/worker references, add Cloud Run and rate_limits config. Comment out git pull section for manual control. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4080638856
commit
0ef03f977b
1 changed files with 26 additions and 25 deletions
51
deploy.sh
51
deploy.sh
|
|
@ -7,8 +7,8 @@
|
|||
#
|
||||
# Architecture:
|
||||
# - Apache (host) serves frontend + api.php from /var/www/html/pdf-accessibility
|
||||
# - Docker Compose runs: worker (Python), Redis, PostgreSQL
|
||||
# - Redis/PostgreSQL exposed on localhost for api.php access
|
||||
# - Docker Compose runs: PostgreSQL
|
||||
# - PDF processing via Google Cloud Run (synchronous HTTP call from api.php)
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
|
|
@ -52,16 +52,16 @@ fi
|
|||
# Check PHP
|
||||
if ! command -v php &>/dev/null; then
|
||||
warn "PHP is not installed. api.php requires PHP ${MIN_PHP_VERSION}+ with extensions:"
|
||||
warn " sudo apt-get install php8.2 php8.2-redis php8.2-pgsql php8.2-curl php8.2-mbstring"
|
||||
warn " sudo apt-get install php8.2 php8.2-pgsql php8.2-curl php8.2-mbstring"
|
||||
else
|
||||
PHP_VER=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')
|
||||
log "PHP version: ${PHP_VER}"
|
||||
|
||||
# Check required extensions
|
||||
MISSING_EXT=""
|
||||
php -m | grep -qi redis || MISSING_EXT="${MISSING_EXT} php-redis"
|
||||
php -m | grep -qi pgsql || MISSING_EXT="${MISSING_EXT} php-pgsql"
|
||||
php -m | grep -qi curl || MISSING_EXT="${MISSING_EXT} php-curl"
|
||||
php -m | grep -qi openssl || MISSING_EXT="${MISSING_EXT} php-openssl"
|
||||
|
||||
if [ -n "${MISSING_EXT}" ]; then
|
||||
warn "Missing PHP extensions:${MISSING_EXT}"
|
||||
|
|
@ -70,17 +70,21 @@ else
|
|||
fi
|
||||
|
||||
# ── Pull Latest Code ─────────────────────────────────────────────
|
||||
# Run `git pull` manually before running this script.
|
||||
|
||||
# log "Pulling latest code..."
|
||||
# cd "${REPO_DIR}"
|
||||
#
|
||||
# if [ -d .git ]; then
|
||||
# git fetch --all
|
||||
# git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)
|
||||
# log "Code updated to $(git log --oneline -1)"
|
||||
# else
|
||||
# warn "Not a git repo — using existing files"
|
||||
# fi
|
||||
|
||||
log "Pulling latest code..."
|
||||
cd "${REPO_DIR}"
|
||||
|
||||
if [ -d .git ]; then
|
||||
git fetch --all
|
||||
git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)
|
||||
log "Code updated to $(git log --oneline -1)"
|
||||
else
|
||||
warn "Not a git repo — using existing files"
|
||||
fi
|
||||
log "Using current code at $(git log --oneline -1 2>/dev/null || echo 'unknown')"
|
||||
|
||||
# ── Environment File ─────────────────────────────────────────────
|
||||
|
||||
|
|
@ -89,15 +93,15 @@ if [ ! -f "${ENV_FILE}" ]; then
|
|||
cp "${REPO_DIR}/.env.example" "${ENV_FILE}"
|
||||
|
||||
# Override Docker hostnames with localhost for host-side PHP
|
||||
# (Worker uses Docker internal names via docker-compose.prod.yml)
|
||||
sed -i 's/^DB_HOST=postgres/DB_HOST=127.0.0.1/' "${ENV_FILE}"
|
||||
sed -i 's/^REDIS_HOST=redis/REDIS_HOST=127.0.0.1/' "${ENV_FILE}"
|
||||
sed -i 's/^DEV_MODE=true/DEV_MODE=false/' "${ENV_FILE}"
|
||||
|
||||
warn "Review and update ${ENV_FILE} with production values:"
|
||||
warn " - DB_PASSWORD (change from default!)"
|
||||
warn " - ANTHROPIC_API_KEY"
|
||||
warn " - GOOGLE_API_KEY"
|
||||
warn " - CLOUD_RUN_URL"
|
||||
warn " - GCP_SA_KEY_PATH (copy pdf-api-invoker-key.json to server)"
|
||||
warn " - AZURE_* settings"
|
||||
else
|
||||
log "Using existing .env file"
|
||||
|
|
@ -179,12 +183,12 @@ else
|
|||
fi
|
||||
|
||||
# Create runtime directories
|
||||
sudo mkdir -p "${WEB_DIR}/uploads" "${WEB_DIR}/results" "${WEB_DIR}/logs"
|
||||
sudo mkdir -p "${WEB_DIR}/uploads" "${WEB_DIR}/results" "${WEB_DIR}/logs" "${WEB_DIR}/rate_limits"
|
||||
|
||||
# Set ownership for Apache
|
||||
sudo chown -R www-data:www-data "${WEB_DIR}"
|
||||
sudo chmod -R 755 "${WEB_DIR}"
|
||||
sudo chmod -R 775 "${WEB_DIR}/uploads" "${WEB_DIR}/results" "${WEB_DIR}/logs"
|
||||
sudo chmod -R 775 "${WEB_DIR}/uploads" "${WEB_DIR}/results" "${WEB_DIR}/logs" "${WEB_DIR}/rate_limits"
|
||||
|
||||
# ── Verify ────────────────────────────────────────────────────────
|
||||
|
||||
|
|
@ -196,22 +200,19 @@ log ""
|
|||
log "Services status:"
|
||||
docker compose -f "${COMPOSE_FILE}" ps --format "table {{.Name}}\t{{.Status}}\t{{.Ports}}"
|
||||
log ""
|
||||
log "Frontend: ${WEB_DIR}"
|
||||
log "Docker: worker + Redis (127.0.0.1:6379) + PostgreSQL (127.0.0.1:5432)"
|
||||
log "Frontend: ${WEB_DIR}"
|
||||
log "Docker: PostgreSQL (127.0.0.1:1221)"
|
||||
log "Cloud Run: ${CLOUD_RUN_URL:-$(grep '^CLOUD_RUN_URL=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2 || echo 'not set')}"
|
||||
log ""
|
||||
|
||||
# Quick health check
|
||||
if curl -sf http://127.0.0.1:6379 &>/dev/null || redis-cli -h 127.0.0.1 ping &>/dev/null 2>&1; then
|
||||
log "Redis: OK"
|
||||
fi
|
||||
|
||||
if docker compose -f "${COMPOSE_FILE}" exec -T postgres pg_isready -U pdf_checker &>/dev/null; then
|
||||
log "PostgreSQL: OK"
|
||||
fi
|
||||
|
||||
log ""
|
||||
log "Next steps:"
|
||||
log " 1. Configure Apache vhost for https://ai-sandbox.oliver.solutions/pdf-accessibility"
|
||||
log " 2. Review ${WEB_DIR}/.env (especially DB_PASSWORD and API keys)"
|
||||
log " 1. Ensure pdf-api-invoker-key.json is at the GCP_SA_KEY_PATH location"
|
||||
log " 2. Review ${WEB_DIR}/.env (especially CLOUD_RUN_URL and API keys)"
|
||||
log " 3. Restart Apache: sudo systemctl reload apache2"
|
||||
log ""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue