mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
build: set remote digest when pushed with docker driver
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
9fcea76dea
commit
19ff7cdadc
@ -937,13 +937,27 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
return errors.Errorf("tag is needed when pushing to registry")
|
return errors.Errorf("tag is needed when pushing to registry")
|
||||||
}
|
}
|
||||||
pw := progress.ResetTime(pw)
|
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 {
|
if err := progress.Wrap(fmt.Sprintf("pushing %s with docker", name), pw.Write, func(l progress.SubLogger) error {
|
||||||
return pushWithMoby(ctx, d, name, l)
|
return pushWithMoby(ctx, d, name, l)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
remoteDigest, err := remoteDigestWithMoby(ctx, d, pushList[0])
|
||||||
|
if err == nil && remoteDigest != "" {
|
||||||
|
// old daemons might not have containerimage.config.digest set
|
||||||
|
// in response so use containerimage.digest value for it if available
|
||||||
|
if _, ok := rr.ExporterResponse[exptypes.ExporterImageConfigDigestKey]; !ok {
|
||||||
|
if v, ok := rr.ExporterResponse[exptypes.ExporterImageDigestKey]; ok {
|
||||||
|
rr.ExporterResponse[exptypes.ExporterImageConfigDigestKey] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rr.ExporterResponse[exptypes.ExporterImageDigestKey] = remoteDigest
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1048,6 +1062,29 @@ func pushWithMoby(ctx context.Context, d driver.Driver, name string, l progress.
|
|||||||
return nil
|
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) {
|
func createTempDockerfile(r io.Reader) (string, error) {
|
||||||
dir, err := ioutil.TempDir("", "dockerfile")
|
dir, err := ioutil.TempDir("", "dockerfile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user