github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/test/install/Makefile (about)

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