Skip to content

Commit 2a7e2a6

Browse files
Adding workflow to deploy to DigitalOcean
1 parent 06ecee1 commit 2a7e2a6

File tree

8 files changed

+111
-28
lines changed

8 files changed

+111
-28
lines changed

.github/workflows/build.yaml

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

client/.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
REACT_APP_CLIENT_URL = https://localhost:3000
22
REACT_APP_SERVER_URL = https://localhost:5000
3-
REACT_APP_CDRT_SERVER1 = ws://localhost:1234
3+
REACT_APP_CRDT_SERVER = ws://localhost:1234
44
REACT_APP_NETLIFY = false

ecosystem.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
DATABASE_URL: '',
15+
GOOGLE_KEY_CLIENTID: '',
16+
GOOGLE_KEY_CLIENTSECRET: '',
17+
GITHUB_KEY_CLIENTID: '',
18+
GITHUB_KEY_CLIENTSECRET: '',
19+
COOKIE_KEYS: '',
20+
JDOODLE_CLIENTID: '',
21+
JDOOLDE_CLIENTSECRET: '',
22+
PORT: '',
23+
},
24+
},
25+
{
26+
name: 'caucus-crdt-server',
27+
script: 'npx y-websocket',
28+
watch: true,
29+
}
30+
],
31+
};

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/src/service/db_connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { DATABASE_URL, PROD } from "../config.keys";
1+
import { DATABASE_URL } from "../config.keys";
22
import Knex from "knex";
33

44
const client = Knex({
55
client: "pg",
66
connection: {
77
connectionString: DATABASE_URL,
8-
ssl: PROD,
8+
ssl: false,
99
},
1010
searchPath: ["knex", "public"],
1111
});

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)