diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..7a4600a --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.SSH_KEY }} + + - name: Install PM2 + run: pnpm install -g pm2 + + - name: Deploy + run: pnpm run deploy diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3f00476..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: shell -os: linux - -services: - - docker - -script: - - ./test.sh diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..1e78e86 --- /dev/null +++ b/deploy.sh @@ -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 diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs new file mode 100644 index 0000000..ac93da8 --- /dev/null +++ b/ecosystem.config.cjs @@ -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: "git@github.com:lowercasename/gathio", + path: "/home/raphael/gathio-production", + "post-deploy": "./deploy.sh", + }, + }, +}; diff --git a/package.json b/package.json index bacccca..59f461f 100644 --- a/package.json +++ b/package.json @@ -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"