Merge pull request #3824 from giggsoff/fix-push

Fix bug: when request to build multiple arches, if one already found, it skips the others
This commit is contained in:
Avi Deitcher 2022-09-13 13:21:48 +03:00 committed by GitHub
commit 3008215556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,21 +229,15 @@ func (p Pkg) Build(bos ...BuildOpt) error {
return fmt.Errorf("contexts not supported, check docker version: %v", err) return fmt.Errorf("contexts not supported, check docker version: %v", err)
} }
skipBuild := bo.skipBuild var platformsToBuild []imagespec.Platform
if !bo.force { if bo.force {
notFound := false platformsToBuild = bo.platforms
} else if !bo.skipBuild {
fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", ref) fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", ref)
for _, platform := range bo.platforms { for _, platform := range bo.platforms {
if _, err := c.ImagePull(&ref, "", platform.Architecture, false); err == nil { if _, err := c.ImagePull(&ref, "", platform.Architecture, false); err == nil {
fmt.Fprintf(writer, "%s found or pulled\n", ref) fmt.Fprintf(writer, "%s found or pulled\n", ref)
skipBuild = true
} else {
fmt.Fprintf(writer, "%s not found: %s\n", ref, err)
notFound = true
}
}
if bo.targetDocker { if bo.targetDocker {
for _, platform := range bo.platforms {
archRef, err := reference.Parse(fmt.Sprintf("%s-%s", p.FullTag(), platform.Architecture)) archRef, err := reference.Parse(fmt.Sprintf("%s-%s", p.FullTag(), platform.Architecture))
if err != nil { if err != nil {
return err return err
@ -251,18 +245,24 @@ func (p Pkg) Build(bos ...BuildOpt) error {
fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", archRef) fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", archRef)
if _, err := c.ImagePull(&archRef, "", platform.Architecture, false); err == nil { if _, err := c.ImagePull(&archRef, "", platform.Architecture, false); err == nil {
fmt.Fprintf(writer, "%s found or pulled\n", archRef) fmt.Fprintf(writer, "%s found or pulled\n", archRef)
skipBuild = true
} else { } else {
fmt.Fprintf(writer, "%s not found: %s\n", archRef, err) fmt.Fprintf(writer, "%s not found, will build: %s\n", archRef, err)
notFound = true platformsToBuild = append(platformsToBuild, platform)
} }
} }
skipBuild = skipBuild && !notFound } else {
fmt.Fprintf(writer, "%s not found, will build: %s\n", ref, err)
platformsToBuild = append(platformsToBuild, platform)
}
} }
} }
if !skipBuild { if len(platformsToBuild) > 0 {
fmt.Fprintf(writer, "building %s\n", ref) var arches []string
for _, platform := range platformsToBuild {
arches = append(arches, platform.Architecture)
}
fmt.Fprintf(writer, "building %s for arches: %s\n", ref, strings.Join(arches, ","))
var ( var (
imageBuildOpts = types.ImageBuildOptions{ imageBuildOpts = types.ImageBuildOptions{
Labels: map[string]string{}, Labels: map[string]string{},
@ -313,7 +313,7 @@ func (p Pkg) Build(bos ...BuildOpt) error {
} }
// build for each arch and save in the linuxkit cache // build for each arch and save in the linuxkit cache
for _, platform := range bo.platforms { for _, platform := range platformsToBuild {
desc, err := p.buildArch(ctx, d, c, bo.builderImage, platform.Architecture, bo.builderRestart, writer, bo, imageBuildOpts) desc, err := p.buildArch(ctx, d, c, bo.builderImage, platform.Architecture, bo.builderRestart, writer, bo, imageBuildOpts)
if err != nil { if err != nil {
return fmt.Errorf("error building for arch %s: %v", platform.Architecture, err) return fmt.Errorf("error building for arch %s: %v", platform.Architecture, err)