Add option customPlatform (#1500)
* Add option customPlatform * fix formatting * fix No newline at end of file
This commit is contained in:
parent
ea59504b9b
commit
275cc9a7e7
10
README.md
10
README.md
|
|
@ -57,6 +57,7 @@ _If you are interested in contributing to kaniko, see [DEVELOPMENT.md](DEVELOPME
|
||||||
- [--cache-ttl duration](#--cache-ttl-duration)
|
- [--cache-ttl duration](#--cache-ttl-duration)
|
||||||
- [--cleanup](#--cleanup)
|
- [--cleanup](#--cleanup)
|
||||||
- [--context-sub-path](#--context-sub-path)
|
- [--context-sub-path](#--context-sub-path)
|
||||||
|
- [--customPlatform](#--customPlatform)
|
||||||
- [--digest-file](#--digest-file)
|
- [--digest-file](#--digest-file)
|
||||||
- [--force](#--force)
|
- [--force](#--force)
|
||||||
- [--git](#--git)
|
- [--git](#--git)
|
||||||
|
|
@ -577,6 +578,13 @@ Set a sub path within the given `--context`.
|
||||||
Its particularly useful when your context is, for example, a git repository,
|
Its particularly useful when your context is, for example, a git repository,
|
||||||
and you want to build one of its subfolders instead of the root folder.
|
and you want to build one of its subfolders instead of the root folder.
|
||||||
|
|
||||||
|
#### --customPlatform
|
||||||
|
|
||||||
|
Allows to build with another default platform than the host, similarly to docker build --platform xxx
|
||||||
|
the value has to be on the form `--customPlatform=linux/arm` , with acceptable values listed here: [GOOS/GOARCH](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63)
|
||||||
|
|
||||||
|
_This is not virtualization and cannot help to build an architecture not natively supported by the build host. This is used to build i386 on an amd64 Host for example, or arm32 on an arm64 host._
|
||||||
|
|
||||||
#### --digest-file
|
#### --digest-file
|
||||||
|
|
||||||
Set this flag to specify a file in the container. This file will
|
Set this flag to specify a file in the container. This file will
|
||||||
|
|
@ -819,4 +827,4 @@ file are made and when the `mtime` is updated. This means:
|
||||||
which will still be correct, but it does affect the number of layers.
|
which will still be correct, but it does affect the number of layers.
|
||||||
|
|
||||||
_Note that these issues are currently theoretical only. If you see this issue occur, please
|
_Note that these issues are currently theoretical only. If you see this issue occur, please
|
||||||
[open an issue](https://github.com/GoogleContainerTools/kaniko/issues)._
|
[open an issue](https://github.com/GoogleContainerTools/kaniko/issues)._
|
||||||
|
|
@ -150,6 +150,7 @@ func addKanikoOptionsFlags() {
|
||||||
RootCmd.PersistentFlags().StringVarP(&opts.Bucket, "bucket", "b", "", "Name of the GCS bucket from which to access build context as tarball.")
|
RootCmd.PersistentFlags().StringVarP(&opts.Bucket, "bucket", "b", "", "Name of the GCS bucket from which to access build context as tarball.")
|
||||||
RootCmd.PersistentFlags().VarP(&opts.Destinations, "destination", "d", "Registry the final image should be pushed to. Set it repeatedly for multiple destinations.")
|
RootCmd.PersistentFlags().VarP(&opts.Destinations, "destination", "d", "Registry the final image should be pushed to. Set it repeatedly for multiple destinations.")
|
||||||
RootCmd.PersistentFlags().StringVarP(&opts.SnapshotMode, "snapshotMode", "", "full", "Change the file attributes inspected during snapshotting")
|
RootCmd.PersistentFlags().StringVarP(&opts.SnapshotMode, "snapshotMode", "", "full", "Change the file attributes inspected during snapshotting")
|
||||||
|
RootCmd.PersistentFlags().StringVarP(&opts.CustomPlatform, "customPlatform", "", "", "Specify the build platform if different from the current host")
|
||||||
RootCmd.PersistentFlags().VarP(&opts.BuildArgs, "build-arg", "", "This flag allows you to pass in ARG values at build time. Set it repeatedly for multiple values.")
|
RootCmd.PersistentFlags().VarP(&opts.BuildArgs, "build-arg", "", "This flag allows you to pass in ARG values at build time. Set it repeatedly for multiple values.")
|
||||||
RootCmd.PersistentFlags().BoolVarP(&opts.Insecure, "insecure", "", false, "Push to insecure registry using plain HTTP")
|
RootCmd.PersistentFlags().BoolVarP(&opts.Insecure, "insecure", "", false, "Push to insecure registry using plain HTTP")
|
||||||
RootCmd.PersistentFlags().BoolVarP(&opts.SkipTLSVerify, "skip-tls-verify", "", false, "Push to insecure registry ignoring TLS verify")
|
RootCmd.PersistentFlags().BoolVarP(&opts.SkipTLSVerify, "skip-tls-verify", "", false, "Push to insecure registry ignoring TLS verify")
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ type KanikoOptions struct {
|
||||||
DockerfilePath string
|
DockerfilePath string
|
||||||
SrcContext string
|
SrcContext string
|
||||||
SnapshotMode string
|
SnapshotMode string
|
||||||
|
CustomPlatform string
|
||||||
Bucket string
|
Bucket string
|
||||||
TarPath string
|
TarPath string
|
||||||
Target string
|
Target string
|
||||||
|
|
|
||||||
|
|
@ -607,8 +607,13 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
configFile.OS = runtime.GOOS
|
if opts.CustomPlatform == "" {
|
||||||
configFile.Architecture = runtime.GOARCH
|
configFile.OS = runtime.GOOS
|
||||||
|
configFile.Architecture = runtime.GOARCH
|
||||||
|
} else {
|
||||||
|
configFile.OS = strings.Split(opts.CustomPlatform, "/")[0]
|
||||||
|
configFile.Architecture = strings.Split(opts.CustomPlatform, "/")[1]
|
||||||
|
}
|
||||||
sourceImage, err = mutate.ConfigFile(sourceImage, configFile)
|
sourceImage, err = mutate.ConfigFile(sourceImage, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ func remoteOptions(registryName string, opts *config.KanikoOptions) []remote.Opt
|
||||||
tr := util.MakeTransport(opts, registryName)
|
tr := util.MakeTransport(opts, registryName)
|
||||||
|
|
||||||
// on which v1.Platform is this currently running?
|
// on which v1.Platform is this currently running?
|
||||||
platform := currentPlatform()
|
platform := currentPlatform(opts)
|
||||||
|
|
||||||
return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain()), remote.WithPlatform(platform)}
|
return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain()), remote.WithPlatform(platform)}
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +199,13 @@ func cachedImage(opts *config.KanikoOptions, image string) (v1.Image, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentPlatform returns the v1.Platform on which the code runs
|
// CurrentPlatform returns the v1.Platform on which the code runs
|
||||||
func currentPlatform() v1.Platform {
|
func currentPlatform(opts *config.KanikoOptions) v1.Platform {
|
||||||
|
if opts.CustomPlatform != "" {
|
||||||
|
return v1.Platform{
|
||||||
|
OS: strings.Split(opts.CustomPlatform, "/")[0],
|
||||||
|
Architecture: strings.Split(opts.CustomPlatform, "/")[1],
|
||||||
|
}
|
||||||
|
}
|
||||||
return v1.Platform{
|
return v1.Platform{
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
Architecture: runtime.GOARCH,
|
Architecture: runtime.GOARCH,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue