Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache bincapz-samples repository to speed up subsequent tests #448

Merged
merged 4 commits into from
Sep 13, 2024

Conversation

egibs
Copy link
Member

@egibs egibs commented Sep 12, 2024

Closes: #445

Repeatedly cloning the bincapz-samples directory (which is >150MB) wastes a lot of time. This PR attempts to cache the output in out/ so that subsequent test runs do not need to re-clone the entire repository.

First run:

$ make test
mkdir -p out
git clone git@github.com:chainguard-dev/bincapz-samples.git out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7
Cloning into 'out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7'...
remote: Enumerating objects: 267, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 267 (delta 5), reused 35 (delta 2), pack-reused 219 (from 1)
Receiving objects: 100% (267/267), 157.86 MiB | 1.15 MiB/s, done.
Resolving deltas: 100% (22/22), done.
pushd out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7; git checkout bdcb8c2e9bf557a0abe3e2b0144f437d456299b7; popd
~/repos/chainguard-dev/bincapz/out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7 ~/repos/chainguard-dev/bincapz
Note: switching to 'bdcb8c2e9bf557a0abe3e2b0144f437d456299b7'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at bdcb8c2 Add samples for: Darkcracks, helmet-validate, noblox, aspdasdksa2 (#4)
~/repos/chainguard-dev/bincapz
rm -rf samples; cp -a out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7 samples/
cp -a test_data/. samples/
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
		tar -xJvf samples/linux/clean/$file -C samples/linux/clean; \
	done
x caddy
x chezmoi
x minio.x86_64
x mongosh
x neuvector-agent.aarch64
x opa
tar -xJvf samples/macOS/clean/bincapz.xz -C samples/macOS/clean
x bincapz
go test github.com/chainguard-dev/bincapz github.com/chainguard-dev/bincapz/out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7/does-nothing github.com/chainguard-dev/bincapz/pkg/action github.com/chainguard-dev/bincapz/pkg/bincapz github.com/chainguard-dev/bincapz/pkg/compile github.com/chainguard-dev/bincapz/pkg/profile github.com/chainguard-dev/bincapz/pkg/render github.com/chainguard-dev/bincapz/pkg/report github.com/chainguard-dev/bincapz/pkg/version github.com/chainguard-dev/bincapz/rules github.com/chainguard-dev/bincapz/samples github.com/chainguard-dev/bincapz/samples/does-nothing github.com/chainguard-dev/bincapz/third_party
?   	github.com/chainguard-dev/bincapz	[no test files]
?   	github.com/chainguard-dev/bincapz/out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7/does-nothing	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/bincapz	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/compile	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/render	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/version	[no test files]
?   	github.com/chainguard-dev/bincapz/rules	[no test files]
ok  	github.com/chainguard-dev/bincapz/pkg/action	(cached)
ok  	github.com/chainguard-dev/bincapz/pkg/profile	(cached)
ok  	github.com/chainguard-dev/bincapz/pkg/report	(cached)
?   	github.com/chainguard-dev/bincapz/samples/does-nothing	[no test files]
?   	github.com/chainguard-dev/bincapz/third_party	[no test files]
ok  	github.com/chainguard-dev/bincapz/samples	56.764s

Subsequent runs:

$ make test
rm -rf samples; cp -a out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7 samples/
cp -a test_data/. samples/
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
		tar -xJvf samples/linux/clean/$file -C samples/linux/clean; \
	done
x caddy
x chezmoi
x minio.x86_64
x mongosh
x neuvector-agent.aarch64
x opa
tar -xJvf samples/macOS/clean/bincapz.xz -C samples/macOS/clean
x bincapz
go test github.com/chainguard-dev/bincapz github.com/chainguard-dev/bincapz/out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7/does-nothing github.com/chainguard-dev/bincapz/pkg/action github.com/chainguard-dev/bincapz/pkg/bincapz github.com/chainguard-dev/bincapz/pkg/compile github.com/chainguard-dev/bincapz/pkg/profile github.com/chainguard-dev/bincapz/pkg/render github.com/chainguard-dev/bincapz/pkg/report github.com/chainguard-dev/bincapz/pkg/version github.com/chainguard-dev/bincapz/rules github.com/chainguard-dev/bincapz/samples github.com/chainguard-dev/bincapz/samples/does-nothing github.com/chainguard-dev/bincapz/third_party
?   	github.com/chainguard-dev/bincapz	[no test files]
?   	github.com/chainguard-dev/bincapz/out/samples-bdcb8c2e9bf557a0abe3e2b0144f437d456299b7/does-nothing	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/bincapz	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/compile	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/render	[no test files]
?   	github.com/chainguard-dev/bincapz/pkg/version	[no test files]
?   	github.com/chainguard-dev/bincapz/rules	[no test files]
ok  	github.com/chainguard-dev/bincapz/pkg/action	(cached)
ok  	github.com/chainguard-dev/bincapz/pkg/profile	(cached)
ok  	github.com/chainguard-dev/bincapz/pkg/report	(cached)
?   	github.com/chainguard-dev/bincapz/samples/does-nothing	[no test files]
?   	github.com/chainguard-dev/bincapz/third_party	[no test files]
ok  	github.com/chainguard-dev/bincapz/samples	55.816s

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs requested a review from tstromberg September 12, 2024 14:47
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated

update-samples: out/samples-$(SAMPLES_HASH)
rm -rf samples; cp -a out/samples-$(SAMPLES_HASH) samples/
cp -a test_data/. samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the test_data where it is? It seems weird to pollute the samples data this way. I'm OK if we leave this for a future PR though as it would involve changing tests around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about that and it's definitely messy as-is. I'll keep thinking on it.

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@egibs egibs marked this pull request as draft September 12, 2024 18:28
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@@ -50,11 +50,11 @@ jobs:

- name: Prepare samples
run: |
cp -a ${{ github.workspace }}/test_data/. ${{ github.workspace }}/samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run the makefile rule instead of duplicating this logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some hang up about that mentally but it may just be because I cloned the other repository separately and wasn't sure if our anonymous clone would work.

The make targets should work in CI as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 4ad123f (#448).

Makefile Outdated
mkdir -p out
git clone https://github.com/chainguard-dev/bincapz-samples.git out/samples-$(SAMPLES_HASH).tmp
git -C out/samples-$(SAMPLES_HASH).tmp checkout $(SAMPLES_HASH)
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this work to avoid hardcoding filenames?

find <path> -name "*.xz" -exec xz -d {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented a variant of this in 4ad123f (#448).

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs marked this pull request as ready for review September 12, 2024 20:30
@egibs egibs requested a review from tstromberg September 12, 2024 20:30
@@ -113,16 +126,7 @@ update-third-party:
.PHONY: refresh-sample-testdata out/bincapz
refresh-sample-testdata: clone-samples out/bincapz
cp ./test_data/refresh-testdata.sh samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: in a future PR, we can switch to running this script from the test_data directory.

@tstromberg
Copy link
Collaborator

merging so I can work on bincapz without wifi :)

@tstromberg tstromberg merged commit 9223b64 into chainguard-dev:main Sep 13, 2024
6 checks passed
@egibs egibs deleted the cache-samples branch September 22, 2024 19:31
egibs added a commit to egibs/malcontent that referenced this pull request Sep 25, 2024
…uard-dev#448)

* Cache bincapz-samples repository to speed up subsequent tests

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Update -> prepare

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Address PR comments; rework out/samples target

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Use Make targets in CI; simplify + clean up targets

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

---------

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache bincapz-samples checkout
2 participants