From 05d726529254c1deb7c08c5ea0c941000ebce67f Mon Sep 17 00:00:00 2001 From: Reino Muhl <10620585+StaberindeZA@users.noreply.github.com> Date: Thu, 30 May 2024 12:40:52 -0400 Subject: [PATCH] feat(many): add partial stack startup scripts Because: - During development it could be useful to start only parts of the stack needed for development on specific domains. This commit: - Provides additional stack startup options to only start specific parts of the stack, by using nx projects and tags. Closes #FXA-9771 --- _scripts/pm2-all.sh | 12 ++- apps/payments/next/project.json | 2 +- package-scripts.js | 111 +++++++++++++++++++--- packages/123done/package.json | 3 +- packages/fxa-admin-panel/package.json | 3 +- packages/fxa-admin-server/package.json | 3 +- packages/fxa-auth-server/package.json | 3 +- packages/fxa-content-server/package.json | 4 +- packages/fxa-customs-server/package.json | 3 +- packages/fxa-event-broker/package.json | 3 +- packages/fxa-graphql-api/package.json | 6 ++ packages/fxa-payments-server/package.json | 3 +- packages/fxa-profile-server/package.json | 3 +- packages/fxa-react/package.json | 3 +- packages/fxa-settings/package.json | 3 +- packages/fxa-shared/package.json | 3 +- yarn.lock | 1 - 17 files changed, 142 insertions(+), 27 deletions(-) diff --git a/_scripts/pm2-all.sh b/_scripts/pm2-all.sh index cc1e6fc46e..b77a8d3fd8 100755 --- a/_scripts/pm2-all.sh +++ b/_scripts/pm2-all.sh @@ -4,6 +4,7 @@ start=`date +%s` DIR=$(dirname "$0") COMMAND=$1 +PROJECTS=$2 cd "$DIR/.." if ! node -p 's = require("semver");v = require("./package.json").engines.node; process.exitCode = s.satisfies(process.version, v) ? 0 : 1; if(process.exitCode) {"\nPlease use node: " + v + "\n"}'; @@ -12,7 +13,16 @@ then fi mkdir -p artifacts -npx nx run-many -t start --all --exclude=fxa-dev-launcher --verbose; + +if [ -z "$PROJECTS" ] +then + # No tags provided, start the entire stack + npx nx run-many -t $COMMAND --all --exclude=fxa-dev-launcher --verbose; +else + # Start only provided projects and dependencies + # Note dependencies are automatically determined by Nx + npx nx run-many -t $COMMAND --projects=$PROJECTS --exclude=fxa-dev-launcher --verbose; +fi end=`date +%s` runtime=$((end-start)) diff --git a/apps/payments/next/project.json b/apps/payments/next/project.json index 92c1004207..ae1027e7e3 100644 --- a/apps/payments/next/project.json +++ b/apps/payments/next/project.json @@ -118,5 +118,5 @@ } } }, - "tags": ["app", "payments"] + "tags": ["app", "payments", "type:sp3"] } diff --git a/package-scripts.js b/package-scripts.js index 5192053a7d..31c1201196 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -1,25 +1,114 @@ +/** + * These are Nx tags used to identify which services to start up + * when executing the various partial startup scripts. + */ +const mzaProjects = 'tag:type:core,tag:type:demo'; +const sp2Projects = 'tag:type:core,tag:type:demo,tag:type:sp2'; +const sp3Projects = 'tag:type:core,tag:type:demo,tag:type:sp3'; + module.exports = { scripts: { default: 'nps help', start: { - default: `_dev/pm2/start.sh && _scripts/pm2-all.sh start && pm2 restart sync && echo "Use 'yarn stop' to stop all the servers"`, - infrastructure: `_dev/pm2/start.sh`, - services: `_scripts/pm2-all.sh start`, + default: { + script: `_dev/pm2/start.sh && _scripts/pm2-all.sh start && pm2 restart sync && echo "Use 'yarn stop' to stop all the servers"`, + description: 'Start the entire stack, i.e. all infrastructure and services.' + }, + infrastructure: { + script: `_dev/pm2/start.sh`, + description: 'Start all infrastructure only.', + }, + services: { + script: `_scripts/pm2-all.sh start`, + description: 'Start all Services only.' + }, firefox: './packages/fxa-dev-launcher/bin/fxa-dev-launcher.mjs &', + mza: { + script: `_dev/pm2/start.sh && _scripts/pm2-all.sh start ${mzaProjects} && pm2 restart sync && echo "Use 'yarn stop' to stop all the servers"`, + description: 'Start infrastructure and only required Mozilla Accounts services', + }, + sp2: { + script: `_dev/pm2/start.sh && _scripts/pm2-all.sh start ${sp2Projects} && pm2 restart sync && echo "Use 'yarn stop' to stop all the servers"`, + description: 'Start infrastructure and only required SubPlat 2.0 services.' + }, + sp3: { + script: `_dev/pm2/start.sh && _scripts/pm2-all.sh start ${sp3Projects} && pm2 restart sync && echo "Use 'yarn stop' to stop all the servers"`, + description: 'Start infrastructure and only required SubPlat 3.0 services.' + }, }, stop: { - default: 'pm2 kill', - infrastructure: `pm2 stop _dev/pm2/infrastructure.config.js`, - services: `_scripts/pm2-all.sh stop`, + default: { + script: 'pm2 kill', + description: 'Stop all infrastructure and services.', + }, + infrastructure: { + script: `pm2 stop _dev/pm2/infrastructure.config.js`, + description: 'Stop all infrastructure, only.', + }, + services: { + script: `_scripts/pm2-all.sh stop`, + description: 'Stop all services, only.', + }, + mza: { + script: `_scripts/pm2-all.sh stop ${mzaProjects}`, + description: 'Stop required Mozilla Accounts services.', + }, + sp2: { + script: `_scripts/pm2-all.sh stop ${sp2Projects}`, + description: 'Stop required SubPlat 2.0 services.', + }, + sp3: { + script: `_scripts/pm2-all.sh stop ${sp3Projects}`, + description: 'Stop required SubPlat 3.0 services.', + }, }, restart: { - default: 'pm2 restart all', - infrastructure: `pm2 restart _dev/pm2/infrastructure.config.js`, - services: `_scripts/pm2-all.sh restart`, + default: { + script: 'pm2 restart all', + description: 'Restart all infrastructure and services.', + }, + infrastructure: { + script: `pm2 restart _dev/pm2/infrastructure.config.js`, + description: 'Restart all infrastructure, only.', + }, + services: { + script: `_scripts/pm2-all.sh restart`, + description: 'Restart all services, only.', + }, + mza: { + script: `_scripts/pm2-all.sh restart ${mzaProjects}`, + description: 'Restart required Mozilla Accounts services.', + }, + sp2: { + script: `_scripts/pm2-all.sh restart ${sp2Projects}`, + description: 'Restart required SubPlat 2.0 services.', + }, + sp3: { + script: `_scripts/pm2-all.sh restart ${sp3Projects}`, + description: 'Restart required SubPlat 3.0 services.', + }, }, delete: { - default: 'pm2 kill', - services: '_scripts/pm2-all.sh delete', + default: { + script: 'pm2 kill', + description: 'Delete all infrastructure and services.', + }, + services: { + script: '_scripts/pm2-all.sh delete', + description: 'Delete all services, only.', + }, + mza: { + script: `_scripts/pm2-all.sh delete ${mzaProjects}`, + description: 'Delete required Mozilla Accounts services.', + }, + sp2: { + script: `_scripts/pm2-all.sh delete ${sp2Projects}`, + description: 'Delete required SubPlat 2.0 services.', + }, + sp3: { + script: `_scripts/pm2-all.sh delete ${sp3Projects}`, + description: 'Delete required SubPlat 3.0 services.', + }, }, }, }; diff --git a/packages/123done/package.json b/packages/123done/package.json index 7bfd6d2292..857b76e261 100644 --- a/packages/123done/package.json +++ b/packages/123done/package.json @@ -46,7 +46,8 @@ }, "nx": { "tags": [ - "scope:demo" + "scope:demo", + "type:demo" ] } } diff --git a/packages/fxa-admin-panel/package.json b/packages/fxa-admin-panel/package.json index be98488754..5b1fcff8df 100644 --- a/packages/fxa-admin-panel/package.json +++ b/packages/fxa-admin-panel/package.json @@ -89,7 +89,8 @@ }, "nx": { "tags": [ - "scope:frontend" + "scope:frontend", + "type:admin" ] } } diff --git a/packages/fxa-admin-server/package.json b/packages/fxa-admin-server/package.json index d448a2ccb9..6e6ea297d2 100644 --- a/packages/fxa-admin-server/package.json +++ b/packages/fxa-admin-server/package.json @@ -78,7 +78,8 @@ }, "nx": { "tags": [ - "scope:server" + "scope:server", + "type:admin" ] } } diff --git a/packages/fxa-auth-server/package.json b/packages/fxa-auth-server/package.json index 1eef11c18e..edcea222cf 100644 --- a/packages/fxa-auth-server/package.json +++ b/packages/fxa-auth-server/package.json @@ -222,7 +222,8 @@ }, "nx": { "tags": [ - "scope:server:auth" + "scope:server:auth", + "type:core" ] } } diff --git a/packages/fxa-content-server/package.json b/packages/fxa-content-server/package.json index 9735c92243..281da6b2f7 100644 --- a/packages/fxa-content-server/package.json +++ b/packages/fxa-content-server/package.json @@ -75,7 +75,6 @@ "fxa-geodb": "workspace:*", "fxa-mustache-loader": "0.0.2", "fxa-pairing-channel": "1.0.2", - "fxa-payments-server": "workspace:*", "fxa-profile-server": "workspace:*", "fxa-react": "workspace:*", "fxa-settings": "workspace:*", @@ -187,7 +186,8 @@ "readmeFilename": "README.md", "nx": { "tags": [ - "scope:frontend" + "scope:frontend", + "type:core" ] } } diff --git a/packages/fxa-customs-server/package.json b/packages/fxa-customs-server/package.json index b8d7058321..5a978c61fc 100644 --- a/packages/fxa-customs-server/package.json +++ b/packages/fxa-customs-server/package.json @@ -68,7 +68,8 @@ }, "nx": { "tags": [ - "scope:server" + "scope:server", + "type:core" ] } } diff --git a/packages/fxa-event-broker/package.json b/packages/fxa-event-broker/package.json index 642924a774..df218dac6f 100644 --- a/packages/fxa-event-broker/package.json +++ b/packages/fxa-event-broker/package.json @@ -107,7 +107,8 @@ }, "nx": { "tags": [ - "scope:broker" + "scope:broker", + "type:broker" ] } } diff --git a/packages/fxa-graphql-api/package.json b/packages/fxa-graphql-api/package.json index 1845ce32a1..c8a258b471 100644 --- a/packages/fxa-graphql-api/package.json +++ b/packages/fxa-graphql-api/package.json @@ -89,5 +89,11 @@ "prettier": "^2.3.1", "supertest": "^7.0.0", "typescript": "^5.4.2" + }, + "nx": { + "tags": [ + "scope:gql", + "type:core" + ] } } diff --git a/packages/fxa-payments-server/package.json b/packages/fxa-payments-server/package.json index 2f8e71a2a3..2fb67f983f 100644 --- a/packages/fxa-payments-server/package.json +++ b/packages/fxa-payments-server/package.json @@ -197,7 +197,8 @@ }, "nx": { "tags": [ - "scope:frontend" + "scope:frontend", + "type:sp2" ] } } diff --git a/packages/fxa-profile-server/package.json b/packages/fxa-profile-server/package.json index 5631a86de9..ee82df1af8 100644 --- a/packages/fxa-profile-server/package.json +++ b/packages/fxa-profile-server/package.json @@ -74,7 +74,8 @@ }, "nx": { "tags": [ - "scope:server" + "scope:server", + "type:core" ] } } diff --git a/packages/fxa-react/package.json b/packages/fxa-react/package.json index abf1437499..431c671519 100644 --- a/packages/fxa-react/package.json +++ b/packages/fxa-react/package.json @@ -112,7 +112,8 @@ }, "nx": { "tags": [ - "scope:shared:lib" + "scope:shared:lib", + "type:core" ] } } diff --git a/packages/fxa-settings/package.json b/packages/fxa-settings/package.json index ec5cccc784..85aa2b309e 100644 --- a/packages/fxa-settings/package.json +++ b/packages/fxa-settings/package.json @@ -256,7 +256,8 @@ }, "nx": { "tags": [ - "scope:frontend" + "scope:frontend", + "type:core" ] }, "babel": { diff --git a/packages/fxa-shared/package.json b/packages/fxa-shared/package.json index d5ea0e38b9..ba76a31114 100644 --- a/packages/fxa-shared/package.json +++ b/packages/fxa-shared/package.json @@ -343,7 +343,8 @@ }, "nx": { "tags": [ - "scope:shared:lib" + "scope:shared:lib", + "type:core" ] } } diff --git a/yarn.lock b/yarn.lock index 7040dfb596..84b779d9fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -38013,7 +38013,6 @@ fsevents@~2.1.1: fxa-geodb: "workspace:*" fxa-mustache-loader: 0.0.2 fxa-pairing-channel: 1.0.2 - fxa-payments-server: "workspace:*" fxa-profile-server: "workspace:*" fxa-react: "workspace:*" fxa-settings: "workspace:*"