From 857aed0b94746487368981e5dd3d756fd44ce611 Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Mon, 24 Feb 2025 16:34:25 -0800 Subject: [PATCH 1/3] better layer contents caching, squash support now layer contents display supports squashfs mediatypes. layer contents are cached less dumb-ly now. we get the full file list once and just grep it when the filter changes, instead of having to do all the file list IO on every filter change. Signed-off-by: Michael McCracken --- ociutils.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ociutils.go b/ociutils.go index a13e71f..be19677 100644 --- a/ociutils.go +++ b/ociutils.go @@ -138,17 +138,26 @@ func (lr layerRef) summary(filter string) string { return cachedSummary } - filterArg := "" - if filter != "" { - filterArg = " | grep " + filter + fileListFilename := fmt.Sprintf("/tmp/%s-filelist", lr.hash) + if _, err := os.Stat(fileListFilename); os.IsNotExist(err) { + cmdstr := "tar tzvf " + lr.blobfilepath + if strings.Contains(lr.mediaType, "squashfs") { + cmdstr = "unsquashfs -llc " + lr.blobfilepath + } + cmd := exec.Command("sh", "-c", cmdstr+" > "+fileListFilename) + err := cmd.Run() + if err != nil { + log.Printf("error: %v", err) + return fmt.Sprintf(" error: %v", err) + } } - cmdstr := "tar tzvf " + lr.blobfilepath + filterArg - if strings.Contains(lr.mediaType, "squashfs") { - cmdstr = "echo TODO: gunzip -c " + lr.blobfilepath + " |unsquashfs -llc " - //TODO: can't unsquash via pipe, need to gunzip to tempfile and delete + filterArg := "cat " + if filter != "" { + filterArg = " grep " + filter } - cmd := exec.Command("sh", "-c", cmdstr) + cmd := exec.Command("sh", "-c", filterArg+" "+fileListFilename) + var out strings.Builder var stderr strings.Builder cmd.Stdout = &out @@ -157,7 +166,8 @@ func (lr layerRef) summary(filter string) string { if err != nil { log.Printf("error: %v", err) } - summaryString := fmt.Sprintf("%q\n%q\n%s\n%s", lr.displayString, cmdstr, out.String(), stderr.String()) + + summaryString := fmt.Sprintf("file listing of blob %q (%s)\n\n%s\n%s", lr.displayString, lr.mediaType, out.String(), stderr.String()) LayerSummaryCache[layerfilterkey] = summaryString return summaryString } From 96ede3a506566230567d2acf28bc61272fec4f0a Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Fri, 28 Feb 2025 12:02:18 -0800 Subject: [PATCH 2/3] build: bump github artifact plugin version to v4 v3 fails Signed-off-by: Michael McCracken --- .github/workflows/makefile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index f23c9d0..cafffd5 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -14,7 +14,7 @@ jobs: - name: Build Static run: make ociv - name: upload binary - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ociv path: ociv From 769c3f1ffad6ef6f722ec43ab8a6dce44e780fb5 Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Mon, 3 Mar 2025 16:57:59 -0800 Subject: [PATCH 3/3] dbg Signed-off-by: Michael McCracken --- .github/workflows/makefile.yml | 6 ------ Makefile | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index cafffd5..f33efb4 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -18,9 +18,3 @@ jobs: with: name: ociv path: ociv - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Lint Go Code - run: make lint diff --git a/Makefile b/Makefile index a7b78ee..fc04ed1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ GOLINTER_VERSION := v1.54.2 GOLINTER := $(TOOLSDIR)/bin/golangci-lint -ociv: *.go lint +ociv: *.go + go env CGO_ENABLED=0 go build ${LDFLAGS} ${GOTAGS} -o ociv ./... $(GOLINTER):