Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix iidfile content #975

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
build: return remote digest for pushed image with docker driver
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 27, 2022
commit 002c7d098631a868c8725d1b72c012eff93b339d
38 changes: 35 additions & 3 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
respMu.Lock()
resp[k] = &client.SolveResponse{
ExporterResponse: map[string]string{
"containerimage.digest": desc.Digest.String(),
exptypes.ExporterImageDigestKey: desc.Digest.String(),
},
}
respMu.Unlock()
Expand Down Expand Up @@ -918,7 +918,6 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
if err != nil {
return err
}
res[i] = rr

d := drivers[dp.driverIndex].Driver
if d.IsMobyDriver() {
Expand All @@ -930,17 +929,26 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
return errors.Errorf("tag is needed when pushing to registry")
}
pw := progress.ResetTime(pw)
for _, name := range strings.Split(pushNames, ",") {
pushList := strings.Split(pushNames, ",")
for _, name := range pushList {
if err := progress.Wrap(fmt.Sprintf("pushing %s with docker", name), pw.Write, func(l progress.SubLogger) error {
return pushWithMoby(ctx, d, name, l)
}); err != nil {
return err
}
}
remoteDigest, errp := remoteDigestWithMoby(ctx, d, pushList[0])
if errp == nil && remoteDigest != "" {
rr.ExporterResponse[exptypes.ExporterImageDigestKey] = remoteDigest
} else if errp != nil {
return err
}
}
}
}
}

res[i] = rr
return nil
})

Expand Down Expand Up @@ -1038,9 +1046,33 @@ func pushWithMoby(ctx context.Context, d driver.Driver, name string, l progress.
parsedError = jm.Error
}
}

return nil
}

func remoteDigestWithMoby(ctx context.Context, d driver.Driver, name string) (string, error) {
api := d.Config().DockerAPI
if api == nil {
return "", errors.Errorf("invalid empty Docker API reference") // should never happen
}
creds, err := imagetools.RegistryAuthForRef(name, d.Config().Auth)
if err != nil {
return "", err
}
image, _, err := api.ImageInspectWithRaw(ctx, name)
if err != nil {
return "", err
}
if len(image.RepoDigests) == 0 {
return "", nil
}
remoteImage, err := api.DistributionInspect(ctx, name, creds)
if err != nil {
return "", err
}
return remoteImage.Descriptor.Digest.String(), nil
}

func createTempDockerfile(r io.Reader) (string, error) {
dir, err := ioutil.TempDir("", "dockerfile")
if err != nil {
Expand Down