Skip to content

Commit 4354fb2

Browse files
Adding workflow to deploy to DigitalOcean
1 parent 06ecee1 commit 4354fb2

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI/CD Digital Ocean PROD
2+
3+
on:
4+
push:
5+
branches: [deploy]
6+
7+
env:
8+
REACT_APP_CLIENT_URL: ${{secrets.REACT_APP_CLIENT_URL}}
9+
REACT_APP_SERVER_URL: ${{secrets.REACT_APP_SERVER_URL}}
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [14.x]
18+
19+
steps:
20+
- name: 'Checkout Repository'
21+
uses: actions/checkout@v2
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Install and Build Server
29+
run: cd server && npm install && npm run build
30+
31+
- name: Install and Build Client
32+
run: cd client && npm install --force --production && npm run build
33+
34+
- name: Upload to Server Digital Ocean
35+
uses: appleboy/scp-action@master # This is the action
36+
with:
37+
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
38+
key: ${{secrets.SSH_KEY}} # Private or public key of the server
39+
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
40+
passphrase: ${{ secrets.SSH_PASSPHRASE }}
41+
source: 'server/dist' # Path to the directory you want to copy
42+
target: '~/' # Path to the directory you want to copy to
43+
44+
- name: Upload to Client Digital Ocean
45+
uses: appleboy/scp-action@master # This is the action
46+
with:
47+
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
48+
key: ${{secrets.SSH_KEY}} # Private or public key of the server
49+
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
50+
passphrase: ${{ secrets.SSH_PASSPHRASE }}
51+
source: 'client/build' # Path to the directory you want to copy
52+
target: '/var/www/html' # Path to the directory you want to copy to
53+
54+
- name: Start Server
55+
uses: appleboy/[email protected] # This is the action
56+
with:
57+
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
58+
key: ${{secrets.SSH_KEY}} # Private or public key of the server
59+
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
60+
passphrase: ${{ secrets.SSH_PASSPHRASE }}
61+
62+
script: |
63+
rm -rf ~/caucus
64+
git clone https://github.com/Rishabh-malhotraa/caucus.git
65+
mv ~/server/dist ~/caucus/server/
66+
cd ~/caucus/server && npm install --production && cd ~/ && rm -rf ./server
67+
pm2 stop caucus-server caucus-crdt-server
68+
pm2 start ~/env/ecosystem.config.js --env production
69+
echo 'Deployment successful to digital ocean'

ecosystem.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// configuration for pm2
2+
// pm2 start ~/env/ecosystem.config.js --env production
3+
4+
module.exports = {
5+
apps: [
6+
{
7+
name: 'caucus-server',
8+
script: '/root/caucus/server/dist/index.js',
9+
watch: true,
10+
env: {
11+
PROD : '',
12+
CLIENT_URL: '',
13+
SERVER_URL: '',
14+
GOOGLE_KEY_CLIENTID: '',
15+
GOOGLE_KEY_CLIENTSECRET: '',
16+
GITHUB_KEY_CLIENTID: '',
17+
GITHUB_KEY_CLIENTSECRET: '',
18+
COOKIE_KEYS: '',
19+
JDOODLE_CLIENTID: '',
20+
JDOOLDE_CLIENTSECRET: '',
21+
PORT: '',
22+
},
23+
},
24+
{
25+
name : 'caucus-crdt-server',
26+
script: 'npx y-websocket',
27+
watch: true,
28+
}
29+
],
30+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.tsx\"",
1717
"lint": "eslint src/**/*.ts src/**/*.tsx",
18-
"install-client": "cd client && npm install",
18+
"install-client": "cd client && npm install --force",
1919
"install-server": "cd server && npm install",
2020
"install-modules": "npm install && npm run install-client && npm run install-server",
2121
"client": "cd client && npm run start",

server/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
"main": "build/index.js",
1414
"proxy": "https://caucus.netlify.app/",
1515
"scripts": {
16-
"build-ts": "tsc",
17-
"postinstall": "npm run build-ts",
16+
"build": "tsc",
1817
"start": "npm run serve",
19-
"serve": "node build/index.js",
18+
"serve": "node dist/index.js",
2019
"dev": "nodemon --exec ts-node src/index.ts",
2120
"format": "prettier --write \"src/**/*.ts\""
2221
},

server/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1515
// "sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
17-
"outDir": "./build" /* Redirect output structure to the directory. */,
17+
"outDir": "./dist" /* Redirect output structure to the directory. */,
1818
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
1919
// "composite": true, /* Enable project compilation */
2020
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */

0 commit comments

Comments
 (0)