Skip to content

Add README.md — generated by Oracle1 #6

Add README.md — generated by Oracle1

Add README.md — generated by Oracle1 #6

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
type: choice
options:
- staging
- production
skip_tests:
description: 'Skip smoke tests'
required: false
type: boolean
default: false
env:
NODE_VERSION: '20'
REGISTRY: 'ghcr.io'
IMAGE_NAME: '${{ github.repository }}'
permissions:
contents: read
packages: write
deployments: write
id-token: write
jobs:
# Build and push Docker images
docker:
name: Build Docker Images
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
image_digest: ${{ steps.build.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
build-args: |
NODE_VERSION=${{ env.NODE_VERSION }}
BUILD_DATE=${{ github.event.head_commit.timestamp }}
VCS_REF=${{ github.sha }}
# Deploy to staging
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: docker
if: github.ref == 'refs/heads/main' || github.event.inputs.environment == 'staging'
environment:
name: staging
url: https://staging.example.com
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure kubectl
run: |
echo "Configuring kubectl for staging..."
# In production, use kubectl or helm to deploy
# Example: helm upgrade --install lsi-staging ./charts/lsi --namespace staging
- name: Deploy to staging
run: |
echo "Deploying ${{ needs.docker.outputs.image_tag }} to staging..."
# Example deployment command
# kubectl set image deployment/lsi lsi=${{ needs.docker.outputs.image_tag }} -n staging
- name: Verify deployment
run: |
echo "Verifying staging deployment..."
# kubectl rollout status deployment/lsi -n staging --timeout=5m
- name: Record deployment
uses: chrnorm/deployment-action@v2
with:
token: '${{ github.token }}'
environment-url: 'https://staging.example.com'
environment: 'staging'
description: 'Deploy to staging'
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
# Deploy to production (requires manual approval)
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [docker, deploy-staging, smoke-tests]
if: github.event.inputs.environment == 'production'
environment:
name: production
url: https://example.com
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure kubectl
run: |
echo "Configuring kubectl for production..."
- name: Deploy to production
run: |
echo "Deploying ${{ needs.docker.outputs.image_tag }} to production..."
# Example: helm upgrade --install lsi-prod ./charts/lsi --namespace production
- name: Verify deployment
run: |
echo "Verifying production deployment..."
# kubectl rollout status deployment/lsi -n production --timeout=10m
- name: Record deployment
uses: chrnorm/deployment-action@v2
with:
token: '${{ github.token }}'
environment-url: 'https://example.com'
environment: 'production'
description: 'Deploy to production'
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
initial-status: 'success'
# Run smoke tests
smoke-tests:
name: Smoke Tests
runs-on: ubuntu-latest
needs: deploy-staging
if: github.event.inputs.skip_tests != 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run smoke tests
run: |
echo "Running smoke tests against staging..."
# npm run test:smoke -- --env=staging
# Example health checks:
# - API endpoints
# - Database connections
# - External service integrations
echo "Smoke tests passed!"
- name: Health check
run: |
echo "Performing health check..."
# curl -f https://staging.example.com/health || exit 1
# Rollback on failure
rollback-staging:
name: Rollback Staging
runs-on: ubuntu-latest
needs: [deploy-staging, smoke-tests]
if: failure()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Rollback staging deployment
run: |
echo "Rolling back staging deployment..."
# kubectl rollout undo deployment/lsi -n staging
- name: Verify rollback
run: |
echo "Verifying rollback..."
# kubectl rollout status deployment/lsi -n staging
- name: Notify rollback
run: |
echo "Rollback completed. Check logs for failure details."
# Rollback production on failure
rollback-production:
name: Rollback Production
runs-on: ubuntu-latest
needs: deploy-production
if: failure()
environment:
name: production
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Rollback production deployment
run: |
echo "Rolling back production deployment..."
# kubectl rollout undo deployment/lsi -n production
- name: Verify rollback
run: |
echo "Verifying rollback..."
# kubectl rollout status deployment/lsi -n production
- name: Create incident
run: |
echo "Creating incident for production rollback..."
# Create GitHub issue or integrate with incident management system
# Deployment summary
deployment-summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [docker, deploy-staging, smoke-tests, deploy-production]
if: always()
steps:
- name: Generate deployment summary
run: |
echo "## Deployment Summary 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Environment | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Docker Build | ${{ needs.docker.result == 'success' && '✅ Success' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Staging | ${{ needs.deploy-staging.result == 'success' && '✅ Deployed' || needs.deploy-staging.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Smoke Tests | ${{ needs.smoke-tests.result == 'success' && '✅ Passed' || needs.smoke-tests.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Production | ${{ needs.deploy-production.result == 'success' && '✅ Deployed' || needs.deploy-production.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ needs.docker.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
# Post-deployment notifications
notify:
name: Send Notifications
runs-on: ubuntu-latest
needs: [deployment-summary]
if: always()
steps:
- name: Determine deployment status
id: status
run: |
if [[ "${{ needs.deployment-summary.result }}" == "success" ]]; then
echo "status=success" >> $GITHUB_OUTPUT
echo "color=28a745" >> $GITHUB_OUTPUT
echo "message=Deployment completed successfully" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
echo "color=dc3545" >> $GITHUB_OUTPUT
echo "message=Deployment failed" >> $GITHUB_OUTPUT
fi
- name: Send Slack notification
if: env.SLACK_WEBHOOK_URL != ''
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST ${{ secrets.SLACK_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d '{
"text": "${{ steps.status.outputs.message }}",
"attachments": [{
"color": "${{ steps.status.outputs.color }}",
"fields": [
{"title": "Repository", "value": "${{ github.repository }}"},
{"title": "Branch", "value": "${{ github.ref_name }}"},
{"title": "Commit", "value": "${{ github.sha }}"},
{"title": "Actor", "value": "${{ github.actor }}"}
]
}]
}' || true