From f5379e0c84bd037f013753604688a0e714d3da9d Mon Sep 17 00:00:00 2001 From: nicolsss Date: Mon, 9 May 2022 16:28:31 -0500 Subject: [PATCH] Removing use of keys.ts to store evironment variables --- .github/workflows/CD-time-tracker-ui.yml | 4 ++-- .github/workflows/CI-time-tracker-ui.yml | 11 ++++++++--- Dockerfile | 4 ++-- package.json | 1 - scripts/populate-keys.sh | 12 ++++++------ src/environments/environment.ts | 13 ++++++------- webpack.config.js | 22 ++++++++++++++++++---- 7 files changed, 42 insertions(+), 25 deletions(-) diff --git a/.github/workflows/CD-time-tracker-ui.yml b/.github/workflows/CD-time-tracker-ui.yml index 5934939b6..db0ed3d19 100644 --- a/.github/workflows/CD-time-tracker-ui.yml +++ b/.github/workflows/CD-time-tracker-ui.yml @@ -35,8 +35,8 @@ jobs: STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.stack_exchange_access_token }} AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.azure_app_configuration_connection_string }} run: | - chmod +x ./scripts/populate-var-file.sh - sh ./scripts/populate-var-file.sh + chmod +x ./scripts/populate-keys.sh + sh ./scripts/populate-keys.sh - name: 'run: npm install and build' run: | diff --git a/.github/workflows/CI-time-tracker-ui.yml b/.github/workflows/CI-time-tracker-ui.yml index f63625e00..bfa81fde6 100644 --- a/.github/workflows/CI-time-tracker-ui.yml +++ b/.github/workflows/CI-time-tracker-ui.yml @@ -48,11 +48,16 @@ jobs: STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.STACK_EXCHANGE_ACCESS_TOKEN }} AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.AZURE_APP_CONFIGURATION_CONNECTION_STRING }} run: | - chmod +x ./scripts/populate-var-file.sh - sh ./scripts/populate-var-file.sh + chmod +x ./scripts/populate-keys.sh + sh ./scripts/populate-keys.sh - name: Running tests - run: npm run ci-test --if-present + run: | + set -a + source .env + set +a + npm run ci-test --if-present + rm .env - name: Generate coverage report env: diff --git a/Dockerfile b/Dockerfile index e1e08bc62..aa7f1e0ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,13 +43,13 @@ USER ${USERNAME} RUN npm cache clean --force && npm install EXPOSE 4200 EXPOSE 9876 -CMD npm run config && ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck +CMD ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck FROM development as build COPY .env . -RUN npm run config && npm run build +RUN npm run build diff --git a/package.json b/package.json index c0661d64e..e40592e44 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "time-tracker", "version": "1.72.5", "scripts": { - "config": "ts-node ./scripts/setenv.ts", "preinstall": "npx npm-force-resolutions", "ng": "ng", "start": "ng serve", diff --git a/scripts/populate-keys.sh b/scripts/populate-keys.sh index 6ab4a5cd4..504fa13d7 100644 --- a/scripts/populate-keys.sh +++ b/scripts/populate-keys.sh @@ -1,10 +1,10 @@ #!/bin/bash > .env -echo 'AUTHORITY = '$AUTHORITY'' >> .env -echo 'CLIENT_ID = '$CLIENT_ID'' >> .env -echo 'SCOPES = '$SCOPES'' >> .env -echo 'STACK_EXCHANGE_ID = '$STACK_EXCHANGE_ID'' >> .env -echo 'STACK_EXCHANGE_ACCESS_TOKEN = '$STACK_EXCHANGE_ACCESS_TOKEN'' >> .env -echo 'AZURE_APP_CONFIGURATION_CONNECTION_STRING = '$AZURE_APP_CONFIGURATION_CONNECTION_STRING'' >> .env +echo "AUTHORITY='$AUTHORITY'" >> .env +echo "CLIENT_ID='$CLIENT_ID'" >> .env +echo "SCOPES='$SCOPES'" >> .env +echo "STACK_EXCHANGE_ID='$STACK_EXCHANGE_ID'" >> .env +echo "STACK_EXCHANGE_ACCESS_TOKEN='$STACK_EXCHANGE_ACCESS_TOKEN'" >> .env +echo "AZURE_APP_CONFIGURATION_CONNECTION_STRING='$AZURE_APP_CONFIGURATION_CONNECTION_STRING'" >> .env cat .env diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 6846b4ca6..142dae653 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,7 +1,6 @@ // This file can be replaced during build by using the `fileReplacements` array. // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. // The list of file replacements can be found in `angular.json`. -import * as keys from './keys'; export const environment = { production: false, @@ -9,13 +8,13 @@ export const environment = { stackexchangeApiUrl: 'https://api.stackexchange.com', }; -export const AUTHORITY = keys.AUTHORITY; -export const CLIENT_ID = keys.CLIENT_ID; -export const SCOPES = keys.SCOPES; +export const AUTHORITY = process.env.AUTHORITY; +export const CLIENT_ID = process.env.CLIENT_ID; +export const SCOPES = process.env.SCOPES.split(","); export const ITEMS_PER_PAGE = 5; -export const STACK_EXCHANGE_ID = keys.STACK_EXCHANGE_ID; -export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN; -export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING; +export const STACK_EXCHANGE_ID = process.env.STACK_EXCHANGE_ID; +export const STACK_EXCHANGE_ACCESS_TOKEN = process.env.STACK_EXCHANGE_ACCESS_TOKEN; +export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = process.env.AZURE_APP_CONFIGURATION_CONNECTION_STRING; export const DATE_FORMAT = 'yyyy-MM-dd'; export const DATE_FORMAT_YEAR = 'YYYY-MM-DD'; export const GROUPS = { diff --git a/webpack.config.js b/webpack.config.js index 1a85a6c20..792122824 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,11 +1,25 @@ +const webpack = require('webpack') const { addTailwindPlugin } = require("@ngneat/tailwind"); const tailwindConfig = require("./tailwind.config.js"); - module.exports = (config) => { + const config_ = { + ...config, + plugins : [ + ...config.plugins, + new webpack.DefinePlugin({ + 'process.env.AUTHORITY': JSON.stringify(process.env["AUTHORITY"]), + 'process.env.CLIENT_ID':JSON.stringify(process.env["CLIENT_ID"]), + 'process.env.SCOPES':JSON.stringify(process.env["SCOPES"]), + 'process.env.STACK_EXCHANGE_ID':JSON.stringify(process.env["STACK_EXCHANGE_ID"]), + 'process.env.STACK_EXCHANGE_ACCESS_TOKEN':JSON.stringify(process.env["STACK_EXCHANGE_ACCESS_TOKEN"]), + 'process.env.AZURE_APP_CONFIGURATION_CONNECTION_STRING':JSON.stringify(process.env["AZURE_APP_CONFIGURATION_CONNECTION_STRING"]) + }) + ] + } addTailwindPlugin({ - webpackConfig: config, + webpackConfig: config_, tailwindConfig, patchComponentsStyles: true }); - return config; -}; + return config_; +}; \ No newline at end of file