Skip to content

Merge pull request #261 from emmanuelist/feature/error-boundaries #47

Merge pull request #261 from emmanuelist/feature/error-boundaries

Merge pull request #261 from emmanuelist/feature/error-boundaries #47

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
- develop
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy to"
required: true
type: choice
options:
- staging
- production
jobs:
build-and-push:
name: Build and Push Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
backend-tag: ${{ steps.meta-backend.outputs.tags }}
frontend-tag: ${{ steps.meta-frontend.outputs.tags }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for backend
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/backend
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract metadata for frontend
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/frontend
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
continue-on-error: true
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/develop' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
environment:
name: staging
url: https://staging.stellarbridgewatch.io
steps:
- uses: actions/checkout@v4
- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
echo "Backend image: ${{ needs.build-and-push.outputs.backend-tag }}"
echo "Frontend image: ${{ needs.build-and-push.outputs.frontend-tag }}"
# Add your deployment commands here (e.g., kubectl, helm, docker-compose)
# Example: kubectl set image deployment/backend backend=${{ needs.build-and-push.outputs.backend-tag }}
- name: Run smoke tests
run: |
echo "Running smoke tests against staging..."
# Add smoke test commands here
# Example: curl -f https://staging.stellarbridgewatch.io/health || exit 1
- name: Notify deployment
if: always()
run: |
echo "Staging deployment completed with status: ${{ job.status }}"
# Add notification logic (Slack, Discord, etc.)
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
environment:
name: production
url: https://stellarbridgewatch.io
steps:
- uses: actions/checkout@v4
- name: Deploy to production
run: |
echo "Deploying to production environment..."
echo "Backend image: ${{ needs.build-and-push.outputs.backend-tag }}"
echo "Frontend image: ${{ needs.build-and-push.outputs.frontend-tag }}"
# Add your deployment commands here
# Example: kubectl set image deployment/backend backend=${{ needs.build-and-push.outputs.backend-tag }}
- name: Run smoke tests
run: |
echo "Running smoke tests against production..."
# Add smoke test commands here
# Example: curl -f https://stellarbridgewatch.io/health || exit 1
- name: Notify deployment
if: always()
run: |
echo "Production deployment completed with status: ${{ job.status }}"
# Add notification logic (Slack, Discord, email, etc.)
rollback:
name: Rollback Deployment
runs-on: ubuntu-latest
if: failure()
needs: [deploy-staging, deploy-production]
environment:
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
steps:
- name: Rollback
run: |
echo "Rolling back deployment..."
# Add rollback commands here
# Example: kubectl rollout undo deployment/backend