m/pkgs/localregistry: make runfile aware
Resolving paths from metropolis/... doesn't seem to work in some tests
(noticed while reworking E2E test package layout, where the test target
isn't in the same package as the localregistry_manifest target).
Change-Id: Id7d9283b9675cbab56ecdb83df6a4b0f5578e5f6
Reviewed-on: https://review.monogon.dev/c/monogon/+/2991
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/pkg/localregistry/BUILD.bazel b/metropolis/pkg/localregistry/BUILD.bazel
index 4281ac1..ae8c384 100644
--- a/metropolis/pkg/localregistry/BUILD.bazel
+++ b/metropolis/pkg/localregistry/BUILD.bazel
@@ -13,6 +13,7 @@
"@com_github_docker_distribution//manifest/schema2",
"@com_github_docker_distribution//reference",
"@com_github_opencontainers_go_digest//:go-digest",
+ "@io_bazel_rules_go//go/runfiles:go_default_library",
"@org_golang_google_protobuf//encoding/prototext",
],
)
diff --git a/metropolis/pkg/localregistry/localregistry.go b/metropolis/pkg/localregistry/localregistry.go
index 885259b..aaf0d99 100644
--- a/metropolis/pkg/localregistry/localregistry.go
+++ b/metropolis/pkg/localregistry/localregistry.go
@@ -14,6 +14,7 @@
"regexp"
"strconv"
+ "github.com/bazelbuild/rules_go/go/runfiles"
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist"
"github.com/docker/distribution/manifest/ocischema"
@@ -37,7 +38,10 @@
}
func manifestDescriptorFromBazel(image *spec.Image) (manifestlist.ManifestDescriptor, error) {
- indexPath := filepath.Join(image.Path, "index.json")
+ indexPath, err := runfiles.Rlocation(filepath.Join("_main", image.Path, "index.json"))
+ if err != nil {
+ return manifestlist.ManifestDescriptor{}, fmt.Errorf("while locating manifest list file: %w", err)
+ }
manifestListRaw, err := os.ReadFile(indexPath)
if err != nil {
@@ -57,7 +61,10 @@
}
func manifestFromBazel(s *Server, image *spec.Image, md manifestlist.ManifestDescriptor) (ocischema.Manifest, error) {
- manifestPath := filepath.Join(image.Path, "blobs", md.Digest.Algorithm().String(), md.Digest.Hex())
+ manifestPath, err := runfiles.Rlocation(filepath.Join("_main", image.Path, "blobs", md.Digest.Algorithm().String(), md.Digest.Hex()))
+ if err != nil {
+ return ocischema.Manifest{}, fmt.Errorf("while locating manifest file: %w", err)
+ }
manifestRaw, err := os.ReadFile(manifestPath)
if err != nil {
return ocischema.Manifest{}, fmt.Errorf("while opening manifest file: %w", err)