feature: support pre-defined build args of multi-platform build arguments
This commit is contained in:
parent
e328007bc1
commit
8218bd7386
|
|
@ -17,8 +17,10 @@ limitations under the License.
|
|||
package dockerfile
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
d "github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/moby/buildkit/frontend/dockerfile/instructions"
|
||||
)
|
||||
|
|
@ -68,3 +70,42 @@ func (b *BuildArgs) AddMetaArgs(metaArgs []instructions.ArgCommand) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddPreDefinedBuildArgs adds pre-defined build args. Such as TARGETOS, TARGETARCH, BUILDPLATFORM, TARGETPLATFORM
|
||||
func (b *BuildArgs) AddPreDefinedBuildArgs(opts *config.KanikoOptions) {
|
||||
buildPlatform := runtime.GOOS + "/" + runtime.GOARCH
|
||||
buildOs := runtime.GOOS
|
||||
buildArch := runtime.GOARCH
|
||||
|
||||
targetPlatform := ""
|
||||
targetOs := ""
|
||||
targetArch := ""
|
||||
targetVariant := ""
|
||||
|
||||
if opts.CustomPlatform == "" {
|
||||
targetPlatform = buildPlatform
|
||||
targetOs = buildOs
|
||||
targetArch = buildArch
|
||||
} else {
|
||||
targetPlatform = opts.CustomPlatform
|
||||
platformParts := strings.Split(opts.CustomPlatform, "/")
|
||||
if len(platformParts) > 0 {
|
||||
targetOs = platformParts[0]
|
||||
}
|
||||
if len(platformParts) > 1 {
|
||||
targetArch = platformParts[1]
|
||||
}
|
||||
if len(platformParts) > 2 {
|
||||
targetVariant = platformParts[2]
|
||||
}
|
||||
}
|
||||
|
||||
b.AddArg("BUILDPLATFORM", &buildPlatform)
|
||||
b.AddArg("BUILDOS", &buildOs)
|
||||
b.AddArg("BUILDARCH", &buildArch)
|
||||
|
||||
b.AddArg("TARGETPLATFORM", &targetPlatform)
|
||||
b.AddArg("TARGETOS", &targetOs)
|
||||
b.AddArg("TARGETARCH", &targetArch)
|
||||
b.AddArg("TARGETVARIANT", &targetVariant)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ func newStageBuilder(args *dockerfile.BuildArgs, opts *config.KanikoOptions, sta
|
|||
s.args = dockerfile.NewBuildArgs(s.opts.BuildArgs)
|
||||
}
|
||||
s.args.AddMetaArgs(s.stage.MetaArgs)
|
||||
s.args.AddPreDefinedBuildArgs(opts)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue