Skip to content

Commit

Permalink
Set up production deploy pipeline (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumManiac authored Feb 23, 2024
1 parent 78fe2ab commit 8c384ad
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Move files to dist
run: |
mv .env ./dist/
mv ecosystem.config.js ./dist/
mv ./deploy/development/ecosystem.config.js ./dist/
- name: Copy files to server
uses: appleboy/scp-action@master
with:
Expand All @@ -64,7 +64,7 @@ jobs:
# Check if PM2 started the application successfully
echo "Checking PM2 process status..."
if pm2 jlist | jq -e 'any(.pm2_env.status == "online")' > /dev/null; then
if pm2 jlist | jq -e 'any(.[]; .name == "minerva-dev" and .pm2_env.status == "online")' > /dev/null; then
echo "PM2 application is running."
exit 0
else
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy to Production

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy Process
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install Dependencies
run: corepack enable && yarn install --immutable
- name: Run unit tests
run: yarn test
- name: Build
run: yarn build
- name: Generate .env file
run: |
touch .env
echo NODE_ENV=production >> .env
echo GOOGLE_ACCOUNT_CLIENT=${{ secrets.GOOGLE_ACCOUNT_CLIENT }} >> .env
echo GOOGLE_ACCOUNT_SECRET=${{ secrets.GOOGLE_ACCOUNT_SECRET }} >> .env
echo GOOGLE_ACCOUNT_TOKEN=${{ secrets.GOOGLE_ACCOUNT_TOKEN }} >> .env
echo GOOGLE_ACCOUNT_OAUTH_REDIRECT=${{ vars.GOOGLE_ACCOUNT_OAUTH_REDIRECT }} >> .env
echo SLACK_APP_TOKEN=${{ secrets.SLACK_APP_TOKEN }} >> .env
echo SLACK_OAUTH_TOKEN=${{ secrets.SLACK_OAUTH_TOKEN }} >> .env
echo SLACK_SIGNING_SECRET=${{ secrets.SLACK_SIGNING_SECRET }} >> .env
echo DEPLOY_COMMIT_SHA=${{ github.sha }} >> .env
- name: Move files to dist
run: |
mv .env ./dist/
mv ./deploy/production/ecosystem.config.js ./dist/
- name: Copy files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_KEY }}
source: dist/
target: ~/minerva/
strip_components: 1
- name: Start pm2 process and monitor startup
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_KEY }}
script: |
cd ~/minerva
echo "Starting the application with PM2."
pm2 start ecosystem.config.js
echo "Waiting for the application to stabilize."
sleep 10
# Check if PM2 started the application successfully
echo "Checking PM2 process status..."
if pm2 jlist | jq -e 'any(.[]; .name == "minerva" and .pm2_env.status == "online")' > /dev/null; then
echo "PM2 application is running."
exit 0
else
echo "PM2 application has failed to start."
exit 1
fi
File renamed without changes.
13 changes: 13 additions & 0 deletions deploy/production/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
apps: [
{
name: "minerva",
script: "node ./bundle.js",
time: true,
instances: 1,
autorestart: true,
max_restarts: 50,
watch: false,
},
],
};
5 changes: 4 additions & 1 deletion src/listeners/commands/helpCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { logCommandUsed } from "../../utils/logging";
import { postEphemeralMessage } from "../../utils/slack";
import { SlackLogger } from "../../classes/SlackLogger";

const message = `For more information, check out <https://github.com/waterloo-rocketry/minerva-rewrite/blob/main/README.md|minerva's README>.`;
const message = `For guides on how to use minerva's functionality, check out the feature reference guides in the Google Drive (<https://drive.google.com/drive/u/1/folders/1h7FZKuF3Zvv8EygjB8pSTk2aGuHHpBtj|link>)
* <https://docs.google.com/document/d/1KbeJtU06Uosjpd3XlvEGtElOx5lAZz9vDe8yzHyFhvU/edit#heading=h.g3pdvke98aqf|Meeting Reminders>
* <https://docs.google.com/document/d/1otYHtmFHzkN8g7089EGQpxi9-7C_iKFhDt2L2tuwxHs/edit#heading=h.8w6auka00s3p|Message Notifications>
`;

/**
* Handles the /help command
Expand Down

0 comments on commit 8c384ad

Please sign in to comment.