| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #!/usr/bin/env bash
- # CelestiaTrace frontend deployment.
- # This updates only the frontend service and never runs docker compose down.
- set -Eeuo pipefail
- SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
- REPO_DIR="$(dirname "$SCRIPT_DIR")"
- SERVER_IP="47.93.193.127"
- PEM_KEY="$REPO_DIR/ccdw-meishi-1.pem"
- REMOTE_DIR="/opt/celestia-trace-frontend"
- SSH_USER="root"
- COMPOSE_PROJECT="celestia-trace-frontend"
- PROXY_DIR="/opt/meishi_ccdw_life"
- PROXY_CONTAINER="meishi_ccdw_life-proxy-1"
- PROXY_CONFIG="$REPO_DIR/remote_nginx.conf"
- API_BASE_URL="https://api.ccdw.life/celestia-trace/v1"
- PUBLIC_URL="http://c.lessncosmos.com"
- SSH_OPTS=(-i "$PEM_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new)
- if [[ ! -f "$PEM_KEY" ]]; then
- echo "SSH key not found: $PEM_KEY" >&2
- exit 1
- fi
- if [[ ! -f "$PROXY_CONFIG" ]]; then
- echo "Nginx config not found: $PROXY_CONFIG" >&2
- exit 1
- fi
- chmod 400 "$PEM_KEY"
- ssh "${SSH_OPTS[@]}" "$SSH_USER@$SERVER_IP" "mkdir -p '$REMOTE_DIR'"
- rsync -avz --delete \
- --exclude '.git' \
- --exclude '.env' \
- --exclude 'node_modules' \
- --exclude 'dist' \
- -e "ssh -i $PEM_KEY -o BatchMode=yes -o StrictHostKeyChecking=accept-new" \
- "$SCRIPT_DIR/" "$SSH_USER@$SERVER_IP:$REMOTE_DIR/"
- ssh "${SSH_OPTS[@]}" "$SSH_USER@$SERVER_IP" << REMOTE_CMDS
- set -Eeuo pipefail
- cd "$REMOTE_DIR"
- export VITE_API_BASE_URL="$API_BASE_URL"
- docker compose -p "$COMPOSE_PROJECT" config --quiet
- docker compose -p "$COMPOSE_PROJECT" up -d --build --no-deps frontend
- for attempt in \$(seq 1 30); do
- health=\$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' celestia-frontend)
- if [[ "\$health" == "healthy" ]]; then
- docker compose -p "$COMPOSE_PROJECT" ps frontend
- exit 0
- fi
- if [[ "\$health" == "unhealthy" || "\$health" == "exited" ]]; then
- docker logs --tail 100 celestia-frontend
- exit 1
- fi
- sleep 2
- done
- echo "Frontend health check timed out" >&2
- docker logs --tail 100 celestia-frontend
- exit 1
- REMOTE_CMDS
- scp "${SSH_OPTS[@]}" "$PROXY_CONFIG" "$SSH_USER@$SERVER_IP:$PROXY_DIR/nginx.conf.next"
- ssh "${SSH_OPTS[@]}" "$SSH_USER@$SERVER_IP" << REMOTE_CMDS
- set -Eeuo pipefail
- cd "$PROXY_DIR"
- docker run --rm \
- --network meishi_ccdw_life_default \
- -v "$PROXY_DIR/nginx.conf.next:/etc/nginx/nginx.conf:ro" \
- -v /etc/letsencrypt:/etc/letsencrypt:ro \
- docker.m.daocloud.io/library/nginx:alpine nginx -t
- cp nginx.conf.next nginx.conf
- chmod 644 nginx.conf
- rm -f nginx.conf.next
- docker exec "$PROXY_CONTAINER" nginx -s reload
- for attempt in \$(seq 1 15); do
- if curl --fail --silent --show-error \
- --resolve c.lessncosmos.com:80:127.0.0.1 \
- "$PUBLIC_URL/healthz" >/dev/null; then
- exit 0
- fi
- sleep 2
- done
- echo "Public HTTP health check failed: $PUBLIC_URL/healthz" >&2
- exit 1
- REMOTE_CMDS
- echo "Frontend deployed: $PUBLIC_URL"
|