|
1 | | -# the envfile has the 2 required environment variables: |
2 | | -# RLSECURE_SITE_KEY= |
| 1 | +# Makefile expects 2 required environment variables for |
| 2 | +# build-with-cache and test targets: |
3 | 3 | # RLSECURE_ENCODED_LICENSE= |
| 4 | +# RLSECURE_SITE_KEY= |
4 | 5 |
|
5 | | -ifdef DOCKER_TAG |
6 | | - BUILD_VERSION := $(DOCKER_TAG) |
7 | | -else |
8 | | - BUILD_VERSION=latest |
| 6 | +ifeq ($(strip $(RLSECURE_ENCODED_LICENSE)),) |
| 7 | + $(error mandatory RLSECURE_ENCODED_LICENSE not set!) |
9 | 8 | endif |
10 | 9 |
|
11 | | -VOLUMES := -v ./output:/output -v ./input:/input |
12 | | -USER_GROUP := $(shell id -u):$(shell id -u ) |
13 | | -COMMON_DOCKER := -i --rm -u $(USER_GROUP) --env-file=$(HOME)/.envfile_rl-scanner.docker |
14 | | - |
15 | | -# IMAGE_NAME := rlsecure/scanner:latest |
16 | | -IMAGE_BASE := reversinglabs/rl-scanner |
17 | | -IMAGE_NAME := $(IMAGE_BASE):$(BUILD_VERSION) |
18 | | - |
19 | | -ARTIFACT_OK := vim |
20 | | -ARTIFACT_ERR := eicarcom2.zip |
| 10 | +ifeq ($(strip $(RLSECURE_SITE_KEY)),) |
| 11 | + $(error mandatory RLSECURE_SITE_KEY not set!) |
| 12 | +endif |
21 | 13 |
|
| 14 | +IMAGE_NAME ?= reversinglabs/rl-scanner:test |
22 | 15 | LINE_LENGTH = 120 |
23 | 16 | PL_LINTERS = "eradicate,mccabe,pycodestyle,pyflakes,pylint" |
24 | 17 | PL_IGNORE = C0114,C0115,C0116 |
25 | 18 | SCRIPTS = scripts/ |
26 | 19 |
|
27 | | -IMAGE ?= reversinglabs/rl-scanner |
28 | | -TAG ?= latest |
29 | 20 |
|
30 | | -.PHONY: build clean |
| 21 | +.PHONY: build-without-cache build-with-cache push clean format pycheck test test.% |
31 | 22 |
|
32 | | -all: clean prep build tests |
| 23 | +all: clean prep build test |
33 | 24 |
|
34 | | -clean: |
35 | | - docker image prune -f |
36 | | - -docker image rm $(IMAGE_NAME) |
37 | | - rm -f eicarcom2.zip |
38 | | - rm -rf .mypy_cache */.mypy_cache |
| 25 | +prep: format pylama mypy |
| 26 | + |
| 27 | +build: build-with-cache |
| 28 | + |
| 29 | +build-without-cache: |
| 30 | + docker buildx build . -f Dockerfile.no_cache \ |
| 31 | + --no-cache \ |
| 32 | + -t $(IMAGE_NAME) |
39 | 33 |
|
40 | | -prep: format pycheck mypy |
41 | | - wget 'https://www.eicar.org/download/eicar-com-2-2/?wpdmdl=8848&refresh=65d33af627b351708342006' --output-document 'eicarcom2.zip' |
| 34 | +# --build-arg CACHE_PATH=/tmp/rl-secure.cache |
| 35 | +build-with-cache: |
| 36 | + docker buildx build . -f Dockerfile.cache \ |
| 37 | + --no-cache \ |
| 38 | + --secret id=rlsecure_license,env=RLSECURE_ENCODED_LICENSE \ |
| 39 | + --secret id=rlsecure_sitekey,env=RLSECURE_SITE_KEY \ |
| 40 | + -t $(IMAGE_NAME) |
42 | 41 |
|
43 | | -format: $(SCRIPTS) |
| 42 | +clean: |
| 43 | + -docker rmi $(IMAGE_NAME) |
| 44 | + rm -rf ./tests/*/report/ |
| 45 | + rm -rf ./tests/repro/store/ |
| 46 | + rm -rf ./tests/repro/report_base/ |
| 47 | + rm -rf ./tests/repro/report_repro_fail/ |
| 48 | + rm -rf ./tests/repro/report_repro_ok/ |
| 49 | + |
| 50 | +format: |
44 | 51 | black \ |
45 | 52 | --line-length $(LINE_LENGTH) \ |
46 | 53 | $(SCRIPTS)/* |
47 | 54 |
|
48 | | -pycheck: $(SCRIPTS) |
| 55 | +pylama: |
49 | 56 | pylama \ |
50 | 57 | --max-line-length $(LINE_LENGTH) \ |
51 | 58 | --linters $(PL_LINTERS) \ |
52 | 59 | --ignore $(PL_IGNORE) \ |
53 | 60 | $(SCRIPTS) |
54 | 61 |
|
55 | | -mypy: $(SCRIPTS) |
| 62 | +mypy: |
56 | 63 | mypy \ |
57 | 64 | --strict \ |
58 | 65 | --no-incremental \ |
59 | 66 | $(SCRIPTS) |
60 | 67 |
|
61 | 68 |
|
62 | | -# build a new docker image from the Dockerfile generated |
63 | | -build: |
64 | | - mkdir -p tmp |
65 | | - docker build -t $(IMAGE_NAME) -f Dockerfile . |
66 | | - docker image ls $(IMAGE_NAME) | tee ./tmp/image_ls.txt |
67 | | - docker image inspect $(IMAGE_NAME) --format '{{ .Config.Labels }}' |
68 | | - docker image inspect $(IMAGE_NAME) --format '{{ .RepoTags }}' |
69 | | - |
70 | | -tests: testFail test_ok test_err |
71 | | - |
72 | | -testFail: |
73 | | - # we know that specifying no arguments should print usage() and fail |
74 | | - -docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) # will fail but we will ignore that |
75 | | - # we know that specifying no arguments to rl-scan should print usage() and fail |
76 | | - -docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) rl-scan # will fail but we will ignore that |
77 | | - |
78 | | -test_ok: |
79 | | - rm -rf output input |
80 | | - mkdir -m 777 -p input output |
81 | | - cp /bin/$(ARTIFACT_OK) ./input/$(ARTIFACT_OK) |
82 | | - docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \ |
83 | | - rl-scan --package-path=/input/$(ARTIFACT_OK) --report-path=/output --report-format all |
84 | | - ls -laR input output >./tmp/list_in_out_ok.txt |
85 | | - cat output/report.rl.json | jq -r . >tmp/test_ok.json |
86 | | - |
87 | | -test_err: |
88 | | - rm -rf output input |
89 | | - mkdir -m 777 -p input output |
90 | | - curl -o $(ARTIFACT_ERR) -sS https://secure.eicar.org/$(ARTIFACT_ERR) |
91 | | - cp $(ARTIFACT_ERR) ./input/$(ARTIFACT_ERR) |
92 | | - # as we are now scanning a item that makes the scan fail (non zero exit code) we have to ignore the error in the makefile |
93 | | - -docker run $(COMMON_DOCKER) $(VOLUMES) $(IMAGE_NAME) \ |
94 | | - rl-scan --package-path=/input/$(ARTIFACT_ERR) --report-path=/output --report-format all |
95 | | - ls -laR input output >./tmp/list_in_out_err.txt |
96 | | - cat output/report.rl.json | jq -r . >tmp/test_err.json |
| 69 | +all-tests := $(addprefix test., $(notdir $(wildcard tests/*))) |
| 70 | + |
| 71 | +test.%: tests/%/run.sh |
| 72 | + cd $(dir $<) && ./run.sh "$(IMAGE_NAME)" |
97 | 73 |
|
| 74 | +test: $(all-tests) |
0 commit comments