Skip to content

Commit 6932912

Browse files
authored
Revert "TT-630 enviroment variables (#867)" (#868)
This reverts commit 78578be.
1 parent 78578be commit 6932912

File tree

10 files changed

+74
-47
lines changed

10 files changed

+74
-47
lines changed

.github/workflows/CD-time-tracker-ui.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.stack_exchange_access_token }}
3636
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.azure_app_configuration_connection_string }}
3737
run: |
38-
chmod +x ./scripts/populate-keys.sh
39-
sh ./scripts/populate-keys.sh
38+
chmod +x ./scripts/populate-var-file.sh
39+
sh ./scripts/populate-var-file.sh
4040
4141
- name: 'run: npm install and build'
4242
run: |

.github/workflows/CI-time-tracker-ui.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@ jobs:
4848
STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.STACK_EXCHANGE_ACCESS_TOKEN }}
4949
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.AZURE_APP_CONFIGURATION_CONNECTION_STRING }}
5050
run: |
51-
chmod +x ./scripts/populate-keys.sh
52-
sh ./scripts/populate-keys.sh
51+
chmod +x ./scripts/populate-var-file.sh
52+
sh ./scripts/populate-var-file.sh
5353
5454
- name: Running tests
55-
run: |
56-
set -a
57-
source .env
58-
set +a
59-
npm run ci-test --if-present
60-
rm .env
55+
run: npm run ci-test --if-present
6156

6257
- name: Generate coverage report
6358
env:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ USER ${USERNAME}
4343
RUN npm cache clean --force && npm install
4444
EXPOSE 4200
4545
EXPOSE 9876
46-
CMD ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck
46+
CMD npm run config && ${HOME}/time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck
4747

4848

4949

5050
FROM development as build
5151
COPY .env .
52-
RUN npm run build
52+
RUN npm run config && npm run build
5353

5454

