Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: TT-511 environment variables and tests setup
  • Loading branch information
mikevillarruel committed Feb 9, 2022
commit ff75680f66069059eae03721040eeeb263797a47
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
Makefile
.gitignore
.env
keys.ts
.keys.json
12 changes: 0 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# choose base image to build off of
FROM node:14

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

# copy these over first and run 'npm install' so the node_modules will be cached
# until the package.json / lock changes
COPY package*.json .
RUN npm cache clean --force && npm install

# copy over all code files
COPY . .

# expose internal docker container port to external environment
EXPOSE 4200

# specify default command to run when we run the image
CMD /time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ help:
@echo "- make build --> Create docker image with dependencies needed"
@echo "- make run --> Execute docker container database from postgres, and api from image created previusly"
@echo "- make stop --> Stop container"
@echo "- make remove --> Restart container"
@echo "- make remove --> Delete container"
@echo "- make test --> Run all tests on docker container"
@echo "- make login --> Login in respository of docker images"
@echo "- make publish --> Publish the container image"
@echo "------------------------------------"

.PHONY: build
Expand All @@ -14,7 +18,7 @@ build:

.PHONY: run
run:
docker-compose up -d
docker-compose --env-file ./.env up -d
docker logs -f timetracker_ui

.PHONY: stop
Expand All @@ -30,3 +34,17 @@ restart:
.PHONY: remove
remove:
docker-compose down

.PHONY: test
test:
docker-compose --env-file ./.env up -d
docker exec -it timetracker_ui bash -c "npm test"

.PHONY: login
login:
az acr login --name timetrackerdevregistry

.PHONY: publish
publish:
docker tag timetracker_ui:latest timetrackerdevregistry.azurecr.io/timetracker_ui:latest
docker push timetrackerdevregistry.azurecr.io/timetracker_ui:latest
50 changes: 27 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ services:
dockerfile: ./Dockerfile
ports:
- 4200:4200
- 9876:9876
environment:
AUTHORITY: ${AUTHORITY}
CLIENT_ID: ${CLIENT_ID}
SCOPES: ${SCOPES}
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${AZURE_APP_CONFIGURATION_CONNECTION_STRING}
working_dir: /time-tracker-ui
command: bash -c "npm run config && /time-tracker-ui/node_modules/.bin/ng serve --host 0.0.0.0 --disableHostCheck"
volumes:
- ./src:/time-tracker-ui/src/
# - ./scripts:/time-tracker-ui/scripts/
# - ./e2e:/time-tracker-ui/e2e/
# - ./.browserslistrc:/time-tracker-ui/.browserslistrc
# - ./.dockerignore:/time-tracker-ui/.dockerignore
# - ./.editorconfig:/time-tracker-ui/.editorconfig
# - ./.eslintrc.js:/time-tracker-ui/.eslintrc.js
# - ./.prettierrc:/time-tracker-ui/.prettierrc
# - ./angular.json:/time-tracker-ui/angular.json
# - ./docker-compose.yml:/time-tracker-ui/docker-compose.yml
# - ./Dockerfile:/time-tracker-ui/Dockerfile
# - ./karma.conf.js:/time-tracker-ui/karma.conf.js
# - ./Makefile:/time-tracker-ui/Makefile
# - ./package.json:/time-tracker-ui/package.json
# - ./package-lock.json:/time-tracker-ui/package-lock.json
# - ./README.md:/time-tracker-ui/README.md
# - ./stryker.conf.json:/time-tracker-ui/stryker.conf.json
# - ./stryker.log:/time-tracker-ui/stryker.log
# - ./tailwind.config.js:/time-tracker-ui/tailwind.config.js
# - ./tsconfig.app.json:/time-tracker-ui/tsconfig.app.json
# - ./tsconfig.json:/time-tracker-ui/tsconfig.json
# - ./tsconfig.spec.json:/time-tracker-ui/tsconfig.spec.json
# - ./tslint.json:/time-tracker-ui/tslint.json
# - ./webpack.config.js:/time-tracker-ui/webpack.config.js
- ./scripts:/time-tracker-ui/scripts/
- ./e2e:/time-tracker-ui/e2e/
- ./coverage:/time-tracker-ui/coverage
- ./.browserslistrc:/time-tracker-ui/.browserslistrc
- ./.dockerignore:/time-tracker-ui/.dockerignore
- ./.editorconfig:/time-tracker-ui/.editorconfig
- ./.eslintrc.js:/time-tracker-ui/.eslintrc.js
- ./.prettierrc:/time-tracker-ui/.prettierrc
- ./angular.json:/time-tracker-ui/angular.json
- ./karma.conf.js:/time-tracker-ui/karma.conf.js
- ./package.json:/time-tracker-ui/package.json
- ./stryker.conf.json:/time-tracker-ui/stryker.conf.json
- ./tailwind.config.js:/time-tracker-ui/tailwind.config.js
- ./tsconfig.app.json:/time-tracker-ui/tsconfig.app.json
- ./tsconfig.json:/time-tracker-ui/tsconfig.json
- ./tsconfig.spec.json:/time-tracker-ui/tsconfig.spec.json
- ./tslint.json:/time-tracker-ui/tslint.json
- ./webpack.config.js:/time-tracker-ui/webpack.config.js
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "time-tracker",
"version": "1.61.0",
"scripts": {
"config": "ts-node ./scripts/setenv.ts",
"preinstall": "npx npm-force-resolutions",
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"start": "npm run config && ng serve",
"build": "npm run config && ng build --prod",
"test": "ng test",
"test-headless": "ng test --browsers ChromeHeadless",
"ci-test": "ng test --no-watch --no-progress --browsers ChromeHeadless",
Expand Down Expand Up @@ -44,6 +45,7 @@
"datatables.net-responsive": "2.2.6",
"datatables.net-responsive-dt": "2.2.6",
"date-fns": "2.22.1",
"dotenv": "^14.2.0",
"jquery": "3.5.1",
"jszip": "3.7.0",
"minimist": "1.2.5",
Expand Down
34 changes: 34 additions & 0 deletions scripts/setenv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { writeFile } = require('fs');
require('dotenv').config();

const pathJs = `./src/environments/keys.ts`
const contentKeys =
`export const AUTHORITY = '${process.env.AUTHORITY}';
export const CLIENT_ID = '${process.env.CLIENT_ID}';
export const SCOPES = ['${process.env.SCOPES}'];
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}';
`;

writeFile(pathJs, contentKeys, function (err) {
if (err) {
console.log(err);
}
console.log(`Wrote variables to ${pathJs}`);
});

const pathJson = `./src/environments/.keys.json`
const contentKeysJson =
`{
"authority": "${process.env.AUTHORITY_JSON}",
"client_id": "${process.env.CLIENT_ID_JSON}",
"scopes": ["${process.env.SCOPES_JSON}"]
}`;

writeFile(pathJson, contentKeysJson, function (err) {
if (err) {
console.log(err);
}
console.log(`Wrote variables to ${pathJson}`);
});