Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Merge pull request #81 from igrowker/franco-back #7

Merge pull request #81 from igrowker/franco-back

Merge pull request #81 from igrowker/franco-back #7

name: CI/CD Pipeline (Back)
on:
push:
branches:
- develop
- main
workflow_dispatch:
inputs:
environment:
description: "Choose deployment environment"
required: true
type: choice
options:
- development
- production
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Dependencies
run: npm install
- name: Build Application
run: npm run build
build-and-push-docker:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker Images
uses: docker/build-push-action@v6
with:
context: ../../Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pawsome-node:backend
${{ secrets.DOCKERHUB_USERNAME }}/pawsome-node:${{ github.sha }}
deploy-to-render:
runs-on: ubuntu-latest
needs: build-and-push-docker
if: ${{ github.ref_name == 'develop' || github.event.inputs.environment == 'development' }}
steps:
- name: Trigger Render Deployment
uses: fjogeleit/http-request-action@v1
with:
url: ${{ secrets.RENDER_DEPLOY_DEV_HOOK }}
method: GET
deploy-to-aws:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout Backend Code
uses: actions/checkout@v3
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.AWS_SSH_KEY }}" > ~/.ssh/aws-key.pem
chmod 400 ~/.ssh/aws-key.pem
- name: Deploy Backend to AWS EC2
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/aws-key.pem ec2-user@your-ec2-public-ip "
cd ../../i004-pawsome-back || git clone https://github.com/igrowker/i004-pawsome-back ../.. && cd /i004-pawsome-back;
git pull;
npm install;
npm run build;
pm2 reload ecosystem.config.js || pm2 start ecosystem.config.js --env production
"