Skip to content

ci: test perfomance

ci: test perfomance #6

Workflow file for this run

name: CD - Continuous Deployment
on:
push:
branches:
- main
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
type: choice
options:
- staging
- production
default: 'staging'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
image-digest: ${{ steps.build.outputs.digest }}
steps:
- name: Checkout code
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=semver,pattern={{major}}
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
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' || github.event.inputs.environment == 'staging'
environment:
name: staging
url: https://staging.example.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
echo "Image: ${{ needs.build.outputs.image-tag }}"
echo "Digest: ${{ needs.build.outputs.image-digest }}"
# Add your deployment commands here
# Example: kubectl set image deployment/app app=${{ needs.build.outputs.image-tag }}
# Example: ssh user@staging-server "docker pull ${{ needs.build.outputs.image-tag }} && docker-compose up -d"
- name: Run smoke tests
run: |
echo "Running smoke tests on staging..."
# Add smoke tests here
# Example: curl -f https://staging.example.com/health || exit 1
- name: Notify deployment
if: always()
run: |
echo "Staging deployment completed"
echo "Status: ${{ job.status }}"
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, deploy-staging]
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.environment == 'production'
environment:
name: production
url: https://example.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to production
run: |
echo "Deploying to production environment..."
echo "Image: ${{ needs.build.outputs.image-tag }}"
echo "Digest: ${{ needs.build.outputs.image-digest }}"
# Add your deployment commands here
# Example: kubectl set image deployment/app app=${{ needs.build.outputs.image-tag }}
# Example: ssh user@prod-server "docker pull ${{ needs.build.outputs.image-tag }} && docker-compose up -d"
- name: Run smoke tests
run: |
echo "Running smoke tests on production..."
# Add smoke tests here
# Example: curl -f https://example.com/health || exit 1
- name: Notify deployment
if: always()
run: |
echo "Production deployment completed"
echo "Status: ${{ job.status }}"
# Add notification logic (Slack, Discord, email, etc.)
rollback:
name: Rollback on Failure
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: failure()
steps:
- name: Rollback deployment
run: |
echo "Deployment failed, initiating rollback..."
# Add rollback commands here
# Example: kubectl rollout undo deployment/app
- name: Notify rollback
run: |
echo "Rollback completed"
# Add notification logic