1818# - helm
1919# - yq
2020
21- ifeq ($(include_guard ) ,)
22- $(error you should never run this makefile directly!)
23- endif
24- ifeq ($(scanner ) ,)
25- $(error scanner ENV is not set)
26- endif
27-
28- # Thx to https://stackoverflow.com/questions/5618615/check-if-a-program-exists-from-a-makefile
29- EXECUTABLES = make docker kind git node npm npx kubectl helm yq
30- K := $(foreach exec,$(EXECUTABLES ) ,\
31- $(if $(shell which $(exec ) ) ,some string,$(error "ERROR: The prerequisites are not met to execute this makefile! No '$(exec ) ' found in your PATH") ) )
32-
33-
34- # Variables you might want to override:
35- #
36- # IMG_NS: Defines the namespace under which the images are build.
37- # For `securecodebox/scanner-nmap` `securecodebox` is the namespace
38- # Defaults to `securecodebox`
39- #
40- # BASE_IMG_TAG: Defines the tag of the base image used to build this scanner/hook
41- #
42- # IMG_TAG: Tag used to tag the newly created image. Defaults to the shortend commit hash
43- # prefixed with `sha-` e.g. `sha-ef8de4b7`
44- #
45- # JEST_VERSION Defines the jest version used for executing the tests. Defaults to latest
46- #
47- # Examples:
48- # make all IMG_TAG=main
49- # make deploy IMG_TAG=$(git rev-parse --short HEAD)
50- # make integration-tests
51- #
21+ name = ${scanner}
5222
53- SHELL = /bin/sh
54-
55- IMG_NS ?= securecodebox
56- GIT_TAG ?= $$(git rev-parse --short HEAD )
57- BASE_IMG_TAG ?= latest
58- IMG_TAG ?= "sha-$(GIT_TAG ) "
59- JEST_VERSION ?= latest
60-
61- scanner-prefix = scanner
62- parser-prefix = parser
23+ include ../../common.mk
6324
6425ifeq ($(custom_scanner ) ,)
6526 docker-build : | docker-build-parser
@@ -73,112 +34,45 @@ else
7334 deploy : deploy-with-scanner
7435endif
7536
76-
77- test : | unit-tests-parser docker-build docker-export kind-import deploy deploy-test-deps integration-tests
78-
79- all : | clean install-deps unit-tests-parser docker-build docker-export kind-import deploy deploy-test-deps integration-tests
80-
81- .PHONY : unit-tests-parser install-deps docker-build docker-export kind-import deploy deploy-test-deps integration-tests all build test
82-
83- unit-tests-parser :
84- @echo " .: 🧪 Starting unit-tests for '$( scanner) ' parser with 'jest@$( JEST_VERSION) '."
85- npx --yes --package jest@$(JEST_VERSION ) jest --ci --colors --coverage --passWithNoTests ${scanner} /parser/
37+ unit-tests :
38+ @$(MAKE ) -s unit-test-js module=$(parser-prefix )
8639
8740install-deps :
88- @echo " .: ⚙️ Installing all scanner specific dependencies."
89- cd ./.. && npm ci
90- cd ../../parser-sdk/nodejs && npm ci
91- cd ./parser/ && npm ci
41+ @$(MAKE ) -s install-deps-js module=$(parser-prefix )
9242
9343docker-build-parser :
94- @echo " .: ⚙️ Build parser with BASE_IMG_TAG: '$( BASE_IMG_TAG) '."
95- docker build --build-arg=baseImageTag=$(BASE_IMG_TAG ) --build-arg=namespace=$(IMG_NS ) -t $(IMG_NS ) /$(parser-prefix ) -$(scanner ) :$(IMG_TAG ) -f ./parser/Dockerfile ./parser
44+ @$(MAKE ) -s common-docker-build module=$(parser-prefix )
9645
9746docker-export-parser :
98- @echo " .: ⚙️ Saving new docker image archive to '$( parser-prefix) -$( scanner) .tar'."
99- docker save $(IMG_NS ) /$(parser-prefix ) -$(scanner ) :$(IMG_TAG ) -o $(parser-prefix ) -$(scanner ) .tar
47+ @$(MAKE ) -s common-docker-export module=$(parser-prefix )
10048
10149kind-import-parser :
102- @echo " .: 💾 Importing the image archive '$( parser-prefix) -$( scanner) .tar' to local kind cluster."
103- kind load image-archive ./$(parser-prefix ) -$(scanner ) .tar
50+ @$(MAKE ) -s common-kind-import module=$(parser-prefix )
10451
10552docker-build-scanner :
106- @echo " .: ⚙️ Build custom scanner with BASE_IMG_TAG: '$( BASE_IMG_TAG) '."
107- docker build --build-arg=scannerVersion=$(shell yq e .appVersion ./Chart.yaml) --build-arg=namespace=$(IMG_NS ) -t $(IMG_NS ) /$(scanner-prefix ) -$(scanner ) :$(IMG_TAG ) -f ./scanner/Dockerfile ./scanner
53+ @$(MAKE ) -s common-docker-build module=$(scanner-prefix )
10854
10955docker-export-scanner :
110- @echo " .: ⚙️ Saving new docker image archive to '$( scanner-prefix) -$( scanner) .tar'." ; \
111- docker save $(IMG_NS ) /$(scanner-prefix ) -$(scanner ) :$(IMG_TAG ) -o $(scanner-prefix ) -$(scanner ) .tar; \
56+ @$(MAKE ) -s common-docker-export module=$(scanner-prefix )
11257
11358kind-import-scanner :
114- @echo " .: 💾 Importing the image archive '$( scanner-prefix) -$( scanner) .tar' to local kind cluster."
115- kind load image-archive ./$(scanner-prefix ) -$(scanner ) .tar
59+ @$(MAKE ) -s common-kind-import module=$(scanner-prefix )
11660
11761deploy-without-scanner :
118- @echo " .: 💾 Deploying '$( scanner ) ' scanner HelmChart with the docker tag '$( IMG_TAG) ' into kind namespace 'integration-tests'."
119- helm -n integration-tests upgrade --install $(scanner ) ./ --wait \
120- --set=" parser.image.repository=docker.io/$( IMG_NS) /$( parser-prefix) -$( scanner ) " \
62+ @echo " .: 💾 Deploying '$( name ) ' $( scanner-prefix ) HelmChart with the docker tag '$( IMG_TAG) ' into kind namespace 'integration-tests'."
63+ helm -n integration-tests upgrade --install $(name ) ./ --wait \
64+ --set=" parser.image.repository=docker.io/$( IMG_NS) /$( parser-prefix) -$( name ) " \
12165 --set=" parser.image.tag=$( IMG_TAG) "
12266
12367deploy-with-scanner :
124- @echo " .: 💾 Deploying '$( scanner ) ' scanner HelmChart with the docker tag '$( IMG_TAG) ' into kind namespace 'integration-tests'."
125- helm -n integration-tests upgrade --install $(scanner ) ./ --wait \
126- --set=" parser.image.repository=docker.io/$( IMG_NS) /$( parser-prefix) -$( scanner ) " \
68+ @echo " .: 💾 Deploying '$( name ) ' $( scanner-prefix ) HelmChart with the docker tag '$( IMG_TAG) ' into kind namespace 'integration-tests'."
69+ helm -n integration-tests upgrade --install $(name ) ./ --wait \
70+ --set=" parser.image.repository=docker.io/$( IMG_NS) /$( parser-prefix) -$( name ) " \
12771 --set=" parser.image.tag=$( IMG_TAG) " \
128- --set=" scanner.image.repository=docker.io/$( IMG_NS) /$( scanner-prefix) -$( scanner ) " \
72+ --set=" scanner.image.repository=docker.io/$( IMG_NS) /$( scanner-prefix) -$( name ) " \
12973 --set=" scanner.image.tag=$( IMG_TAG) "
13074
131- deploy-test-deps : deploy-test-dep-namespace
132-
133- deploy-test-dep-namespace :
134- # If not exists create namespace where the tests will be executed
135- kubectl create namespace demo-targets --dry-run=client -o yaml | kubectl apply -f -
136-
137- deploy-test-dep-dummy-ssh :
138- # Install dummy-ssh app
139- helm -n demo-targets upgrade --install dummy-ssh ../../demo-targets/dummy-ssh/ --set=" fullnameOverride=dummy-ssh" --wait
140-
141- deploy-test-dep-unsafe-https :
142- # Install unsafe-https app
143- helm -n demo-targets upgrade --install unsafe-https ../../demo-targets/unsafe-https/ --set=" fullnameOverride=unsafe-https" --wait
144-
145- deploy-test-dep-bodgeit :
146- # Install bodgeit app
147- helm -n demo-targets upgrade --install bodgeit ../../demo-targets/bodgeit/ --set=" fullnameOverride=bodgeit" --wait
148-
149- deploy-test-dep-petstore :
150- # Install bodgeit app
151- helm -n demo-targets upgrade --install petstore ../../demo-targets/swagger-petstore/ --set=" fullnameOverride=petstore" --wait
152-
153- deploy-test-dep-old-wordpress :
154- # Install old-wordpress app
155- helm -n demo-targets upgrade --install old-wordpress ../../demo-targets/old-wordpress/ --set=" fullnameOverride=old-wordpress" --wait
156-
157- deploy-test-dep-juiceshop :
158- # Install juiceshop app
159- helm -n demo-targets upgrade --install juiceshop ../../demo-targets/juice-shop/ --set=" fullnameOverride=juiceshop" --wait
160-
161- deploy-test-dep-nginx :
162- # Delete leftover nginx's. Unfortunately can't create deployment only if not exists (like namespaces)
163- kubectl delete deployment nginx --namespace demo-targets --ignore-not-found --wait
164- kubectl delete svc nginx --namespace demo-targets --ignore-not-found --wait
165- # Install plain nginx server
166- kubectl create deployment --image nginx:alpine nginx --namespace demo-targets
167- kubectl expose deployment nginx --port 80 --namespace demo-targets
168-
169- install-integration-test-deps :
170-
17175integration-tests :
17276 @echo " .: 🩺 Starting integration test in kind namespace 'integration-tests'."
17377 kubectl -n integration-tests delete scans --all
174- cd ../../tests/integration/ && npm ci && npx --yes --package jest@$(JEST_VERSION ) jest --verbose --ci --colors --coverage --passWithNoTests scanner/${scanner} .test.js
175-
176- clean :
177- @echo " .: 🧹 Cleaning up all generated files."
178- rm -f ./$(parser-prefix ) -$(scanner ) .tar
179- rm -rf ./parser/node_modules
180- rm -rf ./parser/coverage
181- rm -rf ./integration-tests/node_modules
182- rm -rf ./integration-tests/coverage
183- rm -rf ../node_modules
184- rm -rf ../coverage
78+ cd ../../tests/integration/ && npm ci && npx --yes --package jest@$(JEST_VERSION ) jest --verbose --ci --colors --coverage --passWithNoTests ${scanner-prefix} /${name} .test.js
0 commit comments