5555

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "time-tracker",
33
"version": "1.72.7",
44
"scripts": {
5+
"config": "ts-node ./scripts/setenv.ts",
56
"preinstall": "npx npm-force-resolutions",
67
"ng": "ng",
78
"start": "ng serve",

scripts/populate-keys.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

33
> .env
4-
echo "AUTHORITY='$AUTHORITY'" >> .env
5-
echo "CLIENT_ID='$CLIENT_ID'" >> .env
6-
echo "SCOPES='$SCOPES'" >> .env
7-
echo "STACK_EXCHANGE_ID='$STACK_EXCHANGE_ID'" >> .env
8-
echo "STACK_EXCHANGE_ACCESS_TOKEN='$STACK_EXCHANGE_ACCESS_TOKEN'" >> .env
9-
echo "AZURE_APP_CONFIGURATION_CONNECTION_STRING='$AZURE_APP_CONFIGURATION_CONNECTION_STRING'" >> .env
4+
echo 'AUTHORITY = '$AUTHORITY'' >> .env
5+
echo 'CLIENT_ID = '$CLIENT_ID'' >> .env
6+
echo 'SCOPES = '$SCOPES'' >> .env
7+
echo 'STACK_EXCHANGE_ID = '$STACK_EXCHANGE_ID'' >> .env
8+
echo 'STACK_EXCHANGE_ACCESS_TOKEN = '$STACK_EXCHANGE_ACCESS_TOKEN'' >> .env
9+
echo 'AZURE_APP_CONFIGURATION_CONNECTION_STRING = '$AZURE_APP_CONFIGURATION_CONNECTION_STRING'' >> .env
1010
cat .env

scripts/populate-var-file.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
> src/environments/keys.ts
4+
echo 'export const AUTHORITY = "'$AUTHORITY'";' >> src/environments/keys.ts
5+
echo 'export const CLIENT_ID = "'$CLIENT_ID'";' >> src/environments/keys.ts
6+
echo 'export const SCOPES = ["'$SCOPES'"];' >> src/environments/keys.ts
7+
echo 'export const STACK_EXCHANGE_ID = "'$STACK_EXCHANGE_ID'";' >> src/environments/keys.ts
8+
echo 'export const STACK_EXCHANGE_ACCESS_TOKEN = "'$STACK_EXCHANGE_ACCESS_TOKEN'";' >> src/environments/keys.ts
9+
echo 'export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = "'$AZURE_APP_CONFIGURATION_CONNECTION_STRING'";' >> src/environments/keys.ts
10+
cat src/environments/keys.ts

scripts/setenv.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { writeFile } = require('fs');
2+
3+
const pathJs = `./src/environments/keys.ts`
4+
const contentKeys =
5+
`export const AUTHORITY = '${process.env["AUTHORITY"]}';
6+
export const CLIENT_ID = '${process.env["CLIENT_ID"]}';
7+
export const SCOPES = ['${process.env["SCOPES"]}'];
8+
export const STACK_EXCHANGE_ID = '${process.env["STACK_EXCHANGE_ID"]}';
9+
export const STACK_EXCHANGE_ACCESS_TOKEN = '${process.env["STACK_EXCHANGE_ACCESS_TOKEN"]}';
10+
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = '${process.env["AZURE_APP_CONFIGURATION_CONNECTION_STRING"]}';
11+
`;
12+
13+
writeFile(pathJs, contentKeys, function (err) {
14+
if (err) {
15+
console.log(err);
16+
}
17+
console.log(`Wrote variables to ${pathJs}`);
18+
});
19+
20+
const pathJson = `./src/environments/.keys.json`
21+
const contentKeysJson =
22+
`{
23+
"authority": "${process.env.AUTHORITY_JSON}",
24+
"client_id": "${process.env.CLIENT_ID_JSON}",
25+
"scopes": ["${process.env.SCOPES_JSON}"]
26+
}`;
27+
28+
writeFile(pathJson, contentKeysJson, function (err) {
29+
if (err) {
30+
console.log(err);
31+
}
32+
console.log(`Wrote variables to ${pathJson}`);
33+
});

src/environments/environment.prod.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import * as keys from './keys';
12

23
export const environment = {
34
production: true,
45
timeTrackerApiUrl: 'https://timetracker-api.azurewebsites.net',
56
stackexchangeApiUrl: 'https://api.stackexchange.com',
67
};
78

8-
export const AUTHORITY = process.env["AUTHORITY"];
9-
export const CLIENT_ID = process.env["CLIENT_ID"];
10-
export const SCOPES = process.env["SCOPES"].split(",");
9+
export const AUTHORITY = keys.AUTHORITY;
10+
export const CLIENT_ID = keys.CLIENT_ID;
11+
export const SCOPES = keys.SCOPES;
1112
export const ITEMS_PER_PAGE = 5;
12-
export const STACK_EXCHANGE_ID = process.env["STACK_EXCHANGE_ID"];
13-
export const STACK_EXCHANGE_ACCESS_TOKEN = process.env["STACK_EXCHANGE_ACCESS_TOKEN"];
14-
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = process.env["AZURE_APP_CONFIGURATION_CONNECTION_STRING"];
13+
export const STACK_EXCHANGE_ID = keys.STACK_EXCHANGE_ID;
14+
export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN;
15+
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING;
1516
export const DATE_FORMAT = 'yyyy-MM-dd';
1617
export const DATE_FORMAT_YEAR = 'YYYY-MM-DD';
1718
export const GROUPS = {

src/environments/environment.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// This file can be replaced during build by using the `fileReplacements` array.
22
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
33
// The list of file replacements can be found in `angular.json`.
4+
import * as keys from './keys';
45

56
export const environment = {
67
production: false,
78
timeTrackerApiUrl: 'http://localhost:7071/api',
89
stackexchangeApiUrl: 'https://api.stackexchange.com',
910
};
1011

11-
export const AUTHORITY = process.env["AUTHORITY"];
12-
export const CLIENT_ID = process.env["CLIENT_ID"];
13-
export const SCOPES = process.env["SCOPES"].split(",");
12+
export const AUTHORITY = keys.AUTHORITY;
13+
export const CLIENT_ID = keys.CLIENT_ID;
14+
export const SCOPES = keys.SCOPES;
1415
export const ITEMS_PER_PAGE = 5;
15-
export const STACK_EXCHANGE_ID = process.env["STACK_EXCHANGE_ID"];
16-
export const STACK_EXCHANGE_ACCESS_TOKEN = process.env["STACK_EXCHANGE_ACCESS_TOKEN"];
17-
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = process.env["AZURE_APP_CONFIGURATION_CONNECTION_STRING"];
16+
export const STACK_EXCHANGE_ID = keys.STACK_EXCHANGE_ID;
17+
export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN;
18+
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING;
1819
export const DATE_FORMAT = 'yyyy-MM-dd';
1920
export const DATE_FORMAT_YEAR = 'YYYY-MM-DD';
2021
export const GROUPS = {

webpack.config.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
const webpack = require('webpack')
21
const { addTailwindPlugin } = require("@ngneat/tailwind");
32
const tailwindConfig = require("./tailwind.config.js");
3+
44
module.exports = (config) => {
5-
const config_ = {
6-
...config,
7-
plugins : [
8-
...config.plugins,
9-
new webpack.DefinePlugin({
10-
'process.env.AUTHORITY': JSON.stringify(process.env["AUTHORITY"]),
11-
'process.env.CLIENT_ID':JSON.stringify(process.env["CLIENT_ID"]),
12-
'process.env.SCOPES':JSON.stringify(process.env["SCOPES"]),
13-
'process.env.STACK_EXCHANGE_ID':JSON.stringify(process.env["STACK_EXCHANGE_ID"]),
14-
'process.env.STACK_EXCHANGE_ACCESS_TOKEN':JSON.stringify(process.env["STACK_EXCHANGE_ACCESS_TOKEN"]),
15-
'process.env.AZURE_APP_CONFIGURATION_CONNECTION_STRING':JSON.stringify(process.env["AZURE_APP_CONFIGURATION_CONNECTION_STRING"])
16-
})
17-
]
18-
}
195
addTailwindPlugin({
20-
webpackConfig: config_,
6+
webpackConfig: config,
217
tailwindConfig,
228
patchComponentsStyles: true
239
});
24-
return config_;
10+
return config;
2511
};

0 commit comments

Comments
 (0)