Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PM2 deployment config #103

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI / Deploy
on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Set up known_hosts file
run: |
mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts
ssh-keyscan -t rsa ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts

- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}

- name: Install PM2
run: pnpm install -g pm2

- name: Deploy
run: pnpm run deploy
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

# Set up and redeploy Gathio. Called by `pm2 deploy`.

# PM2 doesn't load the user env, so this gets nvm into the PATH
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
# Set the right Node version
nvm use
# Need to use `development` here else pnpm won't install devDependencies (i.e. tsc)
NODE_ENV=development pnpm install
# This calls `tsc`, which fails due to type errors while we're transitioning
# fully to TypeScript, so we short-circuit it to true to continue running the
# deploy script. TODO: Remove this short-circuit when we've migrated to
# TypeScript and don't expect any more errors.
pnpm build || true
pm2 reload ecosystem.config.cjs production
pm2 save
24 changes: 24 additions & 0 deletions ecosystem.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
apps: [
{
name: "gathio-prod",
script: "pnpm start",
watch: false,
instances: 1,
autorestart: true,
max_restarts: 10,
max_memory_restart: "512M",
},
],

deploy: {
production: {
user: "raphael",
host: "gath.io",
ref: "origin/main",
repo: "[email protected]:lowercasename/gathio",
path: "/home/raphael/gathio-production",
"post-deploy": "./deploy.sh",
},
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "node dist/start.js",
"dev": "nodemon -e ts,js --watch src --exec \"pnpm run build ; pnpm run start\"",
"test:dev": "pnpm run dev & wait-on http://localhost:3000 && cypress open --e2e --browser chrome",
"test": "pnpm run build || true && pnpm run start & wait-on http://localhost:3000 && cypress run --e2e --browser chrome"
"test": "pnpm run build || true && pnpm run start & wait-on http://localhost:3000 && cypress run --e2e --browser chrome",
"deploy": "pm2 deploy ecosystem.config.cjs production"
},
"engines": {
"node": ">=16.16.0"
Expand Down
Loading