Skip to content

Commit

Permalink
Adding workflow to deploy to DigitalOcean
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh-malhotraa committed Apr 29, 2024
1 parent 06ecee1 commit 73cce7a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 28 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/build.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/digital-ocean-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI/CD Digital Ocean PROD

on:
push:
branches: [main]

env:
REACT_APP_CLIENT_URL: ${{secrets.REACT_APP_CLIENT_URL}}
REACT_APP_SERVER_URL: ${{secrets.REACT_APP_SERVER_URL}}

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- name: 'Checkout Repository'
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install and Build Server
run: cd server && npm install && npm run build

- name: Install and Build Client
run: cd client && npm install --force && npm run build

- name: Upload to Server Digital Ocean
uses: appleboy/scp-action@master # This is the action
with:
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
key: ${{secrets.SSH_KEY}} # Private or public key of the server
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: 'server/dist' # Path to the directory you want to copy
target: '~/' # Path to the directory you want to copy to

- name: Upload to Client Digital Ocean
uses: appleboy/scp-action@master # This is the action
with:
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
key: ${{secrets.SSH_KEY}} # Private or public key of the server
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: 'client/build' # Path to the directory you want to copy
target: '/var/www/html' # Path to the directory you want to copy to

- name: Start Server
uses: appleboy/[email protected] # This is the action
with:
host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into
key: ${{secrets.SSH_KEY}} # Private or public key of the server
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into
passphrase: ${{ secrets.SSH_PASSPHRASE }}

script: |
echo $PATH
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
rm -rf ~/caucus
git clone https://github.com/Rishabh-malhotraa/caucus.git
mv ~/server/dist ~/caucus/server/
cd ~/caucus/server && npm install --production && cd ~/ && rm -rf ./server
pm2 stop caucus-server caucus-crdt-server
pm2 start ~/env/ecosystem.config.js --env production
echo 'Deployment successful to digital ocean'
2 changes: 1 addition & 1 deletion client/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REACT_APP_CLIENT_URL = https://localhost:3000
REACT_APP_SERVER_URL = https://localhost:5000
REACT_APP_CDRT_SERVER1 = ws://localhost:1234
REACT_APP_CDRT_SERVER = ws://localhost:1234
REACT_APP_NETLIFY = false
31 changes: 31 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// configuration for pm2
// pm2 start ~/env/ecosystem.config.js --env production

module.exports = {
apps: [
{
name: 'caucus-server',
script: '/root/caucus/server/dist/index.js',
watch: true,
env: {
PROD: '',
CLIENT_URL: '',
SERVER_URL: '',
DATABASE_URL: '',
GOOGLE_KEY_CLIENTID: '',
GOOGLE_KEY_CLIENTSECRET: '',
GITHUB_KEY_CLIENTID: '',
GITHUB_KEY_CLIENTSECRET: '',
COOKIE_KEYS: '',
JDOODLE_CLIENTID: '',
JDOOLDE_CLIENTSECRET: '',
PORT: '',
},
},
{
name: 'caucus-crdt-server',
script: 'npx y-websocket',
watch: true,
}
],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.tsx\"",
"lint": "eslint src/**/*.ts src/**/*.tsx",
"install-client": "cd client && npm install",
"install-client": "cd client && npm install --force",
"install-server": "cd server && npm install",
"install-modules": "npm install && npm run install-client && npm run install-server",
"client": "cd client && npm run start",
Expand Down
5 changes: 2 additions & 3 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
"main": "build/index.js",
"proxy": "https://caucus.netlify.app/",
"scripts": {
"build-ts": "tsc",
"postinstall": "npm run build-ts",
"build": "tsc",
"start": "npm run serve",
"serve": "node build/index.js",
"serve": "node dist/index.js",
"dev": "nodemon --exec ts-node src/index.ts",
"format": "prettier --write \"src/**/*.ts\""
},
Expand Down
4 changes: 2 additions & 2 deletions server/src/service/db_connection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DATABASE_URL, PROD } from "../config.keys";
import { DATABASE_URL } from "../config.keys";
import Knex from "knex";

const client = Knex({
client: "pg",
connection: {
connectionString: DATABASE_URL,
ssl: PROD,
ssl: false,
},
searchPath: ["knex", "public"],
});
Expand Down
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand Down

0 comments on commit 73cce7a

Please sign in to comment.