Skip to content

Commit 248d4b3

Browse files
Adding workflow to deploy to DigitalOcean
1 parent 06ecee1 commit 248d4b3

File tree

4 files changed

+69
-5
lines changed

4 files changed

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

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)