mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 17:49:10 +00:00
Fix consistently building of multiple arch
We cannot build for another arch after building for one arch because of setting skipBuild to true if one arch found. In other words "linuxkit pkg build --platforms linux/riscv64,linux/amd64 ..." after "linuxkit pkg build --platforms linux/amd64 ..." will not build for linux/riscv64 which is not expected. In general when we check for available images and able to found part of platforms we do not want to rebuild all of them. So this PR includes platformsToBuild slice which we fill with platforms we want to build for . Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
This commit is contained in:
parent
86cc42bf79
commit
57148029cd
@ -229,21 +229,15 @@ func (p Pkg) Build(bos ...BuildOpt) error {
|
||||
return fmt.Errorf("contexts not supported, check docker version: %v", err)
|
||||
}
|
||||
|
||||
skipBuild := bo.skipBuild
|
||||
if !bo.force {
|
||||
notFound := false
|
||||
var platformsToBuild []imagespec.Platform
|
||||
if bo.force {
|
||||
platformsToBuild = bo.platforms
|
||||
} else if !bo.skipBuild {
|
||||
fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", ref)
|
||||
for _, platform := range bo.platforms {
|
||||
if _, err := c.ImagePull(&ref, "", platform.Architecture, false); err == nil {
|
||||
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 {
|
||||
for _, platform := range bo.platforms {
|
||||
archRef, err := reference.Parse(fmt.Sprintf("%s-%s", p.FullTag(), platform.Architecture))
|
||||
if err != nil {
|
||||
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)
|
||||
if _, err := c.ImagePull(&archRef, "", platform.Architecture, false); err == nil {
|
||||
fmt.Fprintf(writer, "%s found or pulled\n", archRef)
|
||||
skipBuild = true
|
||||
} else {
|
||||
fmt.Fprintf(writer, "%s not found: %s\n", archRef, err)
|
||||
notFound = true
|
||||
fmt.Fprintf(writer, "%s not found, will build: %s\n", archRef, err)
|
||||
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 {
|
||||
fmt.Fprintf(writer, "building %s\n", ref)
|
||||
if len(platformsToBuild) > 0 {
|
||||
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 (
|
||||
imageBuildOpts = types.ImageBuildOptions{
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error building for arch %s: %v", platform.Architecture, err)
|
||||
|
Loading…
Reference in New Issue
Block a user