github.com/anchore/syft@v1.38.2/test/install/Makefile (about) 1 NAME=syft 2 3 FINGERPRINT_FILE := cache.fingerprint 4 5 # for local testing (not testing within containers) use the binny-managed version of cosign. 6 # this also means that the user does not need to install cosign on their system to run tests. 7 COSIGN_BINARY=../../.tool/cosign 8 9 IMAGE_NAME=$(NAME)-install.sh-env 10 UBUNTU_IMAGE=$(IMAGE_NAME):ubuntu-20.04 11 ALPINE_IMAGE=$(IMAGE_NAME):alpine-3.6 12 BUSYBOX_IMAGE=$(IMAGE_NAME):busybox-1.36 13 14 ENVS=./environments 15 DOCKER_RUN=docker run --rm -t -w /project/test/install -v $(shell pwd)/../../:/project 16 UNIT=make unit-run 17 18 # acceptance testing is running the current install.sh against the latest release. Note: this could be a problem down 19 # the line if there are breaking changes made that don't align with the latest release (but will be OK with the next 20 # release). This tests both installing with signature verification and without. 21 ACCEPTANCE_CMD=sh -c '../../install.sh -v -b /usr/local/bin && syft version && rm /usr/local/bin/syft && ../../install.sh -b /usr/local/bin && syft version' 22 # we also want to test against a previous release to ensure that install.sh defers execution to a former install.sh 23 PREVIOUS_RELEASE=v0.33.0 24 ACCEPTANCE_PREVIOUS_RELEASE_CMD=sh -c "../../install.sh -b /usr/local/bin $(PREVIOUS_RELEASE) && syft version" 25 26 27 define title 28 @printf '\n≡≡≡[ $(1) ]≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡\n' 29 endef 30 31 .PHONY: test 32 test: unit acceptance 33 34 .PHONY: ci-test-mac 35 ci-test-mac: unit-run acceptance-local 36 37 # note: do not add acceptance-local to this list 38 .PHONY: acceptance 39 acceptance: acceptance-ubuntu-20.04 acceptance-alpine-3.6 acceptance-busybox-1.36 40 41 .PHONY: unit 42 unit: unit-ubuntu-20.04 43 44 .PHONY: unit-local 45 unit-local: 46 $(call title,unit tests) 47 @for f in $(shell ls *_test.sh); do echo "Running unit test suite '$${f}'"; bash -c "COSIGN_BINARY=$(COSIGN_BINARY) ./$${f}" || exit 1; done 48 49 .PHONY: unit-run 50 unit-run: 51 $(call title,unit tests) 52 @for f in $(shell ls *_test.sh); do echo "Running unit test suite '$${f}'"; bash $${f} || exit 1; done 53 54 .PHONY: acceptance-local 55 acceptance-local: acceptance-current-release-local acceptance-previous-release-local 56 57 .PHONY: acceptance-current-release-local 58 acceptance-current-release-local: 59 $(ACCEPTANCE_CMD) 60 61 .PHONY: acceptance-previous-release-local 62 acceptance-previous-release-local: 63 $(ACCEPTANCE_PREVIOUS_RELEASE_CMD) 64 syft version | grep $(shell echo $(PREVIOUS_RELEASE)| tr -d "v") 65 66 .PHONY: save 67 save: ubuntu-20.04 alpine-3.6 busybox-1.36 68 @mkdir cache || true 69 docker image save -o cache/ubuntu-env.tar $(UBUNTU_IMAGE) 70 docker image save -o cache/alpine-env.tar $(ALPINE_IMAGE) 71 docker image save -o cache/busybox-env.tar $(BUSYBOX_IMAGE) 72 73 .PHONY: load 74 load: 75 docker image load -i cache/ubuntu-env.tar 76 docker image load -i cache/alpine-env.tar 77 docker image load -i cache/busybox-env.tar 78 79 ## UBUNTU ####################################################### 80 81 .PHONY: acceptance-ubuntu-20.04 82 acceptance-ubuntu-20.04: ubuntu-20.04 83 $(call title,ubuntu:20.04 - acceptance) 84 $(DOCKER_RUN) $(UBUNTU_IMAGE) \ 85 $(ACCEPTANCE_CMD) 86 87 .PHONY: unit-ubuntu-20.04 88 unit-ubuntu-20.04: ubuntu-20.04 89 $(call title,ubuntu:20.04 - unit) 90 $(DOCKER_RUN) $(UBUNTU_IMAGE) \ 91 $(UNIT) 92 93 .PHONY: ubuntu-20.04 94 ubuntu-20.04: 95 $(call title,ubuntu:20.04 - build environment) 96 docker build -t $(UBUNTU_IMAGE) -f $(ENVS)/Dockerfile-ubuntu-20.04 . 97 98 ## ALPINE ####################################################### 99 100 # note: unit tests cannot be run with sh (alpine doesn't have bash by default) 101 102 .PHONY: acceptance-alpine-3.6 103 acceptance-alpine-3.6: alpine-3.6 104 $(call title,alpine:3.6 - acceptance) 105 $(DOCKER_RUN) $(ALPINE_IMAGE) \ 106 $(ACCEPTANCE_CMD) 107 108 .PHONY: alpine-3.6 109 alpine-3.6: 110 $(call title,alpine:3.6 - build environment) 111 docker build -t $(ALPINE_IMAGE) -f $(ENVS)/Dockerfile-alpine-3.6 . 112 113 ## BUSYBOX ####################################################### 114 115 # note: unit tests cannot be run with sh (busybox doesn't have bash by default) 116 117 # note: busybox by default will not have cacerts, so you will get TLS warnings (we want to test under these conditions) 118 119 .PHONY: acceptance-busybox-1.36 120 acceptance-busybox-1.36: busybox-1.36 121 $(call title,busybox-1.36 - acceptance) 122 $(DOCKER_RUN) $(BUSYBOX_IMAGE) \ 123 $(ACCEPTANCE_CMD) 124 @echo "\n*** test note: you should see syft spit out a 'x509: certificate signed by unknown authority' error --this is expected ***" 125 126 .PHONY: busybox-1.36 127 busybox-1.36: 128 $(call title,busybox-1.36 - build environment) 129 docker build -t $(BUSYBOX_IMAGE) -f $(ENVS)/Dockerfile-busybox-1.36 . 130 131 ## For CI ######################################################## 132 133 # requirement 3: we always need to recalculate the fingerprint based on source regardless of any existing fingerprint 134 .PHONY: $(FINGERPRINT_FILE) 135 $(FINGERPRINT_FILE): 136 @find ./environments/* -type f -exec sha256sum {} \; | sort -k2 > $(FINGERPRINT_FILE) 137 @#cat $(FINGERPRINT_FILE) | sha256sum | awk '{print $$1}'