From 5837426c7eeddeddfe8758ffff947e77da8501d2 Mon Sep 17 00:00:00 2001 From: Christian Weichel Date: Fri, 3 Dec 2021 08:11:21 +0000 Subject: [PATCH] [image-builder] Pull digested base refs correctly --- .../pkg/orchestrator/orchestrator.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/image-builder-mk3/pkg/orchestrator/orchestrator.go b/components/image-builder-mk3/pkg/orchestrator/orchestrator.go index 0563986345aaeb..e753d3aae05121 100644 --- a/components/image-builder-mk3/pkg/orchestrator/orchestrator.go +++ b/components/image-builder-mk3/pkg/orchestrator/orchestrator.go @@ -17,6 +17,7 @@ import ( "sync" "time" + "github.com/docker/distribution/reference" "github.com/google/uuid" "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" @@ -306,6 +307,17 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil return false } + pbaseref, err := reference.Parse(baseref) + if err != nil { + return xerrors.Errorf("cannot parse baseref: %v", err) + } + bobBaseref := "localhost:8080/base" + if r, ok := pbaseref.(reference.Digested); ok { + bobBaseref += "@" + r.Digest().String() + } else { + bobBaseref += ":latest" + } + var swr *wsmanapi.StartWorkspaceResponse err = retry(ctx, func(ctx context.Context) (err error) { swr, err = o.wsman.StartWorkspace(ctx, &wsmanapi.StartWorkspaceRequest{ @@ -333,7 +345,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil WorkspaceLocation: contextPath, Envvars: []*wsmanapi.EnvironmentVariable{ {Name: "BOB_TARGET_REF", Value: "localhost:8080/target:latest"}, - {Name: "BOB_BASE_REF", Value: "localhost:8080/base:latest"}, + {Name: "BOB_BASE_REF", Value: bobBaseref}, {Name: "BOB_BUILD_BASE", Value: buildBase}, {Name: "BOB_DOCKERFILE_PATH", Value: dockerfilePath}, {Name: "BOB_CONTEXT_DIR", Value: contextPath},