From 6818659c1466d81abb8fdaf5d90757ebbde27bee Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Fri, 16 Apr 2021 16:18:33 -0700 Subject: [PATCH 1/2] op: push-container stores metadata on fs, under /dagger/ Signed-off-by: Sam Alba --- dagger/pipeline.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dagger/pipeline.go b/dagger/pipeline.go index c8f76b81..2778be08 100644 --- a/dagger/pipeline.go +++ b/dagger/pipeline.go @@ -627,7 +627,7 @@ func (p *Pipeline) PushContainer(ctx context.Context, op *compiler.Value, st llb // Add the default tag "latest" to a reference if it only has a repo name. ref = reference.TagNameOnly(ref) - _, err = p.s.Export(ctx, p.State(), &p.image, bk.ExportEntry{ + resp, err := p.s.Export(ctx, p.State(), &p.image, bk.ExportEntry{ Type: bk.ExporterImage, Attrs: map[string]string{ "name": ref.String(), @@ -635,6 +635,29 @@ func (p *Pipeline) PushContainer(ctx context.Context, op *compiler.Value, st llb }, }) + if err != nil { + return st, err + } + + if digest, ok := resp.ExporterResponse["containerimage.digest"]; ok { + imageRef := fmt.Sprintf( + "%s@%s", + resp.ExporterResponse["image.name"], + digest, + ) + + return st.File( + llb.Mkdir("/dagger", fs.FileMode(0755)), + llb.WithCustomName(p.vertexNamef("Mkdir /dagger")), + ).File( + llb.Mkfile("/dagger/image_digest", fs.FileMode(0644), []byte(digest)), + llb.WithCustomName(p.vertexNamef("Storing image digest to /dagger/image_digest")), + ).File( + llb.Mkfile("/dagger/image_ref", fs.FileMode(0644), []byte(imageRef)), + llb.WithCustomName(p.vertexNamef("Storing image ref to /dagger/image_ref")), + ), nil + } + return st, err } From 7d76a87ae23c7323f3144cd3287e1a914cda16d1 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Fri, 16 Apr 2021 16:20:27 -0700 Subject: [PATCH 2/2] examples/jamstack: implemented image_ref Signed-off-by: Sam Alba --- examples/jamstack/ecr_image.cue | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/jamstack/ecr_image.cue b/examples/jamstack/ecr_image.cue index 20963737..01ce4cba 100644 --- a/examples/jamstack/ecr_image.cue +++ b/examples/jamstack/ecr_image.cue @@ -25,21 +25,26 @@ import ( target: pushTarget } - push: #up: [ - // Build the docker image - op.#DockerBuild & { - context: source - if dockerfilePath != _|_ { - "dockerfilePath": dockerfilePath - } - buildArg: buildArgs - }, - // Push the image to the registry - op.#PushContainer & { - ref: pushTarget - }, - ] + ref: { + string - // FIXME: ref does not include the sha256: https://github.com/dagger/dagger/issues/303 - ref: pushTarget + #up: [ + // Build the docker image + op.#DockerBuild & { + context: source + if dockerfilePath != _|_ { + "dockerfilePath": dockerfilePath + } + buildArg: buildArgs + }, + // Push the image to the registry + op.#PushContainer & { + ref: pushTarget + }, + op.#Export & { + source: "/dagger/image_ref" + format: "string" + }, + ] + } }