Configure dashboard to use public GCE IP by default #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI / CD | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| # --------------------------------------------------------------------------- | |
| # test — compile + unit tests only (no network, no DB) | |
| # | |
| # Integration tests (data_source_verification, daemon_lifecycle, etc.) are | |
| # intentionally excluded here — they hit live external APIs (USGS, CWMS, IEM) | |
| # and require a running PostgreSQL instance. Run those manually before major | |
| # releases: cargo test --test data_source_verification | |
| # --------------------------------------------------------------------------- | |
| test: | |
| name: Build & Unit Test | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: flomon_service | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry and build artifacts | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: flomon_service | |
| - name: cargo check (all targets) | |
| run: cargo check --all-targets | |
| - name: cargo test --lib (unit tests only) | |
| run: cargo test --lib | |
| # --------------------------------------------------------------------------- | |
| # deploy — use gcloud compute ssh to pull latest and restart containers | |
| # | |
| # Only runs on push to main after test passes. | |
| # | |
| # Required repository secrets: | |
| # GCP_SA_KEY — service account JSON key (base64-encoded or raw JSON) | |
| # The SA needs roles: compute.osLogin + compute.viewer | |
| # (or compute.instanceAdmin.v1 for broader access) | |
| # GCP_PROJECT_ID — GCP project ID (e.g. my-project-123456) | |
| # GCP_INSTANCE — VM instance name (e.g. riverviews-vm) | |
| # GCP_ZONE — zone the VM is in (e.g. us-central1-a) | |
| # | |
| # Note: first deploy after provisioning takes ~10 min (Rust compile + backfill). | |
| # Subsequent deploys are faster — cargo caches layers in the Docker build cache. | |
| # | |
| # Runs on a self-hosted runner installed on the GCE VM. | |
| # No SSH/IAP/SA key juggling — the runner executes directly as the fiver user. | |
| # Setup: GitHub repo → Settings → Actions → Runners → New self-hosted runner | |
| # --------------------------------------------------------------------------- | |
| deploy: | |
| name: Deploy to GCE | |
| runs-on: self-hosted | |
| needs: test | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: Pull latest and restart containers | |
| run: | | |
| set -e | |
| # Deploy from the repo clone that has .env — NOT the CI workspace. | |
| # $HOME may differ in the systemd service context; derive it from passwd. | |
| REPO="$(getent passwd "$(whoami)" | cut -d: -f6)/riverviews" | |
| echo "Deploying as $(whoami) from $REPO" | |
| if [ ! -f "$REPO/.env" ]; then | |
| echo "ERROR: $REPO/.env not found. Clone the repo and create .env first." | |
| exit 1 | |
| fi | |
| cd "$REPO" | |
| git pull origin main | |
| docker compose up --build -d postgres flomon_service | |
| echo "Containers restarted. Waiting for HTTP API..." | |
| for i in $(seq 1 36); do | |
| if curl -sf http://localhost:8080/health > /dev/null 2>&1; then | |
| echo "Service is healthy." | |
| exit 0 | |
| fi | |
| sleep 10 | |
| done | |
| echo "Health check timed out. Logs:" | |
| docker compose logs --tail=50 flomon_service | |
| exit 1 |