fix build
This commit is contained in:
parent
8ba1239685
commit
94f90d3c7f
1 changed files with 116 additions and 7 deletions
|
|
@ -3,10 +3,9 @@ name: Build and Deploy Backend
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
paths:
|
||||
- 'Backend/**'
|
||||
- "Backend/**"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
|
|
@ -14,6 +13,13 @@ env:
|
|||
REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
|
||||
|
||||
# Docker Image
|
||||
BACKEND_IMAGE_NAME: chamomind/elearning-backend
|
||||
IMAGE_TAG: ${{ github.sha }}
|
||||
|
||||
# Notifications
|
||||
DISCORD_WEBHOOK_URL: ${{ vars.DISCORD_WEBHOOK_URL }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Backend Docker Image
|
||||
|
|
@ -41,7 +47,7 @@ jobs:
|
|||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/elearning-backend
|
||||
images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=sha,prefix=
|
||||
|
|
@ -59,16 +65,119 @@ jobs:
|
|||
cache-to: type=gha,mode=max
|
||||
|
||||
deploy:
|
||||
name: Deploy Backend to Server
|
||||
name: Deploy E-learning Backend to Dev Server
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
steps:
|
||||
- name: Remote Deploy
|
||||
- name: Deploy backend on server
|
||||
uses: appleboy/ssh-action@v1.2.1
|
||||
with:
|
||||
host: ${{ vars.SSH_DEPLOY_HOST }}
|
||||
port: ${{ vars.SSH_DEPLOY_PORT }}
|
||||
username: ${{ secrets.SSH_DEPLOY_USER }}
|
||||
password: ${{ secrets.SSH_DEPLOY_PASSWORD }}
|
||||
script: eval "${{ secrets.SSH_DEPLOY_BACKEND_CMD }}"
|
||||
script: |
|
||||
cd ~/repo
|
||||
chmod +x ./replace-env.sh ./deploy.sh
|
||||
./replace-env.sh BACKEND_TAG "${{ env.IMAGE_TAG }}"
|
||||
./deploy.sh elearning-backend
|
||||
|
||||
notify:
|
||||
name: Notify Deployment Status
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build, deploy]
|
||||
if: always()
|
||||
steps:
|
||||
- name: Send Discord notification - Success
|
||||
if: ${{ needs.deploy.result == 'success' }}
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "✅ E-learning Backend Deployment Successful",
|
||||
"description": "E-learning Backend deployed to dev server",
|
||||
"color": 3066993,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Environment",
|
||||
"value": "Development",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Branch",
|
||||
"value": "${{ github.ref_name }}",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Commit",
|
||||
"value": "`${{ github.sha }}`",
|
||||
"inline": false
|
||||
},
|
||||
{
|
||||
"name": "Image Tag",
|
||||
"value": "`${{ env.IMAGE_TAG }}`",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Web URL",
|
||||
"value": "${{ env.NEXT_PUBLIC_APP_URL }}",
|
||||
"inline": false
|
||||
},
|
||||
{
|
||||
"name": "Deployed By",
|
||||
"value": "${{ github.actor }}",
|
||||
"inline": true
|
||||
}
|
||||
],
|
||||
"footer": {
|
||||
"text": "CMP CD Pipeline"
|
||||
},
|
||||
"timestamp": "'"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)"'"
|
||||
}]
|
||||
}' \
|
||||
${{ env.DISCORD_WEBHOOK_URL }}
|
||||
|
||||
- name: Send Discord notification - Failure
|
||||
if: ${{ needs.deploy.result == 'failure' || needs.build.result == 'failure' }}
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "❌ E-learning Backend Deployment Failed",
|
||||
"description": "Failed to deploy E-learning Backend to dev server",
|
||||
"color": 15158332,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Environment",
|
||||
"value": "Development",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Branch",
|
||||
"value": "${{ github.ref_name }}",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Commit",
|
||||
"value": "`${{ github.sha }}`",
|
||||
"inline": false
|
||||
},
|
||||
{
|
||||
"name": "Failed Job",
|
||||
"value": "${{ needs.build.result == 'failure' && 'Build' || 'Deploy' }}",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Deployed By",
|
||||
"value": "${{ github.actor }}",
|
||||
"inline": true
|
||||
}
|
||||
],
|
||||
"footer": {
|
||||
"text": "CMP CD Pipeline"
|
||||
},
|
||||
"timestamp": "'"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)"'"
|
||||
}]
|
||||
}' \
|
||||
${{ env.DISCORD_WEBHOOK_URL }}
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue