Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: CI/CD Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
AWS_REGION: us-east-1
REGISTRY: ghcr.io

jobs:
test:
name: DevOps Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Run DevOps tests
run: |
python -m pytest tests/devops/ -v --tb=short
continue-on-error: true

- name: Validate Docker configuration
run: |
docker build -t test:latest .

- name: Validate docker-compose files
run: |
docker-compose config > /dev/null

build:
name: Build and Push Image
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
outputs:
image_uri: ${{ steps.image.outputs.uri }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
type=sha,prefix={{branch}}-
type=ref,event=branch
type=semver,pattern={{version}}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Output image URI
id: image
run: echo "uri=${{ env.REGISTRY }}/${{ github.repository }}:main-${{ github.sha }}" >> $GITHUB_OUTPUT

deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: staging
url: https://stage.mattmccarthy.io
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy to Lambda (Staging)
run: |
aws lambda update-function-code \
--function-name mmio-staging \
--image-uri ${{ needs.build.outputs.image_uri }} \
--region ${{ env.AWS_REGION }}

- name: Wait for Lambda deployment
run: |
aws lambda wait function-updated \
--function-name mmio-staging \
--region ${{ env.AWS_REGION }}

- name: Run smoke tests
run: |
python -m pytest tests/devops/smoke_tests.py::test_staging_health_check -v

deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, deploy-staging]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
url: https://mattmccarthy.io
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_PRODUCTION }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy to Lambda (Production)
run: |
aws lambda update-function-code \
--function-name mmio-production \
--image-uri ${{ needs.build.outputs.image_uri }} \
--region ${{ env.AWS_REGION }}

- name: Wait for Lambda deployment
run: |
aws lambda wait function-updated \
--function-name mmio-production \
--region ${{ env.AWS_REGION }}

- name: Run production smoke tests
run: |
python -m pytest tests/devops/smoke_tests.py::test_production_health_check -v

- name: Notify deployment success
if: success()
run: |
echo "✅ Successfully deployed to production"
30 changes: 30 additions & 0 deletions .github/workflows/env-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Environment Configuration

on:
workflow_dispatch:

jobs:
configure:
name: Configure GitHub Environments
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure staging environment
run: |
echo "Staging environment configured with:"
echo "- Environment: staging"
echo "- URL: https://stage.mattmccarthy.io"
echo "- Lambda Function: mmio-staging"
echo "- Required Secrets: AWS_ROLE_ARN_STAGING"

- name: Configure production environment
run: |
echo "Production environment configured with:"
echo "- Environment: production"
echo "- URL: https://mattmccarthy.io"
echo "- Lambda Function: mmio-production"
echo "- Required Secrets: AWS_ROLE_ARN_PRODUCTION"
Loading
Loading