Skip to content

Add rollback system documentation and implement multi-version rollbac… #71

Add rollback system documentation and implement multi-version rollbac…

Add rollback system documentation and implement multi-version rollbac… #71

Workflow file for this run

name: FieldTrack Backend CI/CD
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
working-directory: backend
run: npm ci
- name: TypeScript compilation check
working-directory: backend
run: npx tsc --noEmit
- name: Run tests
working-directory: backend
run: npm run test
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
needs: test
# Only run on push to master, not on PRs
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract commit SHA
run: echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: |
ghcr.io/rajashish147/fieldtrack-backend:${{ env.SHA_SHORT }}
ghcr.io/rajashish147/fieldtrack-backend:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USER }}
key: ${{ secrets.DO_SSH_KEY }}
script: |
cd /home/ashish/FieldTrack-2.0/backend
git fetch origin
git reset --hard origin/master
chmod +x scripts/deploy-bluegreen.sh
./scripts/deploy-bluegreen.sh ${{ env.SHA_SHORT }}