2026-08-09 03:29:16 +00:00
|
|
|
name: Build and Deploy Production
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
build-and-push:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- name: Checkout Code
|
2026-08-09 03:32:07 +00:00
|
|
|
uses: https://github.com/actions/checkout@v4
|
2026-08-09 03:29:16 +00:00
|
|
|
|
|
|
|
|
- name: Install dependencies
|
|
|
|
|
run: |
|
|
|
|
|
apk add --no-cache aws-cli docker-cli
|
|
|
|
|
|
|
|
|
|
- name: Log in to Amazon ECR
|
|
|
|
|
run: |
|
|
|
|
|
aws ecr get-login-password --region ap-south-2 | docker login --username AWS --password-stdin 764709663363.dkr.ecr.ap-south-2.amazonaws.com
|
|
|
|
|
|
|
|
|
|
- name: Build and Push Docker Image
|
|
|
|
|
run: |
|
|
|
|
|
docker build -t 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:latest -t 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:${{ github.sha }} .
|
|
|
|
|
docker push 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:latest
|
|
|
|
|
docker push 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:${{ github.sha }}
|
|
|
|
|
|
|
|
|
|
deploy:
|
|
|
|
|
needs: build-and-push
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- name: Deploy to Production EC2
|
2026-08-09 03:32:07 +00:00
|
|
|
run: |
|
|
|
|
|
apk add --no-cache openssh-client
|
|
|
|
|
mkdir -p ~/.ssh
|
|
|
|
|
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
|
|
|
chmod 600 ~/.ssh/id_rsa
|
|
|
|
|
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }} << 'EOF'
|
2026-08-09 03:29:16 +00:00
|
|
|
command -v aws &> /dev/null || sudo snap install aws-cli --classic || (sudo apt-get update && sudo apt-get install -y unzip && curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" && unzip -q awscliv2.zip && sudo ./aws/install && rm -rf awscliv2.zip ./aws)
|
|
|
|
|
aws ecr get-login-password --region ap-south-2 | sudo docker login --username AWS --password-stdin 764709663363.dkr.ecr.ap-south-2.amazonaws.com
|
|
|
|
|
sudo docker pull 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:latest
|
|
|
|
|
sudo docker stop seller-central-backend || true
|
|
|
|
|
sudo docker rm seller-central-backend || true
|
|
|
|
|
sudo docker run -d --name seller-central-backend -p 8090:8000 --restart always 764709663363.dkr.ecr.ap-south-2.amazonaws.com/seller-central-backend:latest
|
|
|
|
|
sudo docker image prune -a -f
|
2026-08-09 03:32:07 +00:00
|
|
|
EOF
|