Skip to content

Node.js CD

Node.js CD #331

Workflow file for this run

name: Node.js CD
on:
push:
branches: [main]
pull_request:
types:
- closed
branches: [main]
workflow_run:
workflows: ["Node.js CI"]
types:
- completed
jobs:
cd:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and Deploy Database Service
run: |
docker-compose -f docker-compose.prod.yml build db
docker-compose -f docker-compose.prod.yml up -d db
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_PORT: ${{ secrets.DB_PORT }}
- name: Build and Deploy Backend Service
run: |
docker-compose -f docker-compose.prod.yml build --no-cache backend
docker-compose -f docker-compose.prod.yml up -d backend
env:
NODE_DOCKER_PORT: ${{ secrets.NODE_DOCKER_PORT }}
GMAIL_OAUTH_USER: ${{ secrets.GMAIL_OAUTH_USER }}
GMAIL_OAUTH_CLIENT_ID: ${{ secrets.GMAIL_OAUTH_CLIENT_ID }}
GMAIL_OAUTH_CLIENT_SECRET: ${{ secrets.GMAIL_OAUTH_CLIENT_SECRET }}
GMAIL_OAUTH_REFRESH_TOKEN: ${{ secrets.GMAIL_OAUTH_REFRESH_TOKEN }}
AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }}
AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY }}
AWS_S3_REGION: ${{ secrets.AWS_S3_REGION }}
AWS_BUCKET: ${{ secrets.AWS_BUCKET }}
PEXELS_API_KEY: ${{ secrets.PEXELS_API_KEY }}
OPEN_AI_KEY: ${{ secrets.OPEN_AI_KEY }}
RABBITMQ_USER: ${{ secrets.RABBITMQ_USER }}
RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD }}
- name: Build and Deploy Frontend Service
run: |
docker-compose -f docker-compose.prod.yml build --no-cache frontend
docker-compose -f docker-compose.prod.yml up -d frontend
env:
VITE_APP_GOOGLE_ANALYTICS: ${{ secrets.VITE_APP_GOOGLE_ANALYTICS }}
VITE_APP_BUCKET_NAME: ${{ secrets.VITE_APP_BUCKET_NAME }}
VITE_APP_SECRET_ACCESS_KEY_ID: ${{ secrets.VITE_APP_SECRET_ACCESS_KEY_ID }}
VITE_APP_ACCESS_KEY_ID: ${{ secrets.VITE_APP_ACCESS_KEY_ID }}
VITE_APP_REGION: ${{ secrets.VITE_APP_REGION }}
- name: Build and Deploy Nginx Service
run: |
docker-compose -f docker-compose.prod.yml build --no-cache nginx
docker-compose -f docker-compose.prod.yml up -d nginx
- name: Build and Deploy RabbitMQ Service
run: |
docker-compose -f docker-compose.prod.yml build --no-cache rabbitmq
docker-compose -f docker-compose.prod.yml up -d rabbitmq
env:
RABBITMQ_USER: ${{ secrets.RABBITMQ_USER }}
RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD }}
- name: Execute remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.AWS_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /home/ubuntu/project
git stash
git pull origin main
docker-compose -f docker-compose.prod.yml pull
docker-compose -f docker-compose.prod.yml down
docker system prune -af
docker volume prune -f
docker-compose -f docker-compose.prod.yml up --build -d
git stash pop