Merge pull request #14 from Hermi-git/final_implementations #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Production | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'backend/**' | |
| - 'frontend/**' | |
| - '.github/workflows/deploy.yml' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Deployment environment' | |
| required: true | |
| default: 'staging' | |
| type: choice | |
| options: | |
| - staging | |
| - production | |
| jobs: | |
| deployment: | |
| name: Deploy to ${{ github.event.inputs.environment || 'staging' }} | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: ${{ github.event.inputs.environment || 'staging' }} | |
| url: ${{ steps.deploy.outputs.app_url }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Log in to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Build, tag, and push backend image to Amazon ECR | |
| id: image-backend | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: mindvault-backend | |
| IMAGE_TAG: ${{ github.sha }} | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG backend/ | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| - name: Build, tag, and push frontend image to Amazon ECR | |
| id: image-frontend | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: mindvault-frontend | |
| IMAGE_TAG: ${{ github.sha }} | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG frontend/ | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| - name: Update ECS task definition (Backend) | |
| id: task-def-backend | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: infra/ecs-task-definition-backend.json | |
| container-name: mindvault-backend | |
| image: ${{ steps.image-backend.outputs.image }} | |
| - name: Deploy to Amazon ECS (Backend) | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
| with: | |
| task-definition: ${{ steps.task-def-backend.outputs.task-definition }} | |
| service: mindvault-backend-${{ github.event.inputs.environment || 'staging' }} | |
| cluster: mindvault-cluster | |
| wait-for-service-stability: true | |
| - name: Update ECS task definition (Frontend) | |
| id: task-def-frontend | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: infra/ecs-task-definition-frontend.json | |
| container-name: mindvault-frontend | |
| image: ${{ steps.image-frontend.outputs.image }} | |
| - name: Deploy to Amazon ECS (Frontend) | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
| with: | |
| task-definition: ${{ steps.task-def-frontend.outputs.task-definition }} | |
| service: mindvault-frontend-${{ github.event.inputs.environment || 'staging' }} | |
| cluster: mindvault-cluster | |
| wait-for-service-stability: true | |
| - name: Get deployment URL | |
| id: deploy | |
| run: | | |
| FRONTEND_URL=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?contains(LoadBalancerName, 'mindvault-frontend')].DNSName" --output text) | |
| echo "app_url=https://$FRONTEND_URL" >> $GITHUB_OUTPUT | |
| - name: Slack notification - Success | |
| if: success() | |
| uses: slackapi/slack-github-action@v1.24.0 | |
| with: | |
| payload: | | |
| { | |
| "text": "MindVault deployment successful", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*Deployment Success* \nEnvironment: ${{ github.event.inputs.environment || 'staging' }}\nCommit: ${{ github.sha }}\nBranch: ${{ github.ref }}" | |
| } | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| - name: Slack notification - Failure | |
| if: failure() | |
| uses: slackapi/slack-github-action@v1.24.0 | |
| with: | |
| payload: | | |
| { | |
| "text": "MindVault deployment failed", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*Deployment Failed* \nEnvironment: ${{ github.event.inputs.environment || 'staging' }}\nCommit: ${{ github.sha }}" | |
| } | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |