This document provides detailed explanations of the GitHub Actions workflows used in this repository. It's designed to help developers understand the CI/CD pipeline structure, the purpose of each workflow, and how they work together to automate the development and deployment process.
The workflows in this repository are organized into three main categories:
- Main Workflows: Primary entry points triggered by GitHub events
- Composite Workflows: Reusable workflow components called by main workflows
- Resource Management Workflows: Specialized workflows for AWS resource management
Trigger:
- Pull request open or update
- Manual workflow dispatch (for deploying to dev environment)
Purpose: Validates the proposed changes to ensure they meet quality standards and work as expected. Additionally allows manual deployment to the dev environment through workflow dispatch.
Concurrency:
- Group-based concurrency controls to prevent overlapping operations
- Jobs can be canceled in progress for newer runs of the same PR
Steps:
- Uses reusable
.builds.ymlworkflow to build container images for backend, frontend, and migrations . - Plans infrastructure changes using Terraform/Terragrunt with concurrency controls
- Runs comprehensive tests on the codebase including:
- Backend unit tests with a PostgreSQL service container
- Frontend unit tests
- Security scanning with Trivy
- SonarCloud analysis for code quality
- For workflow dispatch events:
- Resumes paused resources in the dev environment with concurrency control
- Deploys the stack to the dev environment for testing with concurrency protection
Permissions:
- Enhanced security permissions including attestations for vulnerability scanning
- Pull request write access for status updates
Outputs: Container images with appropriate tags, test results, SonarCloud reports, and (for workflow dispatch) a deployed environment
Trigger: Pull request targeting the main branch
Purpose: Ensures code quality and validates the proposed changes.
Steps:
- Lints code using ESLint
- Checks for proper formatting with Prettier
- Validates Terraform configurations to detect potential issues
- Enforces conventional commit message format
Outputs: Validation status, with failures blocking PR merges
Trigger: Pull request closed
Purpose: Cleans up resources associated with the PR to avoid unnecessary costs.
Steps:
- Identifies the PR number
- Destroys any PR-specific infrastructure that was deployed
- Removes any container images tagged with the PR number
Outputs: Confirmation of resource cleanup
Trigger: Push to main branch (merge) or manual workflow dispatch with PR number
Purpose: Creates production-ready resources and deploys to both dev and test environments in sequence.
Concurrency: Ensures only one deployment runs at a time for the main branch
Steps:
- Determines the PR number that was merged
- Resumes all AWS resources (dev, test, and prod) before deployment
- Deploys the stack to the dev environment using Terragrunt
- Retags container images with 'dev' tag
- Runs end-to-end tests against the deployed dev environment
- Deploys the stack to the test environment using Terragrunt
- Retags container images with 'test' tag
- Pauses all AWS resources after successful deployment to save costs
Outputs:
- Deployed applications in both dev and test environments
- Container images tagged with PR number, 'dev', and 'test' tags
Trigger: Manual workflow dispatch
Purpose: Creates a new release and deploys to the production environment.
Steps:
- Generates a new version number and changelog using Conventional Commits
- Retags container images with the release version
- Deploys the stack to the production environment
- Creates a GitHub release with release notes
Outputs: Production deployment, GitHub release, versioned container images
Purpose: Standardized test execution for backend and frontend components.
Details:
- Sets up a PostgreSQL service container for backend tests
- Runs unit tests with code coverage reporting
- Analyzes code with SonarCloud
- Designed to be reusable across different workflows
Purpose: Executes end-to-end tests against deployed environments.
Details:
- Can use either deployed URLs or local containers
- Sets up the necessary test environment
- Runs Playwright tests against the frontend
- Captures test results and screenshots
Purpose: Performance testing to validate scalability.
Details:
- Uses k6 to execute load tests
- Tests both backend and frontend components
- Configurable with different load profiles (VUs and duration)
- Reports performance metrics
Purpose: Standardized process for deploying the complete application stack.
Details:
- Handles all infrastructure components (database, API, frontend)
- Uses Terragrunt to manage deployment
- Supports different environments (dev, test, prod)
- Exposes important outputs like API Gateway URL and CloudFront domain
- Orchestrates deployment in the correct order to ensure dependencies are met
- Sets up ECS tasks including the Flyway migration task and main application task
- Configures the task with environment variables for database connectivity
- Manages secrets from AWS Secrets Manager for secure database access
Purpose: Clean removal of deployed infrastructure.
Details:
- Safe teardown of resources in reverse dependency order
- Handles state file management
- Ensures complete cleanup to avoid orphaned resources
Purpose: Standardizes stack naming conventions.
Details:
- Generates consistent resource prefixes
- Reused by multiple workflows
- Ensures naming consistency across environments
Purpose: Standardized deployment process for individual components.
Details:
- Modular approach to deployment
- Can be used for specific components
- Maintains proper dependency order
Purpose: Standardized container image building process.
Details:
- Builds container images for backend, frontend, and migrations
- Handles image tagging with consistent naming conventions
- Supports multiple tags including PR numbers, environment names, and 'latest'
- Designed to be reusable across different workflows
- Uses the bcgov/action-builder-ghcr action for optimized builds
Trigger:
- Schedule (weekdays at 6PM PST)
- Manual workflow dispatch with environment selection
- Workflow call from other workflows
Purpose: Cost optimization by pausing resources outside of working hours.
Inputs:
app_env: Environment to pause resources for (dev, test, prod, or all)
Details:
- Identifies resources that can be safely paused in specified environment(s)
- Scales down ECS services to zero
- Stops RDS clusters
- Uses AWS CLI commands to pause specific services
- Runs on a schedule to automatically pause resources
- Can be targeted to specific environments (dev, test, prod)
Trigger:
- Schedule (weekdays at 7AM PST)
- Manual workflow dispatch with environment selection
- Workflow call from other workflows (like PR deployment)
Purpose: Resume paused resources at the start of the working day or on-demand.
Inputs:
app_env: Environment to resume resources for (dev, test, prod, or all)
Details:
- Starts RDS clusters in specified environment(s)
- Scales ECS services back to their configured capacity
- Ensures all services are in a ready state
- Can be targeted to specific environments (dev, test, prod)
Trigger: Manual workflow dispatch
Purpose: Clean up unused or stale environments to reduce costs.
Details:
- Identifies environments that haven't been used recently
- Safely destroys infrastructure for those environments
- Reports on resource cleanup
The workflows use the following environment configurations:
- Development (dev): Used for continuous integration and feature testing
- Can be deployed manually via workflow dispatch on the PR workflow
- Serves as the target for merged PRs from the main branch
- Uses FARGATE_SPOT instances (80%) for cost optimization
- Auto-scales based on demand with configurable thresholds
- Resources can be paused/resumed individually for this environment
- Testing (test): Used for QA and acceptance testing
- Matches the production configuration for accurate testing
- Includes database migration execution via Flyway ECS tasks
- Requires environment approval for resource management operations
- Can be paused/resumed independently from other environments
- Production (prod): Used for live production deployments via the release workflow
- Uses a mix of FARGATE (base=1, 20%) and FARGATE_SPOT (80%) for reliability and cost-effectiveness
- Database credentials stored and retrieved securely from AWS Secrets Manager
- API Gateway with VPC Link for secure backend access
- Requires strict environment approval for resource management operations
- Can be excluded from automatic pause/resume schedules if needed for 24/7 availability
For the workflows to function properly, the following secrets need to be configured:
AWS_DEPLOY_ROLE_ARN: ARN for the IAM role with deployment permissionsSONAR_TOKEN_BACKEND: SonarCloud token for backend analysisSONAR_TOKEN_FRONTEND: SonarCloud token for frontend analysisAWS_LICENSE_PLATE: License plate identifier for the AWS environment
The workflow interactions follow this general pattern:
GitHub Event (PR, Push, etc.)
│
├─── PR Open/Update ─────────────────── PR Merge to Main
│ │ │
│ │ ▼
│ │ Resume Resources
│ │ │
│ ├─── Build (calls .builds.yml) │
│ │ with concurrency control │
│ │ │
│ ├─── Plan Infrastructure │
│ │ with concurrency control │
│ │ │
│ ├─── Test (calls .tests.yml) │
│ │ with concurrency control │
│ │ ▼
│ │ Deploy to Dev
│ ├─── Manual Workflow Dispatch─┐ │
│ │ │ ▼
│ │ ▼ Retag Images (dev)
│ │ Resume Dev │
│ │ │ ▼
│ │ ▼ Run E2E Tests
│ │ Deploy to Dev
│ │ │
│ │ ▼
│ │ Deploy to Test
│ │ │
│ │ ▼
│ │ Retag Images (test)
│ │ │
│ │ ▼
│ └─── Results Pause Resources │
└─── Resource Management
│
├─── Pause Resources (Scheduled/Manual/After deployment)
│ │
│ ├─── Dev Environment
│ │
│ ├─── Test Environment (with approval)
│ │
│ └─── Prod Environment (with approval) │
├─── Resume Resources (Scheduled/Manual/Before deployment)
│ │
│ ├─── Dev Environment
│ │
│ ├─── Test Environment (with approval)
│ │
│ └─── Prod Environment (with approval)
│
└─── Prune Environments
When customizing these workflows:
- Maintain the separation of concerns between main and composite workflows
- Update environment variables consistently across all workflows
- Test changes thoroughly in isolation before merging
- Consider impacts on automated resource management
- Update documentation when changing workflow behavior
- When using manual workflow dispatch for deployments:
- Ensure proper resource resume/pause mechanisms are in place
- Use consistent tagging strategies between PR-based and manual deployments
- Consider adding validation steps after manual deployments to verify success
Common workflow issues and their solutions:
- Failed Authentication: Ensure AWS role permissions are correctly set
- Deployment Failures: Check Terragrunt outputs for specific error messages
- Test Failures: Review test logs and ensure local tests pass first