Skip to content

Commit ff75680

Browse files
feat: TT-511 environment variables and tests setup
1 parent 3fe4574 commit ff75680

File tree

7 files changed

+91
-38
lines changed

7 files changed

+91
-38
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
Makefile
44
.gitignore
55
.env
6+
keys.ts
7+
.keys.json

Dockerfile

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
# choose base image to build off of
21
FROM node:14
32

4-
# set the current working directory for all commands
53
WORKDIR /time-tracker-ui
64

7-
# copy these over first and run 'npm install' so the node_modules will be cached
8-
# until the package.json / lock changes
95
COPY package*.json .
106
RUN npm cache clean --force && npm install
11-
12-
# copy over all code files
137
COPY . .
14-
15-
# expose internal docker container port to external environment
16-
EXPOSE 4200
17-
18-
# specify default command to run when we run the image
19-
CMD /time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ help:
44
@echo "- make build --> Create docker image with dependencies needed"
55
@echo "- make run --> Execute docker container database from postgres, and api from image created previusly"
66
@echo "- make stop --> Stop container"
7+
@echo "- make remove --> Restart container"
78
@echo "- make remove --> Delete container"
9+
@echo "- make test --> Run all tests on docker container"
10+
@echo "- make login --> Login in respository of docker images"
11+
@echo "- make publish --> Publish the container image"
812
@echo "------------------------------------"
913

1014
.PHONY: build
@@ -14,7 +18,7 @@ build:
1418

1519
.PHONY: run
1620
run:
17-
docker-compose up -d
21+
docker-compose --env-file ./.env up -d
1822
docker logs -f timetracker_ui
1923

2024
.PHONY: stop
@@ -30,3 +34,17 @@ restart:
3034
.PHONY: remove
3135
remove:
3236
docker-compose down
37+
38+
.PHONY: test
39+
test:
40+
docker-compose --env-file ./.env up -d
41+
docker exec -it timetracker_ui bash -c "npm test"
42+
43+
.PHONY: login
44+
login:
45+
az acr login --name timetrackerdevregistry
46+
47+
.PHONY: publish
48+
publish:
49+
docker tag timetracker_ui:latest timetrackerdevregistry.azurecr.io/timetracker_ui:latest
50+
docker push timetrackerdevregistry.azurecr.io/timetracker_ui:latest

docker-compose.yml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,33 @@ services:
88
dockerfile: ./Dockerfile
99
ports:
1010
- 4200:4200
11+
- 9876:9876
12+
environment:
13+
AUTHORITY: ${AUTHORITY}
14+
CLIENT_ID: ${CLIENT_ID}
15+
SCOPES: ${SCOPES}
16+
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
17+
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}
18+
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${AZURE_APP_CONFIGURATION_CONNECTION_STRING}
1119
working_dir: /time-tracker-ui
20+
command: bash -c "npm run config && /time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck"
1221
volumes:
1322
- ./src:/time-tracker-ui/src/
14-
# - ./scripts:/time-tracker-ui/scripts/
15-
# - ./e2e:/time-tracker-ui/e2e/
16-
# - ./.browserslistrc:/time-tracker-ui/.browserslistrc
17-
# - ./.dockerignore:/time-tracker-ui/.dockerignore
18-
# - ./.editorconfig:/time-tracker-ui/.editorconfig
19-
# - ./.eslintrc.js:/time-tracker-ui/.eslintrc.js
20-
# - ./.prettierrc:/time-tracker-ui/.prettierrc
21-
# - ./angular.json:/time-tracker-ui/angular.json
22-
# - ./docker-compose.yml:/time-tracker-ui/docker-compose.yml
23-
# - ./Dockerfile:/time-tracker-ui/Dockerfile
24-
# - ./karma.conf.js:/time-tracker-ui/karma.conf.js
25-
# - ./Makefile:/time-tracker-ui/Makefile
26-
# - ./package.json:/time-tracker-ui/package.json
27-
# - ./package-lock.json:/time-tracker-ui/package-lock.json
28-
# - ./README.md:/time-tracker-ui/README.md
29-
# - ./stryker.conf.json:/time-tracker-ui/stryker.conf.json
30-
# - ./stryker.log:/time-tracker-ui/stryker.log
31-
# - ./tailwind.config.js:/time-tracker-ui/tailwind.config.js
32-
# - ./tsconfig.app.json:/time-tracker-ui/tsconfig.app.json
33-
# - ./tsconfig.json:/time-tracker-ui/tsconfig.json
34-
# - ./tsconfig.spec.json:/time-tracker-ui/tsconfig.spec.json
35-
# - ./tslint.json:/time-tracker-ui/tslint.json
36-
# - ./webpack.config.js:/time-tracker-ui/webpack.config.js
23+
- ./scripts:/time-tracker-ui/scripts/
24+
- ./e2e:/time-tracker-ui/e2e/
25+
- ./coverage:/time-tracker-ui/coverage
26+
- ./.browserslistrc:/time-tracker-ui/.browserslistrc
27+
- ./.dockerignore:/time-tracker-ui/.dockerignore
28+
- ./.editorconfig:/time-tracker-ui/.editorconfig
29+
- ./.eslintrc.js:/time-tracker-ui/.eslintrc.js
30+
- ./.prettierrc:/time-tracker-ui/.prettierrc
31+
- ./angular.json:/time-tracker-ui/angular.json
32+
- ./karma.conf.js:/time-tracker-ui/karma.conf.js
33+
- ./package.json:/time-tracker-ui/package.json
34+
- ./stryker.conf.json:/time-tracker-ui/stryker.conf.json
35+
- ./tailwind.config.js:/time-tracker-ui/tailwind.config.js
36+
- ./tsconfig.app.json:/time-tracker-ui/tsconfig.app.json
37+
- ./tsconfig.json:/time-tracker-ui/tsconfig.json
38+
- ./tsconfig.spec.json:/time-tracker-ui/tsconfig.spec.json
39+
- ./tslint.json:/time-tracker-ui/tslint.json
40+
- ./webpack.config.js:/time-tracker-ui/webpack.config.js

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "time-tracker",
33
"version": "1.61.0",
44
"scripts": {
5+
"config": "ts-node ./scripts/setenv.ts",
56
"preinstall": "npx npm-force-resolutions",
67
"ng": "ng",
7-
"start": "ng serve",
8-
"build": "ng build --prod",
8+
"start": "npm run config && ng serve",
9+
"build": "npm run config && ng build --prod",
910
"test": "ng test",
1011
"test-headless": "ng test --browsers ChromeHeadless",
1112
"ci-test": "ng test --no-watch --no-progress --browsers ChromeHeadless",
@@ -44,6 +45,7 @@
4445
"datatables.net-responsive": "2.2.6",
4546
"datatables.net-responsive-dt": "2.2.6",
4647
"date-fns": "2.22.1",
48+
"dotenv": "^14.2.0",
4749
"jquery": "3.5.1",
4850
"jszip": "3.7.0",
4951
"minimist": "1.2.5",

scripts/setenv.ts

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

0 commit comments

Comments
 (0)