# Cloud Run Landing Pages

Deploy static landing pages to production via Google Cloud Run.

**Use when:** Deploying landing pages to production (NOT staging/dev — use Caddy for that).

## Prerequisites

- **gcloud CLI:** `/home/aria/google-cloud-sdk/bin/gcloud`
- **Service Account:** `aria-firebase-admin@the-agency-symph.iam.gserviceaccount.com`
- **Default Project:** `the-agency-symph`
- **Credentials:** `~/.config/gcloud/aria-firebase-admin.json`

Always set PATH before using gcloud:
```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"
```

## Quick Deploy (Single Command)

For a static HTML landing page in `/home/aria/projects/{name}/`:

```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"
cd /home/aria/projects/{name}

# Create Dockerfile if not exists
cat > Dockerfile << 'EOF'
FROM nginx:alpine
COPY . /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
EOF

# Create nginx config
cat > nginx.conf << 'EOF'
server {
    listen 8080;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;

    location / {
        try_files $uri $uri.html $uri/ /index.html;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
}
EOF

# Create .gcloudignore
cat > .gcloudignore << 'EOF'
.git
.gitignore
docs/
*.md
!index.html
EOF

# Deploy
gcloud run deploy {service-name} \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --port 8080 \
  --memory 256Mi \
  --cpu 1 \
  --min-instances 0 \
  --max-instances 3 \
  --project the-agency-symph \
  --quiet
```

## Service Naming

- Use lowercase, alphanumeric, hyphens only
- Examples: `overture`, `worklane`, `my-landing-page`
- Service URL pattern: `https://{service}-1074779943765.us-central1.run.app`

## Custom Domains

### Verified Domains (Ready to Use)

Currently verified in GCP: `symph.co`

```bash
# Map a symph.co subdomain
gcloud beta run domain-mappings create \
  --service {service-name} \
  --domain {subdomain}.symph.co \
  --region us-central1 \
  --project the-agency-symph
```

### Adding New Domains

For external domains (not *.symph.co), domain verification is required:

1. **Verify domain in GCP Console:**
   - Go to: https://console.cloud.google.com/run/domains?project=the-agency-symph
   - Click "Add mapping" → "Verify a new domain"
   - Follow DNS verification steps

2. **After verification, create mapping:**
   ```bash
   gcloud beta run domain-mappings create \
     --service {service-name} \
     --domain {custom-domain.com} \
     --region us-central1 \
     --project the-agency-symph
   ```

3. **Get DNS records:**
   ```bash
   gcloud beta run domain-mappings describe \
     --domain {custom-domain.com} \
     --region us-central1 \
     --project the-agency-symph
   ```

### DNS Setup for Cloud Run Domains

After mapping, configure DNS:

| Type | Name | Value |
|------|------|-------|
| A | @ | (from gcloud output) |
| AAAA | @ | (from gcloud output) |
| CNAME | www | {apex-domain} |

## Project Structure

For a landing page project:

```
/home/aria/projects/{name}/
├── index.html          # Main landing page
├── Dockerfile          # nginx:alpine container
├── nginx.conf          # nginx configuration
├── .gcloudignore       # Files to exclude from deploy
└── docs/               # Discovery docs (optional, not deployed)
```

## Multiple Pages

For sites with multiple HTML pages:

```
/home/aria/projects/{name}/
├── index.html          # /
├── about.html          # /about
├── pricing.html        # /pricing
├── Dockerfile
└── nginx.conf
```

The nginx config handles clean URLs automatically (`/about` → `about.html`).

## Update Existing Service

To redeploy after changes:

```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"
cd /home/aria/projects/{name}

gcloud run deploy {service-name} \
  --source . \
  --region us-central1 \
  --project the-agency-symph \
  --quiet
```

## List Services

```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"
gcloud run services list --region us-central1 --project the-agency-symph
```

## Delete Service

```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"
gcloud run services delete {service-name} --region us-central1 --project the-agency-symph --quiet
```

## Troubleshooting

### "Domain not verified"
- Only `symph.co` is pre-verified
- External domains need verification in GCP Console
- Use `*.symph.co` subdomains as alternative

### Build fails
- Check Dockerfile syntax
- Ensure index.html exists
- Check .gcloudignore isn't excluding needed files

### 403/404 after deploy
- Verify nginx.conf is correct
- Check file permissions (should be readable)
- Test locally with `docker build -t test . && docker run -p 8080:8080 test`

## Cost

Cloud Run free tier (per month):
- 2 million requests
- 360,000 vCPU-seconds
- 180,000 GiB-seconds

Landing pages typically stay well within free tier.

## Dev vs Prod

| Environment | Platform | Domain Pattern | When to Use |
|-------------|----------|----------------|-------------|
| **DEV/Staging** | Caddy (VPS) | `*.landing.symph.co` | Testing, preview |
| **PRODUCTION** | Cloud Run | Custom domain | Live, customer-facing |

Always deploy to staging first (Caddy), then promote to production (Cloud Run).

## Full Example: Deploy "acme-landing"

```bash
export PATH="/home/aria/google-cloud-sdk/bin:$PATH"

# 1. Set up project
mkdir -p /home/aria/projects/acme-landing
cd /home/aria/projects/acme-landing

# 2. Create HTML (or copy existing)
echo '<html><body><h1>Welcome to Acme</h1></body></html>' > index.html

# 3. Create Dockerfile
cat > Dockerfile << 'EOF'
FROM nginx:alpine
COPY . /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
EOF

# 4. Create nginx.conf
cat > nginx.conf << 'EOF'
server {
    listen 8080;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;
    location / {
        try_files $uri $uri.html $uri/ /index.html;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
}
EOF

# 5. Create .gcloudignore
cat > .gcloudignore << 'EOF'
.git
.gitignore
docs/
*.md
!index.html
EOF

# 6. Deploy
gcloud run deploy acme-landing \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --port 8080 \
  --memory 256Mi \
  --cpu 1 \
  --min-instances 0 \
  --max-instances 3 \
  --project the-agency-symph \
  --quiet

# 7. Map domain (if using symph.co subdomain)
gcloud beta run domain-mappings create \
  --service acme-landing \
  --domain acme.symph.co \
  --region us-central1 \
  --project the-agency-symph
```

## Remember

- **PROD = Cloud Run** (not Caddy/VPS)
- **DEV = Caddy** (*.landing.symph.co or *.dev.apps.symph.co)
- Always use `--quiet` flag for non-interactive deploys
- gcloud path: `/home/aria/google-cloud-sdk/bin/gcloud`
- Default project: `the-agency-symph`
