op.#SaveImage: export the image ID

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-10-12 15:37:01 -07:00
parent 5a1d4bff62
commit 50d55a8885
3 changed files with 7 additions and 30 deletions

View File

@ -57,8 +57,7 @@ Load a docker image into a docker engine
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*ref* | `string` |Image ref |
|*digest* | `string` |Image digest |
|*id* | `string` |Image ID |
## docker.#Pull

View File

@ -914,22 +914,13 @@ func (p *Pipeline) SaveImage(ctx context.Context, op *compiler.Value, st llb.Sta
return st, err
}
if digest, ok := resp.ExporterResponse["containerimage.digest"]; ok {
imageRef := fmt.Sprintf(
"%s@%s",
resp.ExporterResponse["image.name"],
digest,
)
if id, ok := resp.ExporterResponse["containerimage.config.digest"]; ok {
st = 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")),
llb.Mkfile("/dagger/image_id", fs.FileMode(0644), []byte(id)),
llb.WithCustomName(p.vertexNamef("Storing image id to /dagger/image_id")),
)
}

View File

@ -155,28 +155,15 @@ import (
command: "docker load -i /src/image.tar"
}
// Image ref
ref: {
// Image ID
id: {
string
#up: [
op.#Load & {from: save},
op.#Export & {
source: "/dagger/image_ref"
},
]
} & dagger.#Output
// Image digest
digest: {
string
#up: [
op.#Load & {from: save},
op.#Export & {
source: "/dagger/image_digest"
source: "/dagger/image_id"
},
]
} & dagger.#Output