diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index b3761e4ce..d8e61bd4b 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -15,17 +15,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@v33 + uses: tj-actions/changed-files@v32 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: Run script if: steps.changed-files.outputs.any_changed == 'true' run: | diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2059b22dc..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: Get changed files + id: changed-files + 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: Get changed files - id: changed-files - uses: tj-actions/changed-files@v33 - with: - files: | - server/src/configs/default.json - name: Generate latest env vars if: steps.changed-files.outputs.any_changed == 'true' run: | diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 0dfc7fdb9..e86760e4b 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -6,29 +6,54 @@ 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/ + # 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/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/package.json b/package.json index b91b72925..c97682128 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ "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}\"", + "prettier:check": "prettier --check \"**/*.{css,html,js,jsx,yml}\"", + "prettier:fix": "prettier --write \"**/*.{css,html,js,jsx,yml}\"", "eslint:check": "eslint \"**/*.{js,jsx}\"", "eslint:fix": "eslint \"**/*.{js,jsx}\" --fix" }, 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(