Slim down docker cache size (#3190)

* slim down docker cache size

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* remove old centos images

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* troubleshoot test failure

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix wget version ref

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor caching mechanisms

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add cache cleanup steps

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* simplify deleting cache

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix first clone issue

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add tool dep

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2024-09-09 11:15:13 -04:00
committed by GitHub
parent deabd4115a
commit 0a3f513f92
75 changed files with 1302 additions and 382 deletions
+1
View File
@@ -0,0 +1 @@
results
+1 -1
View File
@@ -33,7 +33,7 @@ func TestValidCycloneDX(t *testing.T) {
{
name: "validate cyclonedx output",
subcommand: "scan",
args: []string{"-o", "cyclonedx-json"},
args: []string{"-o", "cyclonedx-json", "-o", "cyclonedx-json=results/sbom.cdx.json"},
fixture: imageFixture,
assertions: []traitAssertion{
assertSuccessfulReturnCode,
+44 -6
View File
@@ -143,8 +143,22 @@ func TestPackagesCmdFlags(t *testing.T) {
name: "squashed-scope-flag-hidden-packages",
args: []string{"scan", "-o", "json", "-s", "squashed", hiddenPackagesImage},
assertions: []traitAssertion{
assertPackageCount(162),
assertNotInOutput("vsftpd"), // hidden package
assertPackageCount(14),
// package 1: alpine-baselayout-data@3.6.5-r0 (apk)
// package 2: alpine-baselayout@3.6.5-r0 (apk)
// package 3: alpine-keys@2.4-r1 (apk)
// package 4: apk-tools@2.14.4-r0 (apk)
// package 5: busybox-binsh@1.36.1-r29 (apk)
// package 6: busybox@1.36.1-r29 (apk)
// package 7: ca-certificates-bundle@20240705-r0 (apk)
// package 8: libcrypto3@3.3.1-r3 (apk)
// package 9: libssl3@3.3.1-r3 (apk)
// package 10: musl-utils@1.2.5-r0 (apk)
// package 11: musl@1.2.5-r0 (apk)
// package 12: scanelf@1.3.7-r2 (apk)
// package 13: ssl_client@1.36.1-r29 (apk)
// package 14: zlib@1.3.1-r1 (apk)
assertNotInOutput(`"name":"curl"`), // hidden package
assertSuccessfulReturnCode,
},
},
@@ -152,9 +166,33 @@ func TestPackagesCmdFlags(t *testing.T) {
name: "all-layers-scope-flag",
args: []string{"scan", "-o", "json", "-s", "all-layers", hiddenPackagesImage},
assertions: []traitAssertion{
assertPackageCount(163), // packages are now deduplicated for this case
assertPackageCount(24),
// package 1: alpine-baselayout-data@3.6.5-r0 (apk)
// package 2: alpine-baselayout@3.6.5-r0 (apk)
// package 3: alpine-keys@2.4-r1 (apk)
// package 4: apk-tools@2.14.4-r0 (apk)
// package 5: brotli-libs@1.1.0-r2 (apk)
// package 6: busybox-binsh@1.36.1-r29 (apk)
// package 7: busybox@1.36.1-r29 (apk)
// package 8: c-ares@1.28.1-r0 (apk)
// package 9: ca-certificates-bundle@20240705-r0 (apk)
// package 10: ca-certificates@20240705-r0 (apk)
// package 11: curl@8.9.1-r1 (apk)
// package 12: libcrypto3@3.3.1-r3 (apk)
// package 13: libcurl@8.9.1-r1 (apk)
// package 14: libidn2@2.3.7-r0 (apk)
// package 15: libpsl@0.21.5-r1 (apk)
// package 16: libssl3@3.3.1-r3 (apk)
// package 17: libunistring@1.2-r0 (apk)
// package 18: musl-utils@1.2.5-r0 (apk)
// package 19: musl@1.2.5-r0 (apk)
// package 20: nghttp2-libs@1.62.1-r0 (apk)
// package 21: scanelf@1.3.7-r2 (apk)
// package 22: ssl_client@1.36.1-r29 (apk)
// package 23: zlib@1.3.1-r1 (apk)
// package 24: zstd-libs@1.5.6-r0 (apk)
assertInOutput("all-layers"),
assertInOutput("vsftpd"), // hidden package
assertInOutput(`"name":"curl"`), // hidden package
assertSuccessfulReturnCode,
},
},
@@ -165,9 +203,9 @@ func TestPackagesCmdFlags(t *testing.T) {
"SYFT_SCOPE": "all-layers",
},
assertions: []traitAssertion{
assertPackageCount(163), // packages are now deduplicated for this case
assertPackageCount(24), // packages are now deduplicated for this case
assertInOutput("all-layers"),
assertInOutput("vsftpd"), // hidden package
assertInOutput(`"name":"curl"`), // hidden package
assertSuccessfulReturnCode,
},
},
+21 -5
View File
@@ -1,6 +1,22 @@
# change these if you want CI to not use previous stored cache
CLI_CACHE_BUSTER := "e5cdfd8"
FINGERPRINT_FILE=cache.fingerprint
.DEFAULT_GOAL := fixtures
# requirement 1: 'fixtures' goal to generate any and all test fixtures
fixtures:
@echo "nothing to do"
# requirement 2: 'fingerprint' goal to determine if the fixture input that indicates any existing cache should be busted
fingerprint: $(FINGERPRINT_FILE)
# requirement 3: we always need to recalculate the fingerprint based on source regardless of any existing fingerprint
.PHONY: $(FINGERPRINT_FILE)
$(FINGERPRINT_FILE):
@find image-* -type f -exec sha256sum {} \; | sort -k2 > $(FINGERPRINT_FILE)
@#cat $(FINGERPRINT_FILE) | sha256sum | awk '{print $$1}'
# requirement 4: 'clean' goal to remove all generated test fixtures
.PHONY: clean
clean:
rm -f $(FINGERPRINT_FILE)
.PHONY: cache.fingerprint
cache.fingerprint:
find image-* -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum | tee cache.fingerprint && echo "$(CLI_CACHE_BUSTER)" >> cache.fingerprint
@@ -1,4 +1,4 @@
FROM centos:7.9.2009@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f
# all-layers scope should pickup on vsftpd
RUN yum install -y vsftpd
RUN yum remove -y vsftpd
FROM --platform=linux/amd64 alpine:3.20.2@sha256:eddacbc7e24bf8799a4ed3cdcfa50d4b88a323695ad80f317b6629883b2c2a78
RUN apk add --no-cache curl
RUN apk del curl
+7 -6
View File
@@ -1,5 +1,7 @@
NAME=syft
FINGERPRINT_FILE := cache.fingerprint
# for local testing (not testing within containers) use the binny-managed version of cosign.
# this also means that the user does not need to install cosign on their system to run tests.
COSIGN_BINARY=../../.tool/cosign
@@ -21,8 +23,6 @@ ACCEPTANCE_CMD=sh -c '../../install.sh -v -b /usr/local/bin && syft version && r
PREVIOUS_RELEASE=v0.33.0
ACCEPTANCE_PREVIOUS_RELEASE_CMD=sh -c "../../install.sh -b /usr/local/bin $(PREVIOUS_RELEASE) && syft version"
# CI cache busting values; change these if you want CI to not use previous stored cache
INSTALL_TEST_CACHE_BUSTER=894d8ca
define title
@printf '\n≡≡≡[ $(1) ]≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡\n'
@@ -130,7 +130,8 @@ busybox-1.36:
## For CI ########################################################
.PHONY: cache.fingerprint
cache.fingerprint:
$(call title,Install test fixture fingerprint)
@find ./environments/* -type f -exec md5sum {} + | awk '{print $1}' | sort | tee /dev/stderr | md5sum | tee cache.fingerprint && echo "$(INSTALL_TEST_CACHE_BUSTER)" >> cache.fingerprint
# requirement 3: we always need to recalculate the fingerprint based on source regardless of any existing fingerprint
.PHONY: $(FINGERPRINT_FILE)
$(FINGERPRINT_FILE):
@find ./environments/* -type f -exec sha256sum {} \; | sort -k2 > $(FINGERPRINT_FILE)
@#cat $(FINGERPRINT_FILE) | sha256sum | awk '{print $$1}'