WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 471f977

Browse files
committed
add deployment script and example
1 parent 6ea7cd4 commit 471f977

File tree

5 files changed

+325
-70
lines changed

5 files changed

+325
-70
lines changed

examples-copier/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ go build -o examples-copier .
5151
go build -o config-validator ./cmd/config-validator
5252
```
5353

54-
### Configuration
54+
### Local Configuration
5555

5656
1. **Copy environment example file**
5757

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,60 @@
1-
env_variables:
2-
# =============================================================================
3-
# GitHub Configuration (Non-sensitive)
4-
# =============================================================================
5-
GITHUB_APP_ID: "1166559"
6-
INSTALLATION_ID: "62138132"
7-
REPO_OWNER: "mongodb"
8-
REPO_NAME: "docs-mongodb-internal"
9-
SRC_BRANCH: "main"
10-
11-
# =============================================================================
12-
# Secret Manager References (Sensitive Data - SECURE!)
13-
# =============================================================================
14-
# GitHub App private key - loaded from Secret Manager
15-
GITHUB_APP_PRIVATE_KEY_SECRET_NAME: "projects/1054147886816/secrets/CODE_COPIER_PEM/versions/latest"
16-
17-
# Webhook secret - loaded from Secret Manager
18-
WEBHOOK_SECRET_NAME: "projects/1054147886816/secrets/webhook-secret/versions/latest"
19-
20-
# MongoDB URI - loaded from Secret Manager (for audit logging - OPTIONAL)
21-
MONGO_URI_SECRET_NAME: "projects/1054147886816/secrets/mongo-uri/versions/latest"
22-
23-
# =============================================================================
24-
# Application Settings (Non-sensitive)
25-
# =============================================================================
26-
# PORT is automatically set by App Engine Flexible (do not override)
27-
WEBSERVER_PATH: "/events"
28-
CONFIG_FILE: "copier-config.yaml"
29-
DEPRECATION_FILE: "deprecated_examples.json"
30-
31-
# =============================================================================
32-
# Committer Information (Non-sensitive)
33-
# =============================================================================
34-
COMMITTER_NAME: "GitHub Copier App"
35-
COMMITTER_EMAIL: "[email protected]"
36-
37-
# =============================================================================
38-
# Google Cloud Configuration (Non-sensitive)
39-
# =============================================================================
40-
GOOGLE_CLOUD_PROJECT_ID: "github-copy-code-examples"
41-
COPIER_LOG_NAME: "code-copier-log"
42-
43-
# Logging Configuration (Optional - uncomment for debugging)
44-
# LOG_LEVEL: "debug" # Enable verbose debug logging
45-
# COPIER_DEBUG: "true" # Alternative debug flag
46-
# COPIER_DISABLE_CLOUD_LOGGING: "true" # Disable GCP logging
47-
48-
# =============================================================================
49-
# Feature Flags (Optional)
50-
# =============================================================================
51-
AUDIT_ENABLED: "true"
52-
METRICS_ENABLED: "true"
53-
# DRY_RUN: "false"
54-
55-
# =============================================================================
56-
# Default Behaviors (Optional)
57-
# =============================================================================
58-
# DEFAULT_RECURSIVE_COPY: "true"
59-
# DEFAULT_PR_MERGE: "false"
60-
# DEFAULT_COMMIT_MESSAGE: "Automated PR with updated examples"
1+
# =============================================================================
2+
# GitHub Configuration (Non-sensitive)
3+
# =============================================================================
4+
GITHUB_APP_ID: "1166559"
5+
INSTALLATION_ID: "62138132"
6+
REPO_OWNER: "mongodb"
7+
REPO_NAME: "docs-mongodb-internal"
8+
SRC_BRANCH: "main"
9+
10+
# =============================================================================
11+
# Secret Manager References (Sensitive Data - SECURE!)
12+
# =============================================================================
13+
# GitHub App private key - loaded from Secret Manager
14+
GITHUB_APP_PRIVATE_KEY_SECRET_NAME: "projects/1054147886816/secrets/CODE_COPIER_PEM/versions/latest"
15+
16+
# Webhook secret - loaded from Secret Manager
17+
WEBHOOK_SECRET_NAME: "projects/1054147886816/secrets/webhook-secret/versions/latest"
18+
19+
# MongoDB URI - loaded from Secret Manager (for audit logging - OPTIONAL)
20+
MONGO_URI_SECRET_NAME: "projects/1054147886816/secrets/mongo-uri/versions/latest"
21+
22+
# =============================================================================
23+
# Application Settings (Non-sensitive)
24+
# =============================================================================
25+
# PORT is automatically set by App Engine Flexible (do not override)
26+
WEBSERVER_PATH: "/events"
27+
CONFIG_FILE: "copier-config.yaml"
28+
DEPRECATION_FILE: "deprecated_examples.json"
29+
30+
# =============================================================================
31+
# Committer Information (Non-sensitive)
32+
# =============================================================================
33+
COMMITTER_NAME: "GitHub Copier App"
34+
COMMITTER_EMAIL: "[email protected]"
35+
36+
# =============================================================================
37+
# Google Cloud Configuration (Non-sensitive)
38+
# =============================================================================
39+
GOOGLE_CLOUD_PROJECT_ID: "github-copy-code-examples"
40+
COPIER_LOG_NAME: "code-copier-log"
41+
42+
# Logging Configuration (Optional - uncomment for debugging)
43+
# LOG_LEVEL: "debug" # Enable verbose debug logging
44+
# COPIER_DEBUG: "true" # Alternative debug flag
45+
# COPIER_DISABLE_CLOUD_LOGGING: "true" # Disable GCP logging
46+
47+
# =============================================================================
48+
# Feature Flags (Optional)
49+
# =============================================================================
50+
AUDIT_ENABLED: "true"
51+
METRICS_ENABLED: "true"
52+
# DRY_RUN: "false"
53+
54+
# =============================================================================
55+
# Default Behaviors (Optional)
56+
# =============================================================================
57+
# DEFAULT_RECURSIVE_COPY: "true"
58+
# DEFAULT_PR_MERGE: "false"
59+
# DEFAULT_COMMIT_MESSAGE: "Automated PR with updated examples"
6160

examples-copier/docs/DEPLOYMENT.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ METRICS_ENABLED: "true"
282282

283283
### Important Notes
284284

285+
**About env-cloudrun.yaml:**
286+
- This file contains **environment variables only** (application configuration)
287+
- It does **NOT** contain infrastructure settings (CPU, memory, timeout, etc.)
288+
- Infrastructure settings must be specified via command-line flags or a `service.yaml` file
289+
- Use the deployment script (`./scripts/deploy-cloudrun.sh`) to avoid typing all the flags
290+
285291
**✅ DO:**
286292
- Use Secret Manager references (`*_SECRET_NAME` variables)
287293
- Keep `env-cloudrun.yaml` in `.gitignore`
@@ -323,10 +329,34 @@ services.LoadMongoURI(config) // Loads from Secret Manager
323329

324330
### Deploy to Cloud Run
325331

332+
#### Option 1: Use the deployment script (Recommended)
333+
334+
The simplest way to deploy is using the provided script:
335+
336+
```bash
337+
cd examples-copier
338+
339+
# Deploy to default region (us-central1)
340+
./scripts/deploy-cloudrun.sh
341+
342+
# Or specify a different region
343+
./scripts/deploy-cloudrun.sh us-east1
344+
```
345+
346+
The script will:
347+
- ✅ Check that `env-cloudrun.yaml` exists
348+
- ✅ Verify your Google Cloud project is set
349+
- ✅ Show configuration before deploying
350+
- ✅ Deploy with all recommended settings
351+
- ✅ Display the service URL and next steps
352+
353+
#### Option 2: Manual deployment command
354+
355+
If you prefer to run the command directly:
356+
326357
```bash
327358
cd examples-copier
328359

