fix(tools): manage PM2 globally

This commit is contained in:
Oliver Eyton-Williams
2023-03-10 15:03:58 +01:00
committed by Mrugesh Mohapatra
parent 5482650dd0
commit 7fd74c8f5c
6 changed files with 71 additions and 644 deletions

View File

@@ -68,6 +68,10 @@ jobs:
- name: Move serve.json to Public Folder
run: cp client-config/serve.json client/public/serve.json
# start-ci uses pm2, so it needs to be installed globally
- name: Install pm2
run: npm i -g pm2
# In our cypress config, we default to the cypress/e2e/default directory.
# We need to change this to cypress/e2e/ for the specific tests we are running
# in this workflow.

View File

@@ -135,6 +135,10 @@ jobs:
- name: Seed Database
run: pnpm run seed
# start-ci uses pm2, so it needs to be installed globally
- name: Install pm2
run: npm i -g pm2
- name: Cypress run
uses: cypress-io/github-action@v4
with:

View File

@@ -5,13 +5,19 @@ const dotenv = require('dotenv');
const filePath = path.resolve(__dirname, '..', '.env');
const env = dotenv.parse(fs.readFileSync(filePath));
// without this, loopback cannot find strong-error-handler. Node can, so we know
// there's no _real_ issue, but loopback is not able to find it.
const loopbackModuleResolutionHack = path.resolve(
__dirname,
'../node_modules/.pnpm/node_modules'
);
module.exports = {
apps: [
{
script: `./lib/production-start.js`,
cwd: __dirname,
env,
env: { ...env, NODE_PATH: loopbackModuleResolutionHack },
max_memory_restart: '600M',
instances: 'max',
exec_mode: 'cluster',

View File

@@ -458,7 +458,13 @@ Provisioning VMs with the Code
npm install -g pnpm
```
3. Clone freeCodeCamp, set up env, and keys.
3. Install pm2 globally.
```console
npm install -g pm2
```
4. Clone freeCodeCamp, set up env, and keys.
```console
git clone https://github.com/freeCodeCamp/freeCodeCamp.git
@@ -466,28 +472,28 @@ cd freeCodeCamp
git checkout prod-current # or any other branch to be deployed
```
4. Create the `.env` from the secure credentials storage.
5. Create the `.env` from the secure credentials storage.
5. Install dependencies
6. Install dependencies
```console
pnpm install
```
6. Setup pm2 `logrotate` and startup on boot
7. Setup pm2 `logrotate` and startup on boot
```console
pnpm pm2 install pm2-logrotate
pnpm pm2 startup
pm2 install pm2-logrotate
pm2 startup
```
7. Build the server
8. Build the server
```console
pnpm prebuild && pnpm build:curriculum && pnpm build:server
```
8. Start Instances
9. Start Instances
```console
pnpm start:server
@@ -496,11 +502,11 @@ pnpm start:server
### Logging and Monitoring
```console
pnpm pm2 logs
pm2 logs
```
```console
pnpm pm2 monit
pm2 monit
```
### Updating Instances (Maintenance)
@@ -517,7 +523,7 @@ dependencies or adding environment variables.
1. Stop all instances
```console
pnpm pm2 stop all
pm2 stop all
```
2. Install dependencies
@@ -535,13 +541,13 @@ pnpm prebuild && pnpm build:curriculum && pnpm build:server
4. Start Instances
```console
pnpm start:server && pnpm pm2 logs
pnpm start:server && pm2 logs
```
#### 2. Rolling updates - Used for logical changes to code.
```console
pnpm reload:server && pnpm pm2 logs
pnpm reload:server && pm2 logs
```
> [!NOTE] We are handling rolling updates to code and logic via pipelines. You
@@ -554,7 +560,7 @@ pnpm reload:server && pnpm pm2 logs
2. Update pm2 to use the new version
```console
pnpm pm2 update
pm2 update
```
## Work on Client Instances

View File

@@ -99,8 +99,7 @@
},
"dependencies": {
"dotenv": "16.3.1",
"invariant": "2.2.4",
"pm2": "^5.2.2"
"invariant": "2.2.4"
},
"devDependencies": {
"@babel/plugin-proposal-function-bind": "7.22.5",

662
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff