-
Notifications
You must be signed in to change notification settings - Fork 32
Add dual staging environment infrastructure (pathroute & subdomain) #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saurya
wants to merge
6
commits into
main
Choose a base branch
from
sv-ohe-staging-infra
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34dedb7
Add dual staging environment infrastructure (pathroute & subdomain)
saurya 4dd4352
Address PR review: eliminate duplication with matrix strategy and com…
saurya e03a926
Add testbed deployment scripts for Platform Team Sandbox
saurya e58da0c
Add PRD: Enterprise Staging Environments
saurya 98f8ffc
Update PRD with completed testbed infrastructure progress
saurya 8f18771
refactor: Use platform-team-sandbox infrastructure from PR #580
openhands-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,315 @@ | ||
| name: Deploy to Staging | ||
|
|
||
| on: | ||
| # Manual trigger with options | ||
| workflow_dispatch: | ||
| inputs: | ||
| image_tag: | ||
| description: 'OpenHands image tag to deploy' | ||
| required: true | ||
| default: 'main' | ||
| environment: | ||
| description: 'Environment to deploy' | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - both | ||
| - pathroute | ||
| - subdomain | ||
| default: 'both' | ||
| skip_secrets: | ||
| description: 'Skip applying secrets (use existing)' | ||
| type: boolean | ||
| default: false | ||
| dry_run: | ||
| description: 'Dry run (template only, no deploy)' | ||
| type: boolean | ||
| default: false | ||
|
|
||
| env: | ||
| GCP_PROJECT: staging-092324 | ||
| GCP_ZONE: us-central1 | ||
| GCP_CLUSTER: staging-core-application | ||
|
|
||
| jobs: | ||
| deploy-pathroute: | ||
| name: Deploy to staging-pathroute | ||
| if: ${{ inputs.environment == 'both' || inputs.environment == 'pathroute' }} | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| NAMESPACE: openhands-pathroute | ||
| HELM_RELEASE: openhands-pathroute | ||
| ENV_DIR: envs/staging-pathroute | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install SOPS | ||
| run: | | ||
| curl -L "https://github.com/mozilla/sops/releases/download/v3.9.1/sops-v3.9.1.linux.amd64" -o sops | ||
| chmod +x sops | ||
| sudo mv sops /usr/local/bin/sops | ||
| sops --version | ||
|
|
||
| - name: Install Helm | ||
| uses: azure/setup-helm@v3 | ||
| with: | ||
| version: 'latest' | ||
|
|
||
| - name: Authenticate with Google Cloud | ||
| uses: google-github-actions/auth@v2 | ||
| with: | ||
| credentials_json: ${{ secrets.GCP_SERVICE_KEY }} | ||
|
|
||
| - name: Set up Google Cloud SDK | ||
| uses: google-github-actions/setup-gcloud@v2 | ||
|
|
||
| - name: Install gke-gcloud-auth-plugin | ||
| run: | | ||
| gcloud components install gke-gcloud-auth-plugin | ||
|
|
||
| - name: Configure kubectl | ||
| run: | | ||
| gcloud container clusters get-credentials ${{ env.GCP_CLUSTER }} \ | ||
| --zone ${{ env.GCP_ZONE }} \ | ||
| --project ${{ env.GCP_PROJECT }} | ||
|
|
||
| - name: Create namespace if not exists | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| kubectl create namespace ${{ env.NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f - | ||
|
|
||
| - name: Decrypt and apply secrets | ||
| if: ${{ !inputs.skip_secrets && !inputs.dry_run }} | ||
| run: | | ||
| SECRETS_DIR="${{ env.ENV_DIR }}/secrets" | ||
|
|
||
| if [[ -d "$SECRETS_DIR" ]]; then | ||
| echo "Applying secrets from $SECRETS_DIR" | ||
| for file in "$SECRETS_DIR"/*.yaml; do | ||
| # Skip .gitkeep or non-existent files | ||
| [[ -e "$file" ]] || continue | ||
| [[ "$(basename "$file")" == ".gitkeep" ]] && continue | ||
|
|
||
| echo "Decrypting and applying: $file" | ||
| sops --decrypt "$file" | kubectl apply -n ${{ env.NAMESPACE }} -f - | ||
| done | ||
| echo "All secrets applied successfully" | ||
| else | ||
| echo "No secrets directory found at $SECRETS_DIR" | ||
| fi | ||
|
|
||
| - name: Update Helm dependencies | ||
| run: | | ||
| helm dependency update charts/openhands | ||
|
|
||
| - name: Helm template (dry run) | ||
| if: ${{ inputs.dry_run }} | ||
| run: | | ||
| helm template ${{ env.HELM_RELEASE }} charts/openhands \ | ||
| --namespace ${{ env.NAMESPACE }} \ | ||
| --values ${{ env.ENV_DIR }}/values.yaml \ | ||
| --set image.tag=${{ inputs.image_tag }} \ | ||
| --debug | ||
|
|
||
| - name: Deploy with Helm | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| # Check current release status | ||
| if helm status ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} &>/dev/null; then | ||
| status=$(helm status ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} -o json | jq -r '.info.status') | ||
| if [[ "$status" != "deployed" ]]; then | ||
| echo "Found release in non-deployed state ($status). Attempting rollback..." | ||
| helm rollback ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} || true | ||
| fi | ||
| fi | ||
|
|
||
| helm upgrade --install \ | ||
| --wait \ | ||
| --timeout 10m \ | ||
| ${{ env.HELM_RELEASE }} \ | ||
| charts/openhands \ | ||
| --namespace ${{ env.NAMESPACE }} \ | ||
| --values ${{ env.ENV_DIR }}/values.yaml \ | ||
| --set image.tag=${{ inputs.image_tag }} \ | ||
| --debug | ||
|
|
||
| - name: Get deployment info | ||
| if: ${{ !inputs.dry_run }} | ||
| id: deployment_info | ||
| run: | | ||
| echo "## Deployment Summary (pathroute)" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Environment:** staging-pathroute" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Namespace:** ${{ env.NAMESPACE }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Image Tag:** ${{ inputs.image_tag }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| # Get ingress hostname | ||
| hostname=$(kubectl get ing -n ${{ env.NAMESPACE }} -o jsonpath='{.items[0].spec.rules[0].host}' 2>/dev/null || echo "N/A") | ||
| echo "- **Hostname:** https://$hostname" >> $GITHUB_STEP_SUMMARY | ||
| echo "hostname=$hostname" >> $GITHUB_OUTPUT | ||
|
|
||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### Pods Status" >> $GITHUB_STEP_SUMMARY | ||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||
| kubectl get pods -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} >> $GITHUB_STEP_SUMMARY | ||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Verify deployment health | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| echo "Waiting for deployment to stabilize..." | ||
| kubectl rollout status deployment -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} --timeout=5m || true | ||
|
|
||
| echo "" | ||
| echo "Current pod status:" | ||
| kubectl get pods -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} | ||
|
|
||
| outputs: | ||
| hostname: ${{ steps.deployment_info.outputs.hostname }} | ||
|
|
||
| deploy-subdomain: | ||
| name: Deploy to staging-subdomain | ||
| if: ${{ inputs.environment == 'both' || inputs.environment == 'subdomain' }} | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| NAMESPACE: openhands-subdomain | ||
| HELM_RELEASE: openhands-subdomain | ||
| ENV_DIR: envs/staging-subdomain | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install SOPS | ||
| run: | | ||
| curl -L "https://github.com/mozilla/sops/releases/download/v3.9.1/sops-v3.9.1.linux.amd64" -o sops | ||
| chmod +x sops | ||
| sudo mv sops /usr/local/bin/sops | ||
| sops --version | ||
|
|
||
| - name: Install Helm | ||
| uses: azure/setup-helm@v3 | ||
| with: | ||
| version: 'latest' | ||
|
|
||
| - name: Authenticate with Google Cloud | ||
| uses: google-github-actions/auth@v2 | ||
| with: | ||
| credentials_json: ${{ secrets.GCP_SERVICE_KEY }} | ||
|
|
||
| - name: Set up Google Cloud SDK | ||
| uses: google-github-actions/setup-gcloud@v2 | ||
|
|
||
| - name: Install gke-gcloud-auth-plugin | ||
| run: | | ||
| gcloud components install gke-gcloud-auth-plugin | ||
|
|
||
| - name: Configure kubectl | ||
| run: | | ||
| gcloud container clusters get-credentials ${{ env.GCP_CLUSTER }} \ | ||
| --zone ${{ env.GCP_ZONE }} \ | ||
| --project ${{ env.GCP_PROJECT }} | ||
|
|
||
| - name: Create namespace if not exists | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| kubectl create namespace ${{ env.NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f - | ||
|
|
||
| - name: Decrypt and apply secrets | ||
| if: ${{ !inputs.skip_secrets && !inputs.dry_run }} | ||
| run: | | ||
| SECRETS_DIR="${{ env.ENV_DIR }}/secrets" | ||
|
|
||
| if [[ -d "$SECRETS_DIR" ]]; then | ||
| echo "Applying secrets from $SECRETS_DIR" | ||
| for file in "$SECRETS_DIR"/*.yaml; do | ||
| # Skip .gitkeep or non-existent files | ||
| [[ -e "$file" ]] || continue | ||
| [[ "$(basename "$file")" == ".gitkeep" ]] && continue | ||
|
|
||
| echo "Decrypting and applying: $file" | ||
| sops --decrypt "$file" | kubectl apply -n ${{ env.NAMESPACE }} -f - | ||
| done | ||
| echo "All secrets applied successfully" | ||
| else | ||
| echo "No secrets directory found at $SECRETS_DIR" | ||
| fi | ||
|
|
||
| - name: Update Helm dependencies | ||
| run: | | ||
| helm dependency update charts/openhands | ||
|
|
||
| - name: Helm template (dry run) | ||
| if: ${{ inputs.dry_run }} | ||
| run: | | ||
| helm template ${{ env.HELM_RELEASE }} charts/openhands \ | ||
| --namespace ${{ env.NAMESPACE }} \ | ||
| --values ${{ env.ENV_DIR }}/values.yaml \ | ||
| --set image.tag=${{ inputs.image_tag }} \ | ||
| --debug | ||
|
|
||
| - name: Deploy with Helm | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| # Check current release status | ||
| if helm status ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} &>/dev/null; then | ||
| status=$(helm status ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} -o json | jq -r '.info.status') | ||
| if [[ "$status" != "deployed" ]]; then | ||
| echo "Found release in non-deployed state ($status). Attempting rollback..." | ||
| helm rollback ${{ env.HELM_RELEASE }} -n ${{ env.NAMESPACE }} || true | ||
| fi | ||
| fi | ||
|
|
||
| helm upgrade --install \ | ||
| --wait \ | ||
| --timeout 10m \ | ||
| ${{ env.HELM_RELEASE }} \ | ||
| charts/openhands \ | ||
| --namespace ${{ env.NAMESPACE }} \ | ||
| --values ${{ env.ENV_DIR }}/values.yaml \ | ||
| --set image.tag=${{ inputs.image_tag }} \ | ||
| --debug | ||
|
|
||
| - name: Get deployment info | ||
| if: ${{ !inputs.dry_run }} | ||
| id: deployment_info | ||
| run: | | ||
| echo "## Deployment Summary (subdomain)" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Environment:** staging-subdomain" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Namespace:** ${{ env.NAMESPACE }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Image Tag:** ${{ inputs.image_tag }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| # Get ingress hostname | ||
| hostname=$(kubectl get ing -n ${{ env.NAMESPACE }} -o jsonpath='{.items[0].spec.rules[0].host}' 2>/dev/null || echo "N/A") | ||
| echo "- **Hostname:** https://$hostname" >> $GITHUB_STEP_SUMMARY | ||
| echo "hostname=$hostname" >> $GITHUB_OUTPUT | ||
|
|
||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### Pods Status" >> $GITHUB_STEP_SUMMARY | ||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||
| kubectl get pods -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} >> $GITHUB_STEP_SUMMARY | ||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Verify deployment health | ||
| if: ${{ !inputs.dry_run }} | ||
| run: | | ||
| echo "Waiting for deployment to stabilize..." | ||
| kubectl rollout status deployment -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} --timeout=5m || true | ||
|
|
||
| echo "" | ||
| echo "Current pod status:" | ||
| kubectl get pods -n ${{ env.NAMESPACE }} -l app.kubernetes.io/instance=${{ env.HELM_RELEASE }} | ||
|
|
||
| outputs: | ||
| hostname: ${{ steps.deployment_info.outputs.hostname }} | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # SOPS configuration for OpenHands-Cloud | ||
| # This file tells SOPS which encryption keys to use for different file patterns | ||
| creation_rules: | ||
| # Staging path-route environment secrets - use GCP KMS | ||
| - path_regex: envs/staging-pathroute/.*secrets.*\.yaml$ | ||
| gcp_kms: projects/global-432717/locations/global/keyRings/sops-key-ring/cryptoKeys/sops-key | ||
| encrypted_regex: "^(data|stringData|config)$" | ||
|
|
||
| # Staging subdomain environment secrets - use GCP KMS | ||
| - path_regex: envs/staging-subdomain/.*secrets.*\.yaml$ | ||
| gcp_kms: projects/global-432717/locations/global/keyRings/sops-key-ring/cryptoKeys/sops-key | ||
| encrypted_regex: "^(data|stringData|config)$" | ||
|
|
||
| # Production environment secrets (future use) | ||
| - path_regex: envs/production/.*secrets.*\.yaml$ | ||
| gcp_kms: projects/global-432717/locations/global/keyRings/sops-key-ring/cryptoKeys/sops-key | ||
| encrypted_regex: "^(data|stringData|config)$" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Critical - Data Structure: Jobs
deploy-pathrouteanddeploy-subdomainare 99% identical (150+ lines duplicated). This is exactly the wrong data structure.The right way: Use a matrix strategy:
Then add conditional matrix execution:
This eliminates 150 lines of duplication and makes adding new environments trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Addressed - Refactored to use matrix strategy. The workflow now uses:
This eliminated 150+ lines of duplication. See commit 4dd4352.
This comment was written by an AI assistant (OpenHands).