Skip to content

Commit

Permalink
RN-961 pm2 local dev (#5264)
Browse files Browse the repository at this point in the history
* Add pm2

* Add pm2 for local dev

* Refactor start-fullstack commands to use pm2

* Minor: rename fn for clarity

The fn is used for frontends as well, doesnt make sense having server in the name

* Use start-stack instead of start-fullstack

* Add start-stack at root level for ergonomics

Running `yarn start-stack x` is nicer than `yarn package:start-stack x`
  • Loading branch information
IgorNadj authored Dec 15, 2023
1 parent b0df66a commit d8d5a47
Show file tree
Hide file tree
Showing 15 changed files with 971 additions and 74 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"build:non-internal-dependencies": "./scripts/bash/buildNonInternalDependencies.sh",
"build:admin-panel": "yarn workspace @tupaia/admin-panel build",
"build:web-frontend": "yarn workspace @tupaia/web-frontend build",
"start-dev": "echo Starting default stack tupaia-web && scripts/bash/pm2startInline.sh tupaia-web",
"start-stack": "scripts/bash/pm2startInline.sh",
"download-env-vars": "./scripts/bash/downloadEnvironmentVariables.sh",
"dump-database": "yarn workspace @tupaia/database dump-database --target ../../",
"migrate": "yarn workspace @tupaia/database migrate",
Expand All @@ -42,7 +44,8 @@
"package:test": "cd $INIT_CWD && jest --maxWorkers=50%",
"package:test:withdb": "cd $INIT_CWD && yarn workspace @tupaia/database check-test-database-exists && DB_NAME=tupaia_test jest --runInBand",
"package:start:backend-start-dev": "cd $INIT_CWD && LOG_LEVEL=debug ../../scripts/bash/backendStartDev.sh",
"package:start:vite": "cd $INIT_CWD && vite --config \"../../vite.config.js\""
"package:start:vite": "cd $INIT_CWD && vite --config \"../../vite.config.js\"",
"package:start-stack": "scripts/bash/pm2startInline.sh"
},
"resolutions": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
Expand Down Expand Up @@ -79,6 +82,7 @@
"jest-when": "^3.6.0",
"nodemon": "^2.0.4",
"npm-package-json-lint": "5.1.0",
"pm2": "^5.3.0",
"ts-jest": "^27.1.3",
"ts-node": "^10.7.0",
"typescript": "^5.2.2",
Expand Down
10 changes: 2 additions & 8 deletions packages/admin-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
"lint:fix": "yarn lint --fix",
"start": "yarn package:start:vite --port 3000",
"start-dev": "yarn start",
"start-fullstack": "npm-run-all -c -l -p start-servers start-dev",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-report-server": "yarn workspace @tupaia/report-server start-dev",
"start-admin-panel-server": "yarn workspace @tupaia/admin-panel-server start-dev",
"start-data-table-server": "yarn workspace @tupaia/data-table-server start-dev",
"test": "echo No tests",
"start-servers": "npm-run-all -c -l -p start-central-server start-entity-server start-report-server start-admin-panel-server start-data-table-server"
"start-stack": "yarn package:start-stack admin-panel",
"test": "echo No tests"
},
"browserslist": [
"defaults"
Expand Down
7 changes: 1 addition & 6 deletions packages/datatrak-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@
"lint:fix": "yarn lint --fix",
"preview": "vite preview",
"start-dev": "npm run --prefix ../../ package:start:vite",
"start-fullstack": "npm-run-all -c -l -p start-servers start-dev",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-datatrak-web-server": "yarn workspace @tupaia/datatrak-web-server start-dev",
"start-web-config-server": "yarn workspace @tupaia/web-config-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-servers": "npm-run-all -c -l -p start-central-server start-web-config-server start-datatrak-web-server start-entity-server",
"start-stack": "yarn package:start-stack datatrak",
"test": "yarn test:jest",
"test:jest": "yarn package:test --env=jsdom"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/devops/configs/pm2/admin-panel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const { startDevConfigs } = require("./base.config");

module.exports = {
apps: startDevConfigs([
"central-server",
"entity-server",
"report-server",
"data-table-server",
"admin-panel-server",
"admin-panel",
])
};
31 changes: 31 additions & 0 deletions packages/devops/configs/pm2/base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const baseConfig = {
"error_file" : null,
"out_file" : null,
"wait_ready" : false, // don't wait for one process to finish starting before starting next
}

/**
* Convenience fn
*/
const startDevConfig = (packageName) => ({
"name" : packageName,
"script" : `yarn workspace @tupaia/${packageName} start-dev`,
...baseConfig,
});

/**
* Convenience fn
*/
const startDevConfigs = (packageNames) =>
packageNames.map(packageName => startDevConfig(packageName));

module.exports = {
baseConfig: baseConfig,
startDevConfig,
startDevConfigs,
}
16 changes: 16 additions & 0 deletions packages/devops/configs/pm2/datatrak.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const { startDevConfigs } = require("./base.config");

module.exports = {
apps: startDevConfigs([
"central-server",
"entity-server",
"report-server",
"datatrak-web-server",
"datatrak-web",
])
};
16 changes: 16 additions & 0 deletions packages/devops/configs/pm2/lesmis.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const { startDevConfigs } = require("./base.config");

module.exports = {
apps: startDevConfigs([
"central-server",
"entity-server",
"report-server",
"lesmis-server",
"lesmis",
])
};
17 changes: 17 additions & 0 deletions packages/devops/configs/pm2/psss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const { startDevConfigs } = require("./base.config");

module.exports = {
apps: startDevConfigs([
"central-server",
"entity-server",
"report-server",
"data-table-server",
"psss-server",
"psss",
])
};
18 changes: 18 additions & 0 deletions packages/devops/configs/pm2/tupaia-web.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

const { startDevConfigs } = require("./base.config");

module.exports = {
apps: startDevConfigs([
"central-server",
"entity-server",
"report-server",
"web-config-server",
"data-table-server",
"tupaia-web-server",
"tupaia-web",
])
};
10 changes: 2 additions & 8 deletions packages/lesmis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
"preview": "vite preview",
"lint": "yarn package:lint",
"lint:fix": "yarn lint --fix",
"start-fullstack": "npm-run-all -c -l -p start-servers start-dev",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-report-server": "yarn workspace @tupaia/report-server start-dev",
"start-web-config-server": "yarn workspace @tupaia/web-config-server start-dev",
"start-lesmis-server": "yarn workspace @tupaia/lesmis-server start-dev",
"start-stack": "yarn package:start-stack lesmis",
"test": "yarn package:test",
"start": "yarn package:start:vite --port 3003",
"start-dev": "yarn start",
"start-servers": "npm-run-all -c -l -p start-central-server start-entity-server start-report-server start-web-config-server start-lesmis-server"
"start-dev": "yarn start"
},
"browserslist": [
"defaults"
Expand Down
7 changes: 1 addition & 6 deletions packages/psss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
"build": "npm run --prefix ../../ package:build:vite",
"lint": "yarn package:lint",
"lint:fix": "yarn lint --fix",
"start-fullstack": "npm-run-all -c -l -p start-servers start-dev",
"start-psss-server": "yarn workspace @tupaia/psss-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-report-server": "yarn workspace @tupaia/report-server start-dev",
"start-stack": "yarn package:start-stack psss",
"test": "yarn test:jest",
"test:jest": "yarn package:test --env=jsdom",
"start-servers": "npm-run-all -c -l -p start-psss-server start-entity-server start-central-server start-report-server",
"start-dev": "yarn package:start:vite"
},
"browserslist": [
Expand Down
9 changes: 1 addition & 8 deletions packages/tupaia-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
"lint:fix": "yarn lint --fix",
"preview": "vite preview",
"start-dev": "npm run --prefix ../../ package:start:vite --port=8088",
"start-fullstack": "npm-run-all -c -l -p start-servers start-dev",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-report-server": "yarn workspace @tupaia/report-server start-dev",
"start-web-config-server": "yarn workspace @tupaia/web-config-server start-dev",
"start-tupaia-web-server": "yarn workspace @tupaia/tupaia-web-server start-dev",
"start-servers": "npm-run-all -c -l -p start-central-server start-entity-server start-report-server start-tupaia-web-server start-web-config-server start-data-table-server",
"start-data-table-server": "yarn workspace @tupaia/data-table-server start-dev",
"start-stack": "yarn package:start-stack tupaia-web",
"storybook": "storybook dev -p 6006",
"test": "yarn package:test --env=jsdom",
"build-storybook": "storybook build"
Expand Down
7 changes: 0 additions & 7 deletions packages/web-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
"start": "PORT=8088 SKIP_PREFLIGHT_CHECK=true react-scripts start",
"start-dev": "yarn start",
"start-mobile": "REACT_APP_APP_TYPE=mobile PORT=8089 PORT=8088 SKIP_PREFLIGHT_CHECK=true react-scripts start",
"start-fullstack": "npm-run-all -c -l -p start-servers start-frontend",
"start-central-server": "yarn workspace @tupaia/central-server start-dev",
"start-entity-server": "yarn workspace @tupaia/entity-server start-dev",
"start-report-server": "yarn workspace @tupaia/report-server start-dev",
"start-web-config-server": "yarn workspace @tupaia/web-config-server start-dev",
"start-servers": "npm-run-all -c -l -p start-central-server start-entity-server start-report-server start-web-config-server start-data-table-server",
"start-data-table-server": "yarn workspace @tupaia/data-table-server start-dev",
"storybook": "start-storybook -s public -p 6007",
"test": "node scripts/test.js --env=jsdom",
"start-ui-components": "yarn workspace @tupaia/ui-components build -w",
Expand Down
23 changes: 23 additions & 0 deletions scripts/bash/pm2startInline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e

cd "$(dirname "${BASH_SOURCE[0]}")"


if [ -z "$1" ]; then
echo "Usage: yarn start-dev <stack>"
echo ""
echo "All stacks:"
ls -1 ../../packages/devops/configs/pm2/ | sed 's|.config.js||g' | grep -v 'base' | awk '$0=" "$0'
echo ""
echo "Tips:"
echo " - normal pm2 commands work e.g. yarn pm2 status"
echo " - start multiple stacks by calling this cmd multiple times"
exit 1
fi

yarn pm2 start "../../packages/devops/configs/pm2/$1.config.js"

# When user quits logs stop everything
trap "echo Stopping... && yarn pm2 delete all" EXIT

yarn pm2 logs --lines 0
Loading

0 comments on commit d8d5a47

Please sign in to comment.