CI/CD with GitHub Actions, path filters, OIDC to AWS & image tagging
Continuous integration vs delivery vs deployment, workflow anatomy, path filters for monorepos, keyless AWS auth with OIDC, tagging images by git SHA, and deploy strategies.
Definitions
- CI: every push is built and tested automatically.
- Continuous Delivery: every green build can be deployed with one click.
- Continuous Deployment: every green build on main is deployed automatically.
A workflow, annotated
name: backend
on:
push: { branches: [main] }
pull_request:
permissions:
id-token: write # allow OIDC token for AWS
contents: read
jobs:
changes:
runs-on: ubuntu-latest
outputs: { backend: ${{ steps.f.outputs.backend }} }
steps:
- uses: actions/checkout@v4
- id: f
uses: dorny/paths-filter@v3
with: { filters: "backend: ['hostel-backend/**']" } # skip if only frontend changed
test:
needs: changes
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { distribution: temurin, java-version: '25', cache: maven }
- run: ./mvnw -B -ntp verify # Docker is available, so Testcontainers works
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production # can require manual approval
steps:
- uses: aws-actions/configure-aws-credentials@v4
with: { role-to-assume: arn:aws:iam::123456789012:role/Deploy, aws-region: eu-west-1 }
- run: docker build -t $ECR/app:${{ github.sha }} . && docker push $ECR/app:${{ github.sha }}
OIDC: no stored cloud keys
GitHub issues a short-lived signed token saying “this is repo X, branch main”. AWS IAM trusts GitHub’s OIDC provider and lets that token assume a role. No long-lived AWS_ACCESS_KEY_ID is stored in GitHub secrets, so there’s nothing to leak.
In your projects
.github/workflows/deploy.yml“Build and Deploy to AWS Fargate”: paths-filter on backend changes, OIDC (role-to-assume: ...:role/Hostel-Github-Actions, id-token: write), then npx cdk bootstrap and npx cdk deploy --require-approval never. The infrastructure and app deploy together.
.github/workflows/backend-deploy.yml · backend-tests.ymlbackend-tests.yml runs ./mvnw -B test. The deploy workflow builds an ARM image tagged kontentt-backend:${{ github.sha }}, pushes it to ECR, then deploys with aws ssm send-command, which runs the update script on EC2 without SSH or open ports.
Report-Manager-2/.github/workflows/deploy.ymlpaths-filter, ./mvnw -B -ntp test, then build and push :latest (main) or :staging. Watchtower on the server polls the registry and restarts containers when the tag’s image changes. As a comment in ResilientPublisher notes, Watchtower “never applies docker-compose changes”, so new env vars or services still need a manual step.
Deployment strategies
| Strategy | How | Downtime / risk |
|---|---|---|
| Recreate | Stop old, start new | Downtime |
| Rolling (ECS default) | Replace instances gradually | No downtime; mixed versions briefly |
| Blue/green | Run the new version alongside, switch traffic | Instant rollback; 2× resources |
| Canary | Send 5% of traffic to the new version, watch metrics, then increase | Safest; needs good metrics |
| Feature flags | Deploy dark, enable later | Decouples deploy from release |
Hostel’s ECS service has circuit-breaker rollback: if new tasks fail health checks, ECS automatically rolls back.
Related concepts you must know
- Branch protection. Require green CI and reviews before merging to main.
- Caching Maven dependencies (
cache: maven) for fast CI. - Environments and approvals in GitHub for production gates.
- Dependabot or Renovate for dependency updates.
- For your course on Render, CI is built in: every push to the repo triggers a Render build and deploy.