From 1a97115d4b337fc89fe12879fdaa06ce5edc2b9b Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:50:06 -0500 Subject: [PATCH 01/10] update docker-compose-example - Add reactmap specific db example to docker-compose, as well as a bunch of comments to help guide - Try an alternative import for package.json version to see if it helps it be more consistent --- .github/workflows/config.yml | 2 +- .github/workflows/docker.yml | 2 +- docker-compose.example.yml | 28 ++++++++++++++++++-- esbuild.config.js | 11 ++++---- server/src/index.js | 7 ++--- server/src/services/config.js | 48 +++++++++++++++++++++++++++-------- 6 files changed, 75 insertions(+), 23 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index b3761e4ce..688d5924e 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -22,7 +22,7 @@ jobs: cache: 'yarn' - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v33 + uses: tj-actions/changed-files@v34 with: files: | server/src/configs/default.json diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2059b22dc..1b1257ef9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,7 +20,7 @@ jobs: cache: 'yarn' - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v33 + uses: tj-actions/changed-files@v34 with: files: | server/src/configs/default.json diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 0dfc7fdb9..a5751318c 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -6,27 +6,51 @@ services: command: sh -c "yarn start" restart: unless-stopped environment: + # All database values are ignored if you are using a `local.json` file! + + # Your Scanner Database SCANNER_DB_HOST: 127.0.0.1 SCANNER_DB_PORT: 3306 SCANNER_DB_USERNAME: scanner_username SCANNER_DB_PASSWORD: scanner_user_pw - SCANNER_DB_NAME: realdevicemap + SCANNER_DB_NAME: scanner_db + + # Your ReactMap Database + # optional, but recommended, if omitted it will default to your manual database + REACT_MAP_DB_HOST: 127.0.0.1 + REACT_MAP_DB_PORT: 3306 + REACT_MAP_DB_USERNAME: react_map_username + REACT_MAP_DB_PASSWORD: react_map_user_pw + REACT_MAP_DB_NAME: react_map_db + + # Your Manual Database (Optional - Nests & Portals) MANUAL_DB_HOST: 127.0.0.1 MANUAL_DB_PORT: 3306 MANUAL_DB_USERNAME: manual_username MANUAL_DB_PASSWORD: manual_user_pw MANUAL_DB_NAME: manual_db + + # Other config values - the below env vars will override anything, including `local.json` + # More config values you can add: + # https://github.com/WatWowMap/ReactMap/blob/main/server/src/configs/custom-environment-variables.json + # Config wiki page: + # https://github.com/WatWowMap/ReactMap/wiki/04.-Full-Config-Explanation + # Devs recommened that you use a `local.json` config file though instead of env variables! MAP_GENERAL_TITLE: ReactMap MAP_GENERAL_START_LAT: 0 MAP_GENERAL_START_LON: 0 - ARRAY_VALUE_EXAMPLE: "[3, 4, 5]" + # ARRAY_VALUE_EXAMPLE: "[3, 4, 5]" + volumes: + # All of these are optional - comment out whichever ones you aren't using - ./server/src/configs/areas.json:/home/node/server/src/configs/areas.json - ./server/src/configs/local.json:/home/node/server/src/configs/local.json - ./server/src/configs/geofence.json/:/home/node/server/src/configs/geofence.json - ./example.env:/home/node/.env + security_opt: - no-new-privileges:true #https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ + ports: - "9090:8080" # nginx: diff --git a/esbuild.config.js b/esbuild.config.js index b19a4bde2..9bd4a3c07 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -11,12 +11,11 @@ const esbuildMxnCopy = require('esbuild-plugin-mxn-copy') const aliasPlugin = require('esbuild-plugin-path-alias') const { eslintPlugin } = require('esbuild-plugin-eslinter') +const pkg = require('./package.json') + const env = fs.existsSync(resolve(__dirname, '.env')) ? dotenv.config() : { parsed: process.env } -const { version } = JSON.parse( - fs.readFileSync(resolve(__dirname, 'package.json')), -) const isDevelopment = Boolean(process.argv.includes('--dev')) const isRelease = Boolean(process.argv.includes('--release')) const isServing = Boolean(process.argv.includes('--serve')) @@ -112,7 +111,7 @@ ${customPaths.map((x, i) => ` ${i + 1}. src/${x.split('src/')[1]}`).join('\n')} }, }) } - console.log(`[BUILD] Building production version: ${version}`) + console.log(`[BUILD] Building production version: ${pkg.version}`) } const esbuild = { @@ -121,7 +120,7 @@ const esbuild = { bundle: true, outdir: 'dist/', publicPath: '/', - entryNames: isDevelopment ? undefined : `[name]-${version}-[hash]`, + entryNames: isDevelopment ? undefined : `[name]-${pkg.version}-[hash]`, metafile: true, minify: env.parsed.NO_MINIFIED ? false : isRelease || !isDevelopment, logLevel: isDevelopment ? 'info' : 'error', @@ -143,7 +142,7 @@ const esbuild = { SENTRY_DSN: env.parsed.SENTRY_DSN || '', SENTRY_TRACES_SAMPLE_RATE: env.parsed.SENTRY_TRACES_SAMPLE_RATE || 0.1, SENTRY_DEBUG: env.parsed.SENTRY_DEBUG || false, - VERSION: version, + VERSION: pkg.version, DEVELOPMENT: isDevelopment, CUSTOM: hasCustom, LOCALES: fs.readdirSync(resolve(__dirname, 'public/locales')), diff --git a/server/src/index.js b/server/src/index.js index 6d0d8068f..745eccc25 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -19,7 +19,7 @@ const { sessionStore } = require('./services/sessionStore') const rootRouter = require('./routes/rootRouter') const typeDefs = require('./graphql/typeDefs') const resolvers = require('./graphql/resolvers') -const { version } = require('../../package.json') +const pkg = require('../../package.json') if (!config.devOptions.skipUpdateCheck) { require('./services/checkForUpdates') @@ -41,8 +41,9 @@ const server = new ApolloServer({ Db, Event, perms, - serverV: version, - clientV: req.headers['apollographql-client-version']?.trim() || version, + serverV: pkg.version || 1, + clientV: + req.headers['apollographql-client-version']?.trim() || pkg.version || 1, } }, formatError: (e) => { diff --git a/server/src/services/config.js b/server/src/services/config.js index 5478bfe46..fb3b55f2e 100644 --- a/server/src/services/config.js +++ b/server/src/services/config.js @@ -40,6 +40,11 @@ if (!fs.existsSync(resolve(`${__dirname}/../configs/local.json`))) { SCANNER_DB_NAME, SCANNER_DB_USERNAME, SCANNER_DB_PASSWORD, + REACT_MAP_DB_HOST, + REACT_MAP_DB_PORT, + REACT_MAP_DB_USERNAME, + REACT_MAP_DB_PASSWORD, + REACT_MAP_DB_NAME, MANUAL_DB_HOST, MANUAL_DB_PORT, MANUAL_DB_NAME, @@ -49,13 +54,26 @@ if (!fs.existsSync(resolve(`${__dirname}/../configs/local.json`))) { MAP_GENERAL_START_LON, } = process.env - if ( + const hasScannerDb = SCANNER_DB_HOST && SCANNER_DB_PORT && SCANNER_DB_NAME && SCANNER_DB_USERNAME && SCANNER_DB_PASSWORD - ) { + const hasReactMapDb = + REACT_MAP_DB_HOST && + REACT_MAP_DB_PORT && + REACT_MAP_DB_USERNAME && + REACT_MAP_DB_PASSWORD && + REACT_MAP_DB_NAME + const hasManualDb = + MANUAL_DB_HOST && + MANUAL_DB_PORT && + MANUAL_DB_NAME && + MANUAL_DB_USERNAME && + MANUAL_DB_PASSWORD + + if (hasScannerDb) { config.database.schemas.push({ host: SCANNER_DB_HOST, port: +SCANNER_DB_PORT, @@ -77,20 +95,30 @@ if (!fs.existsSync(resolve(`${__dirname}/../configs/local.json`))) { 'Missing scanner database config! \nCheck to make sure you have SCANNER_DB_HOST,SCANNER_DB_PORT, SCANNER_DB_NAME, SCANNER_DB_USERNAME, and SCANNER_DB_PASSWORD', ) } - if ( - MANUAL_DB_HOST && - MANUAL_DB_PORT && - MANUAL_DB_NAME && - MANUAL_DB_USERNAME && - MANUAL_DB_PASSWORD - ) { + if (hasReactMapDb) { + config.database.schemas.push({ + host: REACT_MAP_DB_HOST, + port: +REACT_MAP_DB_PORT, + database: REACT_MAP_DB_USERNAME, + username: REACT_MAP_DB_PASSWORD, + password: REACT_MAP_DB_NAME, + useFor: ['session', 'user'], + }) + } else { + console.log( + 'Missing ReactMap specific table, attempting to use the manual database instead.', + ) + } + if (hasManualDb) { config.database.schemas.push({ host: MANUAL_DB_HOST, port: +MANUAL_DB_PORT, database: MANUAL_DB_NAME, username: MANUAL_DB_USERNAME, password: MANUAL_DB_PASSWORD, - useFor: ['session', 'user', 'nest', 'portal'], + useFor: hasReactMapDb + ? ['nest', 'portal'] + : ['session', 'user', 'nest', 'portal'], }) } else { console.error( From bb4bba1aec6bb129a860037b3c49c152c935d3ef Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:54:10 -0500 Subject: [PATCH 02/10] wf changes --- .github/workflows/config.yml | 2 +- .github/workflows/docker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 688d5924e..7f2491d01 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -25,7 +25,7 @@ jobs: uses: tj-actions/changed-files@v34 with: files: | - server/src/configs/default.json + ./server/src/configs/default.json - name: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1257ef9..356bac924 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,7 +23,7 @@ jobs: uses: tj-actions/changed-files@v34 with: files: | - server/src/configs/default.json + ./server/src/configs/default.json - name: Generate latest env vars if: steps.changed-files.outputs.any_changed == 'true' run: | From 955043135d7b994468e5516d583cb589fb7783a6 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:59:03 -0500 Subject: [PATCH 03/10] attempt #3... --- .github/workflows/config.yml | 2 +- .github/workflows/docker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 7f2491d01..99a02a252 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -25,7 +25,7 @@ jobs: uses: tj-actions/changed-files@v34 with: files: | - ./server/src/configs/default.json + server/src/configs/*.json - name: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 356bac924..d5912639f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,7 +23,7 @@ jobs: uses: tj-actions/changed-files@v34 with: files: | - ./server/src/configs/default.json + server/src/configs/*.json - name: Generate latest env vars if: steps.changed-files.outputs.any_changed == 'true' run: | From 70fe727df9f607cfc13e87b880536cd74d8e3c46 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:01:43 -0500 Subject: [PATCH 04/10] Update config.yml --- .github/workflows/config.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 99a02a252..c0e7cd627 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -15,18 +15,19 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 2 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v17 + with: + files: | + server/src/configs/default.json - name: Setup Node.js environment + if: steps.changed-files.outputs.any_changed == 'true' uses: actions/setup-node@v3 with: node-version: 16 cache: 'yarn' - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: | - server/src/configs/*.json - - name: Run script + - name: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | yarn config-check From eb13b91cf08d8d486b84e93993f8526de6198a6c Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:14:25 -0500 Subject: [PATCH 05/10] formatting --- .github/workflows/config.yml | 6 +++--- docker-compose.example.yml | 21 +++++++++++---------- package.json | 8 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index c0e7cd627..c2950984a 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v17 + uses: tj-actions/changed-files@v19 with: files: | server/src/configs/default.json @@ -26,8 +26,8 @@ jobs: uses: actions/setup-node@v3 with: node-version: 16 - cache: 'yarn' - - name: Run script + cache: 'yarn' + - name: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | yarn config-check diff --git a/docker-compose.example.yml b/docker-compose.example.yml index a5751318c..5bddb39ce 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -15,7 +15,7 @@ services: SCANNER_DB_PASSWORD: scanner_user_pw SCANNER_DB_NAME: scanner_db - # Your ReactMap Database + # Your ReactMap Database # optional, but recommended, if omitted it will default to your manual database REACT_MAP_DB_HOST: 127.0.0.1 REACT_MAP_DB_PORT: 3306 @@ -29,11 +29,11 @@ services: MANUAL_DB_USERNAME: manual_username MANUAL_DB_PASSWORD: manual_user_pw MANUAL_DB_NAME: manual_db - + # Other config values - the below env vars will override anything, including `local.json` - # More config values you can add: - # https://github.com/WatWowMap/ReactMap/blob/main/server/src/configs/custom-environment-variables.json - # Config wiki page: + # More config values you can add: + # https://github.com/WatWowMap/ReactMap/blob/main/server/src/configs/custom-environment-variables.json + # Config wiki page: # https://github.com/WatWowMap/ReactMap/wiki/04.-Full-Config-Explanation # Devs recommened that you use a `local.json` config file though instead of env variables! MAP_GENERAL_TITLE: ReactMap @@ -42,17 +42,18 @@ services: # ARRAY_VALUE_EXAMPLE: "[3, 4, 5]" volumes: - # All of these are optional - comment out whichever ones you aren't using + # All of these are optional - comment out whichever ones you aren't using - ./server/src/configs/areas.json:/home/node/server/src/configs/areas.json - ./server/src/configs/local.json:/home/node/server/src/configs/local.json - ./server/src/configs/geofence.json/:/home/node/server/src/configs/geofence.json - ./example.env:/home/node/.env - + security_opt: - - no-new-privileges:true #https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ - + # https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ + - no-new-privileges:true + ports: - - "9090:8080" + - '9090:8080' # nginx: # image: nginx # container_name: nginx diff --git a/package.json b/package.json index b91b72925..295dd1620 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "migrate:latest": "knex --knexfile server/knexfile.cjs migrate:latest", "migrate:rollback": "knex --knexfile server/knexfile.cjs migrate:rollback", "release": "node server/scripts/newRelease.js", - "prettier:check": "prettier --check \"**/*.{css,html,js,jsx}\"", - "prettier:fix": "prettier --write \"**/*.{css,html,js,jsx}\"", - "eslint:check": "eslint \"**/*.{js,jsx}\"", - "eslint:fix": "eslint \"**/*.{js,jsx}\" --fix" + "prettier:check": "prettier --check \"**/*.{css,html,js,jsx,yml}\"", + "prettier:fix": "prettier --write \"**/*.{css,html,js,jsx,yml}\"", + "eslint:check": "eslint \"**/*.{js,jsx,yml}\"", + "eslint:fix": "eslint \"**/*.{js,jsx,yml}\" --fix" }, "engines": { "node": ">=16", From a431d1aea49e1b00220ad1e070fd689edb987511 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:16:05 -0500 Subject: [PATCH 06/10] Update config.yml --- .github/workflows/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index c2950984a..c2a49adbe 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: 16 - cache: 'yarn' + cache: 'yarn' - name: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | From 847b2faabaed1776a0b45c98861a1d3b0490709c Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:18:05 -0500 Subject: [PATCH 07/10] f --- .github/workflows/config.yml | 2 +- docker-compose.example.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index c2a49adbe..0d22cb063 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v19 + uses: tj-actions/changed-files@v27 with: files: | server/src/configs/default.json diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 5bddb39ce..6094ca4c3 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -50,7 +50,7 @@ services: security_opt: # https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ - - no-new-privileges:true + - no-new-privileges:true ports: - '9090:8080' From 8d3a2959f97f5fbfef7d523c4f40531d60eedf41 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:20:27 -0500 Subject: [PATCH 08/10] ff --- .github/workflows/config.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 0d22cb063..d8e61bd4b 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v27 + uses: tj-actions/changed-files@v32 with: files: | server/src/configs/default.json diff --git a/package.json b/package.json index 295dd1620..c97682128 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "release": "node server/scripts/newRelease.js", "prettier:check": "prettier --check \"**/*.{css,html,js,jsx,yml}\"", "prettier:fix": "prettier --write \"**/*.{css,html,js,jsx,yml}\"", - "eslint:check": "eslint \"**/*.{js,jsx,yml}\"", - "eslint:fix": "eslint \"**/*.{js,jsx,yml}\" --fix" + "eslint:check": "eslint \"**/*.{js,jsx}\"", + "eslint:fix": "eslint \"**/*.{js,jsx}\" --fix" }, "engines": { "node": ">=16", From 75d67e84cc7bb9083293530a6b079e3dea8b29d1 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:28:58 -0500 Subject: [PATCH 09/10] fff --- .github/workflows/docker.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d5912639f..f045feba8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,17 +13,18 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 2 - - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'yarn' - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v34 + uses: tj-actions/changed-files@v32 with: files: | server/src/configs/*.json + - name: Setup Node.js environment + if: steps.changed-files.outputs.any_changed == 'true' + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' - name: Generate latest env vars if: steps.changed-files.outputs.any_changed == 'true' run: | From b68b74e45b2aeae3862d92fdbd936dec03106598 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:31:07 -0500 Subject: [PATCH 10/10] Update docker-compose.example.yml --- docker-compose.example.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 6094ca4c3..e86760e4b 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -49,8 +49,8 @@ services: - ./example.env:/home/node/.env security_opt: - # https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ - - no-new-privileges:true + # https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/ + - no-new-privileges:true ports: - '9090:8080'