Install skopeo during bootstrap (#1260)

The "make integration" target assumes that skopeo will be available on
PATH, but this wasn't documented. Install it during bootstrap when other
utilities are installed. (See ./test/integration/utils_test.go:50).
Include a sample skopeo policy.json, otherwise skopeo will look for a
missing policy doc a /etc/containers/policy.json and exit with an error.
The sample policy document matches the one included by default with
"brew install skopeo".

Signed-off-by: Will Murphy <will.murphy@anchore.com>
Co-authored-by: Will Murphy <will.murphy@anchore.com>
This commit is contained in:
William Murphy 2023-04-28 10:10:29 -04:00 committed by GitHub
parent aa52d673d0
commit f0a09c0b9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -18,6 +18,7 @@ GORELEASER_VERSION := v1.17.2
YAJSV_VERSION := v1.4.1
QUILL_VERSION := v0.2.0
GLOW_VERSION := v1.5.0
SKOPEO_VERSION := v1.12.0
# Formatting variables ############################
BOLD := $(shell tput -T linux bold)
@ -117,6 +118,7 @@ bootstrap-tools: $(TEMP_DIR)
GOBIN="$(realpath $(TEMP_DIR))" go install github.com/rinchsan/gosimports/cmd/gosimports@$(GOSIMPORTS_VERSION)
GOBIN="$(realpath $(TEMP_DIR))" go install github.com/neilpa/yajsv@$(YAJSV_VERSION)
GOBIN="$(realpath $(TEMP_DIR))" go install github.com/charmbracelet/glow@$(GLOW_VERSION)
GOBIN="$(realpath $(TEMP_DIR))" CGO_ENABLED=0 GO_DYN_FLAGS="" go install -tags "containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@$(SKOPEO_VERSION)
.PHONY: bootstrap-go
bootstrap-go:

View file

@ -0,0 +1,16 @@
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports": {
"docker-daemon": {
"": [
{
"type": "insecureAcceptAnything"
}
]
}
}
}

View file

@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/scylladb/go-set/strset"
@ -46,8 +47,15 @@ func PullThroughImageCache(t testing.TB, imageName string) string {
func saveImage(t testing.TB, imageName string, destPath string) {
sourceImage := fmt.Sprintf("docker://docker.io/%s", imageName)
destinationString := fmt.Sprintf("docker-archive:%s", destPath)
skopeoPath := filepath.Join(repoRoot(t), ".tmp", "skopeo")
policyPath := filepath.Join(repoRoot(t), "test", "integration", "test-fixtures", "skopeo-policy.json")
cmd := exec.Command("skopeo", "copy", "--override-os", "linux", sourceImage, destinationString)
skopeoCommand := []string{
"--policy", policyPath,
"copy", "--override-os", "linux", sourceImage, destinationString,
}
cmd := exec.Command(skopeoPath, skopeoCommand...)
out, err := cmd.Output()
if err != nil {
@ -101,3 +109,16 @@ func getMatchSet(matches match.Matches) *strset.Set {
}
return s
}
func repoRoot(tb testing.TB) string {
tb.Helper()
root, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
tb.Fatalf("unable to find repo root dir: %+v", err)
}
absRepoRoot, err := filepath.Abs(strings.TrimSpace(string(root)))
if err != nil {
tb.Fatal("unable to get abs path to repo root:", err)
}
return absRepoRoot
}