-
Notifications
You must be signed in to change notification settings - Fork 1
ci: automated GHCR + EC2 deployment with QA gating #458
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
saqibmanan
wants to merge
5
commits into
dev
Choose a base branch
from
ci/deploy-workflow
base: dev
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d006a6
ci: add GHCR build + EC2 deploy and QA gating workflows
ae46ffb
Potential fix for pull request finding 'CodeQL / Workflow does not co…
saqibmanan b62dd76
ci: add Docker Compose setup with branding and multi-env support
956b9a9
Merge branch 'ci/docker-compose-setup' into ci/deploy-workflow
84fe092
ci: fix deploy workflow — branding clone, build context, missing env …
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,115 @@ | ||
| name: Deploy | ||
|
|
||
| # Build the image, push it to GHCR, deploy to the target EC2 host over SSH, and | ||
| # (on dev) run the QA smoke suite against the freshly deployed dev environment. | ||
| # | ||
| # push to dev -> environment "development" -> tag :dev -> dev EC2 host -> smoke gate | ||
| # push to main -> environment "production" -> tag :prod -> prod EC2 host | ||
| # | ||
| # NEXT_PUBLIC_* values are baked into the image at build time, so the dev and | ||
| # prod images differ; the values come from the selected environment's secrets. | ||
| # The host already has a docker-compose.yml whose service image points at | ||
| # ghcr.io/<repo>:<dev|prod>; this workflow only pulls and restarts it. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [dev, main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| concurrency: | ||
| group: deploy-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| name: Build & push image | ||
| runs-on: ubuntu-latest | ||
| environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | ||
| steps: | ||
| - uses: actions/checkout@v6.0.3 | ||
|
|
||
| - name: Clone branding repo | ||
| run: git clone https://github.com/CivicDataLab/ids-drr-india-branding.git ../ids-drr-india-branding | ||
|
|
||
| # ghcr.io image paths must be lowercase; the repo slug is mixed-case. | ||
| - id: meta | ||
| run: | | ||
| echo "name=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" | ||
| echo "env_tag=${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - uses: docker/build-push-action@v7 | ||
| with: | ||
| push: true | ||
| context: .. | ||
| file: IDS-DRR-Frontend/Dockerfile | ||
| target: runner | ||
| build-args: | | ||
| CONTEXT_SUBDIR=IDS-DRR-Frontend | ||
| BRANDING_PACKAGE=ids-drr-india-branding | ||
| NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL=${{ secrets.NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL }} | ||
| NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} | ||
| NEXT_PUBLIC_TIME_PERIOD=${{ secrets.NEXT_PUBLIC_TIME_PERIOD }} | ||
| NEXT_PUBLIC_GOOGLE_ANALYTICS_APP_ID=${{ secrets.NEXT_PUBLIC_GOOGLE_ANALYTICS_APP_ID }} | ||
| NEXT_PUBLIC_GOOGLE_TRANSLATE_KEY=${{ secrets.NEXT_PUBLIC_GOOGLE_TRANSLATE_KEY }} | ||
| NEXT_PUBLIC_DOWNLOAD_REPORT_LINK=${{ secrets.NEXT_PUBLIC_DOWNLOAD_REPORT_LINK }} | ||
| tags: | | ||
| ghcr.io/${{ steps.meta.outputs.name }}:${{ steps.meta.outputs.env_tag }} | ||
| ghcr.io/${{ steps.meta.outputs.name }}:${{ github.sha }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| deploy: | ||
| name: Deploy to EC2 | ||
| needs: build-and-push | ||
| runs-on: ubuntu-latest | ||
| environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | ||
| steps: | ||
| - name: Pull & restart on host | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.EC2_HOST }} | ||
| username: ${{ secrets.EC2_USER }} | ||
| key: ${{ secrets.EC2_SSH_KEY }} | ||
| envs: TOKEN,REG_USER,DEPLOY_PATH,SERVICE | ||
| script: | | ||
| set -euo pipefail | ||
| echo "$TOKEN" | docker login ghcr.io -u "$REG_USER" --password-stdin | ||
| cd "$DEPLOY_PATH" | ||
| docker compose pull "$SERVICE" | ||
| docker compose up -d "$SERVICE" | ||
| docker image prune -f | ||
| env: | ||
| TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REG_USER: ${{ github.actor }} | ||
| DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} | ||
| SERVICE: ${{ vars.COMPOSE_SERVICE }} | ||
|
|
||
| dev-smoke: | ||
| name: Smoke (dev) | ||
| needs: deploy | ||
| if: github.ref == 'refs/heads/dev' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Triggers IDS-DRR-QA-Automation's dispatch.yml and blocks until it | ||
| # finishes; this job (and its check) is green only if smoke passes. | ||
| - uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5 | ||
| with: | ||
| owner: CivicDataLab | ||
| repo: IDS-DRR-QA-Automation | ||
| github_token: ${{ secrets.QA_REPO_PAT }} | ||
| workflow_file_name: dispatch.yml | ||
| ref: main | ||
| wait_interval_seconds: 30 | ||
| client_payload: '{"scope":"smoke","target_env":"dev"}' |
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,32 @@ | ||
| name: QA Gate | ||
|
|
||
| # Gate for promoting dev -> main. On a PR targeting main, run the full QA | ||
| # regression suite against the dev environment and block the merge until it | ||
| # passes. Mark the "qa-gate" check as a required status check on the main | ||
| # branch (Settings -> Branches) so the PR cannot be merged while it is red. | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: qa-gate-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| qa-gate: | ||
| name: Full regression (dev) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5 | ||
| with: | ||
| owner: CivicDataLab | ||
| repo: IDS-DRR-QA-Automation | ||
| github_token: ${{ secrets.QA_REPO_PAT }} | ||
| workflow_file_name: dispatch.yml | ||
| ref: main | ||
| wait_interval_seconds: 60 | ||
| client_payload: '{"scope":"regression","target_env":"dev"}' | ||
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 |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ npm-debug.log* | |
| # local env files | ||
| .env*.local | ||
| .env | ||
| .env.development | ||
| .env.production | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
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
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,57 @@ | ||
| # docker-compose.yml — IDS-DRR-Frontend | ||
| # | ||
| # Prerequisites: | ||
| # Clone the India branding repo as a sibling directory: | ||
| # git clone https://github.com/CivicDataLab/ids-drr-india-branding.git ../ids-drr-india-branding | ||
| # | ||
| # Env files (gitignored — create these on the server): | ||
| # .env.development — dev values | ||
| # .env.production — prod values | ||
| # | ||
| # Usage: | ||
| # Dev: docker compose --env-file .env.development up dev --build | ||
| # Prod: docker compose --env-file .env.production up prod --build | ||
| # | ||
| # --env-file feeds ${VAR} substitutions used in build args below. | ||
|
|
||
| x-build-common: &build-common | ||
| context: .. | ||
| dockerfile: IDS-DRR-Frontend/Dockerfile | ||
| args: | ||
| CONTEXT_SUBDIR: IDS-DRR-Frontend | ||
| BRANDING_PACKAGE: ids-drr-india-branding | ||
| NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL: ${NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL} | ||
| NEXT_PUBLIC_BACKEND_URL: ${NEXT_PUBLIC_BACKEND_URL:-} | ||
| NEXT_PUBLIC_TIME_PERIOD: ${NEXT_PUBLIC_TIME_PERIOD:-} | ||
| NEXT_PUBLIC_GOOGLE_ANALYTICS_APP_ID: ${NEXT_PUBLIC_GOOGLE_ANALYTICS_APP_ID:-} | ||
| NEXT_PUBLIC_GOOGLE_TRANSLATE_KEY: ${NEXT_PUBLIC_GOOGLE_TRANSLATE_KEY:-} | ||
| NEXT_PUBLIC_DOWNLOAD_REPORT_LINK: ${NEXT_PUBLIC_DOWNLOAD_REPORT_LINK:-} | ||
|
|
||
| services: | ||
| dev: | ||
| build: | ||
| <<: *build-common | ||
| target: dev | ||
| image: ids-drr-frontend:dev | ||
| ports: | ||
| - "${PORT:-3000}:3000" | ||
| volumes: | ||
| - .:/app | ||
| - ../ids-drr-india-branding:/app/branding-stub | ||
| - /app/node_modules | ||
| - /app/.next | ||
| working_dir: /app | ||
| env_file: | ||
| - .env.development | ||
| command: npm run dev | ||
|
|
||
| prod: | ||
| build: | ||
| <<: *build-common | ||
| target: runner | ||
| image: ${GHCR_IMAGE:-ghcr.io/civicdatalab/ids-drr-frontend}:${IMAGE_TAG:-prod} | ||
| ports: | ||
| - "${PORT:-3000}:3000" | ||
| env_file: | ||
| - .env.production | ||
| restart: unless-stopped |
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.
Uh oh!
There was an error while loading. Please reload this page.