-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (145 loc) · 5.97 KB
/
deployment.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Deployment CI
on: [ push, pull_request ]
jobs:
# BUILD PROJECT AND DEPENDENCIES
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.19.1 ]
steps:
- uses: actions/checkout@v4
- name: Cache project node-modules
uses: actions/cache@v4
with:
path: 'node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# pipeline actions
- run: npm ci
- run: npm run build
# RUN TESTS
test:
needs: [ build ]
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout@v4
- name: Cache project node-modules
uses: actions/cache@v4
with:
path: 'node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install codecov dependency
run: npm install -g codecov
# pipeline actions
- run: npm run lint
- run: npm test
- run: codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# DEPLOY PROJECT (DEVELOP)
deploy-dev:
needs: [ test ]
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create env variables file
run: ./create_env_file.sh
env:
NODE_ENV: development
DATABASE_HOST: ${{ secrets.DEV__DATABASE_HOST }}
DATABASE_PORT: ${{ secrets.DEV__DATABASE_PORT }}
DATABASE_NAME: ${{ secrets.DEV__DATABASE_NAME }}
DATABASE_USERNAME: ${{ secrets.DEV__DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.DEV__DATABASE_PASSWORD }}
CORS: false
ORIGINS: '*'
BLOG_RESOURCES: ${{ secrets.DEV__BLOG_RESOURCES }}
SITE_URL: https://dev.binary-coffee.dev
API_URL: https://api-dev.binary-coffee.dev
JWT_SECRET: ${{ secrets.DEV__JWT_SECRET }}
ADMIN_JWT_SECRET: ${{ secrets.DEV__ADMIN_JWT_SECRET }}
SECRET: ${{ secrets.DEV__SECRET }}
GITHUB_CLIENT_ID: ${{ secrets.DEV__GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.DEV__GITHUB_CLIENT_SECRET }}
SMTP_HOST: ${{ secrets.PROD__SMTP_HOST }}
SMTP_PORT: ${{ secrets.PROD__SMTP_PORT }}
SMTP_USERNAME: ${{ secrets.PROD__SMTP_USERNAME }}
SMTP_PASSWORD: ${{ secrets.PROD__SMTP_PASSWORD }}
BOT_NOTIFICATION_TOKEN: ${{ secrets.BOT_NOTIFICATION_TOKEN }}
- name: Copy project to the hosting
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
ARGS: "-rltgoDzvO --delete"
SOURCE: ""
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.DEV__REMOTE_TARGET }}
- name: Deploy project with docker in hosting
uses: garygrossgarten/github-action-ssh@release
with:
command: cd ${{ secrets.DEV__REMOTE_TARGET }} && BACKEND_PORT=${{ secrets.DEV__BACKEND_PORT }} ./deploy.sh blog-api-dev
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
privateKey: ${{ secrets.SERVER_SSH_KEY}}
# DEPLOY PROJECT (PRODUCTION)
deploy-prod:
needs: [ test ]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create env variables file
run: ./create_env_file.sh
env:
NODE_ENV: production
DATABASE_HOST: ${{ secrets.PROD__DATABASE_HOST }}
DATABASE_PORT: ${{ secrets.PROD__DATABASE_PORT }}
DATABASE_NAME: ${{ secrets.PROD__DATABASE_NAME }}
DATABASE_USERNAME: ${{ secrets.PROD__DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.PROD__DATABASE_PASSWORD }}
CORS: false
ORIGINS: '*'
BLOG_RESOURCES: ${{ secrets.PROD__BLOG_RESOURCES }}
SITE_URL: https://binarycoffee.dev
API_URL: https://api.binarycoffee.dev
JWT_SECRET: ${{ secrets.PROD__JWT_SECRET }}
ADMIN_JWT_SECRET: ${{ secrets.PROD__ADMIN_JWT_SECRET }}
SECRET: ${{ secrets.PROD__SECRET }}
GITHUB_CLIENT_ID: ${{ secrets.PROD__GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.PROD__GITHUB_CLIENT_SECRET }}
SMTP_HOST: ${{ secrets.PROD__SMTP_HOST }}
SMTP_PORT: ${{ secrets.PROD__SMTP_PORT }}
SMTP_USERNAME: ${{ secrets.PROD__SMTP_USERNAME }}
SMTP_PASSWORD: ${{ secrets.PROD__SMTP_PASSWORD }}
BOT_NOTIFICATION_TOKEN: ${{ secrets.BOT_NOTIFICATION_TOKEN }}
- name: Copy project to the hosting
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.PROD__SERVER_SSH_KEY }}
ARGS: "-rltgoDzvO --delete"
SOURCE: ""
REMOTE_HOST: ${{ secrets.PROD__REMOTE_HOST }}
REMOTE_USER: ${{ secrets.PROD__REMOTE_USER }}
TARGET: ${{ secrets.PROD__REMOTE_TARGET }}
- name: Deploy project with docker in hosting
uses: garygrossgarten/github-action-ssh@release
with:
command: cd ${{ secrets.PROD__REMOTE_TARGET }} && BACKEND_PORT=${{ secrets.PROD__BACKEND_PORT }} ./deploy.sh blog-api-prod-v4
host: ${{ secrets.PROD__REMOTE_HOST }}
username: ${{ secrets.PROD__REMOTE_USER }}
privateKey: ${{ secrets.PROD__SERVER_SSH_KEY}}