forked from bcgov/PSP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
223 lines (171 loc) · 8.99 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/make
SHELL := /usr/bin/env bash
.DEFAULT_GOAL := help
ifneq ($(OS),Windows_NT)
POSIXSHELL := 1
else
POSIXSHELL :=
endif
# to see all colors, run
# bash -c 'for c in {0..255}; do tput setaf $c; tput setaf $c | cat -v; echo =$c; done'
# the first 15 entries are the 8-bit colors
# define standard colors
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
# default "prompt"
P = ${GREEN}[+]${RESET}
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help
##############################################################################
# Release Management
##############################################################################
VERSION := $(shell node -pe "require('./frontend/package.json').version")
.PHONY: version
version: ## Prints the current version number
@echo "v$(VERSION)"
.PHONY: bump
bump: ## Bumps the version number
ifndef $(ARGS)
$(eval ARGS := --build)
endif
@node ./build/bump-version.js $(ARGS) --apply
##############################################################################
# DevSecOps
##############################################################################
# python is required for DevSecOps tools
PYTHON := $(shell command -v python 2> /dev/null)
JQ := $(shell command -v jq 2> /dev/null)
.PHONY: devops-install
devops-install: ## Installs software required by DevSecOps tooling (e.g. python, etc)
@if [ -z $(PYTHON) ]; then echo "Python could not be found. See See https://docs.python.org/3/"; exit 2; fi
@if [ -z $(JQ) ]; then echo "JQ could not be found. See See https://stedolan.github.io/jq/"; exit 2; fi
@python -m ensurepip --upgrade
@pip install trufflehog3 jtbl
.PHONY: devops-scan
devops-scan: | devops-install ## Scans the repo for accidental leaks of passwords/secrets
@echo "$(P) Scanning codebase for leaked passwords and secrets..."
-@trufflehog3 --no-history --config .github/.trufflehog3.yml --format json --output trufflehog_report.json
@echo "$(P) Generating HTML report..."
@trufflehog3 -R trufflehog_report.json --output trufflehog_report.html
@echo "$(P) HTML report saved to trufflehog_report.html"
@echo
@./build/secops_report.sh trufflehog_report.json
##############################################################################
# Docker Development
##############################################################################
restart: | stop build up ## Restart local docker environment
refresh: | down build up ## Recreates local docker environment
.PHONY: start-infra
start-infra: ## Starts infrastructure containers (e.g. keycloak, database, geoserver). Useful for local debugging
@echo "$(P) Starting up infrastructure containers..."
@"$(MAKE)" start n="keycloak database geoserver"
start up: ## Runs the local containers (n=service name)
@echo "$(P) Running client and server..."
@docker-compose up -d $(n)
destroy: ## Stops the local containers and removes them (n=service name)
@echo "$(P) Removing docker containers..."
@docker-compose rm -s -f $(n)
down: ## Stops the local containers and removes them
@echo "$(P) Stopping client and server..."
@docker-compose down
stop: ## Stops the local containers (n=service name)
@echo "$(P) Stopping client and server..."
@docker-compose stop $(n)
build: ## Builds the local containers (n=service name)
@echo "$(P) Building images..."
@docker-compose build --no-cache $(n)
rebuild: ## Build the local contains (n=service name) and then start them after building
@"$(MAKE)" build n=$(n)
@"$(MAKE)" up n=$(n)
clean: ## Removes all local containers, images, volumes, etc
@echo "$(P) Removing all containers, images, volumes for solution."
@docker-compose rm -f -v -s
@docker volume rm -f psp-frontend-node-cache
@docker volume rm -f psp-api-db-data
logs: ## Shows logs for running containers (n=service name)
@docker-compose logs -f $(n)
setup: ## Setup local container environment, initialize keycloak and database
@"$(MAKE)" build; make up; make pause-30; make db-update; make db-seed; make keycloak-sync;
pause-30:
@echo "$(P) Pausing 30 seconds..."
@-sleep 30
client-test: ## Runs the client tests in a container
@echo "$(P) Running client unit tests..."
@docker-compose run frontend npm test
server-test: ## Runs the server tests in a container
@echo "$(P) Running server unit tests..."
@docker-compose run backend dotnet test
server-run: ## Starts local server containers
@echo "$(P) Starting server containers..."
@docker-compose up -d keycloak backend
npm-clean: ## Removes local containers, images, volumes, for frontend application.
@echo "$(P) Removing frontend containers and volumes."
@docker-compose stop frontend
@docker-compose rm -f -v -s frontend
@docker volume rm -f psp-frontend-node-cache
npm-refresh: ## Cleans and rebuilds the frontend. This is useful when npm packages are changed.
@"$(MAKE)" npm-clean; make build n=frontend; make up;
db-migrations: ## Display a list of migrations.
@echo "$(P) Display a list of migrations."
@cd backend/dal; dotnet ef migrations list
db-add: ## Add a new database migration for the specified name (n=name of migration).
@echo "$(P) Create a new database migration for the specified name."
@cd backend/dal; dotnet ef migrations add $(n); code -r ./Migrations/*_$(n).cs
@./scripts/db-migration.sh $(n);
db-update: ## Update the database with the latest migration.
@echo "$(P) Updating database with latest migration..."
@docker-compose up -d database; cd backend/dal; dotnet ef database update
db-rollback: ## Rollback to the specified database migration (n=name of migration).
@echo "$(P) Rollback to the specified database migration."
@cd backend/dal; dotnet ef database update $(n);
db-remove: ## Remove the last database migration.
@echo "$(P) Remove the last migration."
@cd backend/dal; dotnet ef migrations remove --force;
db-clean: ## Re-creates an empty docker database - ready for seeding.
@echo "$(P) Refreshing the database..."
@cd backend/dal; dotnet ef database drop --force; dotnet ef database update
db-refresh: | server-run pause-30 db-clean db-seed keycloak-sync ## Refresh the database and seed it with data.
db-drop: ## Drop the database.
@echo "$(P) Drop the database."
@cd backend/dal; dotnet ef database drop;
db-seed: ## Imports a JSON file of properties into PIMS
@echo "$(P) Seeding docker database..."
@cd tools/import; dotnet build; dotnet run;
db-script: ## Export an SQL script from the migration (from=0 to=Initial).
@echo "$(P) Exporting script to 'db-migration.sql'"
@cd backend/dal; dotnet ef migrations script ${from} ${to} --output ../../db-migration.sql
keycloak-sync: ## Syncs accounts with Keycloak and PIMS
@echo "$(P) Syncing keycloak with PIMS..."
@cd tools/keycloak/sync; dotnet build; dotnet run;
convert: ## Convert Excel files to JSON
@echo "$(P) Convert Excel files to JSON..."
@cd tools/converters/excel; dotnet build; dotnet run;
backend-test: ## Run backend unit tests
@echo "$(P) Run backend unit tests"
@cd backend; dotnet test;
frontend-test: ## Run frontend unit tests
@echo "$(P) Run frontend unit tests"
@cd frontend; npm run test:watch;
backend-coverage: ## Generate coverage report for backend
@echo "$(P) Generate coverage report for backend"
@cd backend/tests/unit/api; dotnet build;
@cd backend/tests/unit/dal; dotnet build;
@cd backend; coverlet ./tests/unit/api/bin/Debug/net5.0/Pims.Api.Test.dll --target "dotnet" --targetargs "test ./ --no-build" -o "./tests/TestResults/coverage.json" --exclude "[*.Test]*" --exclude "[*]*Model" --exclude-by-attribute "CompilerGenerated" -f json
@cd backend; coverlet ./tests/unit/dal/bin/Debug/net5.0/Pims.Dal.Test.dll --target "dotnet" --targetargs "test ./ --no-build" -o "./tests/TestResults/coverage.xml" --exclude "[*.Test]*" --exclude "[*]*Model" --exclude-by-attribute "CompilerGenerated" --merge-with "tests/TestResults/coverage.json" -f cobertura
@cd backend; reportgenerator "-reports:./tests/TestResults/coverage.xml" "-targetdir:./tests/TestResults/Coverage" -reporttypes:Html
@cd backend; start ./tests/TestResults/Coverage/index.htm
frontend-coverage: ## Generate coverage report for frontend
@echo "$(P) Generate coverage report for frontend"
@cd frontend; npm run coverage;
env: ## Generate env files
@echo "$(P) Generate/Regenerate env files required for application (generated passwords only match if database .env file does not already exist)"
@./scripts/gen-env-files.sh;
.PHONY: logs start destroy local setup restart refresh up down stop build rebuild clean client-test server-test pause-30 server-run db-migrations db-add db-update db-rollback db-remove db-clean db-drop db-seed db-refresh db-script npm-clean npm-refresh keycloak-sync convert backend-coverage frontend-coverage backend-test frontend-test env