329-
# Deploy from source (Cloud Run builds the container automatically)
330360
gcloud run deploy examples-copier \
331361
--source . \
332362
--region us-central1 \
@@ -338,14 +368,6 @@ gcloud run deploy examples-copier \
338368
--timeout=300s \
339369
--concurrency=80 \
340370
--port=8080
341-
342-
# Or specify project
343-
gcloud run deploy examples-copier \
344-
--source . \
345-
--region us-central1 \
346-
--env-vars-file=env-cloudrun.yaml \
347-
--project=your-project-id \
348-
--allow-unauthenticated
349371
```
350372

351373
**Deployment options explained:**
@@ -358,6 +380,7 @@ gcloud run deploy examples-copier \
358380
- `--memory=512Mi` - 512MB RAM per instance
359381
- `--timeout=300s` - 5 minute timeout for webhook processing
360382
- `--concurrency=80` - Handle up to 80 concurrent requests per instance
383+
- `--port=8080` - Container port (matches Dockerfile EXPOSE)
361384

362385
### Verify Deployment
363386

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# Deploy examples-copier to Google Cloud Run
3+
# Usage: ./scripts/deploy-cloudrun.sh [region]
4+
5+
set -e
6+
7+
# Configuration
8+
SERVICE_NAME="examples-copier"
9+
REGION="${1:-us-central1}"
10+
ENV_FILE="env-cloudrun.yaml"
11+
12+
# Colors for output
13+
GREEN='\033[0;32m'
14+
BLUE='\033[0;34m'
15+
YELLOW='\033[1;33m'
16+
NC='\033[0m' # No Color
17+
18+
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
19+
echo -e "${BLUE}║ Deploying examples-copier to Cloud Run ║${NC}"
20+
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
21+
echo ""
22+
23+
# Check if env-cloudrun.yaml exists
24+
if [ ! -f "$ENV_FILE" ]; then
25+
echo -e "${YELLOW}⚠️ Warning: $ENV_FILE not found${NC}"
26+
echo "Create it from a template:"
27+
echo " cp configs/env.yaml.production $ENV_FILE"
28+
echo " # Edit with your values"
29+
exit 1
30+
fi
31+
32+
# Get current project
33+
PROJECT=$(gcloud config get-value project 2>/dev/null)
34+
if [ -z "$PROJECT" ]; then
35+
echo -e "${YELLOW}⚠️ No Google Cloud project set${NC}"
36+
echo "Set your project:"
37+
echo " gcloud config set project YOUR_PROJECT_ID"
38+
exit 1
39+
fi
40+
41+
echo -e "${GREEN}📦 Configuration:${NC}"
42+
echo " Service: $SERVICE_NAME"
43+
echo " Region: $REGION"
44+
echo " Project: $PROJECT"
45+
echo " Env File: $ENV_FILE"
46+
echo ""
47+
48+
# Confirm deployment
49+
read -p "Deploy to Cloud Run? (y/N) " -n 1 -r
50+
echo
51+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
52+
echo "Deployment cancelled"
53+
exit 0
54+
fi
55+
56+
echo ""
57+
echo -e "${BLUE}🚀 Deploying...${NC}"
58+
echo ""
59+
60+
# Deploy to Cloud Run
61+
gcloud run deploy "$SERVICE_NAME" \
62+
--source . \
63+
--region "$REGION" \
64+
--env-vars-file="$ENV_FILE" \
65+
--allow-unauthenticated \
66+
--max-instances=10 \
67+
--cpu=1 \
68+
--memory=512Mi \
69+
--timeout=300s \
70+
--concurrency=80 \
71+
--port=8080
72+
73+
echo ""
74+
echo -e "${GREEN}✅ Deployment complete!${NC}"
75+
echo ""
76+
77+
# Get service URL
78+
SERVICE_URL=$(gcloud run services describe "$SERVICE_NAME" \
79+
--region="$REGION" \
80+
--format="value(status.url)" 2>/dev/null)
81+
82+
if [ -n "$SERVICE_URL" ]; then
83+
echo -e "${GREEN}🌐 Service URL:${NC}"
84+
echo " $SERVICE_URL"
85+
echo ""
86+
echo -e "${BLUE}📋 Next steps:${NC}"
87+
echo " 1. Test health endpoint:"
88+
echo " curl $SERVICE_URL/health"
89+
echo ""
90+
echo " 2. View logs:"
91+
echo " gcloud run services logs read $SERVICE_NAME --region=$REGION --limit=50"
92+
echo ""
93+
echo " 3. Configure GitHub webhook:"
94+
echo " Payload URL: $SERVICE_URL/events"
95+
echo " Secret: (from Secret Manager)"
96+
fi
97+

0 commit comments

Comments
 (0)