-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (92 loc) · 3.75 KB
/
cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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