34c7a2ff12
Set the default platform based on the client's OS and architecture. This function is the same one that buildkit uses (https://github.com/moby/buildkit/blob/master/frontend/dockerfile/builder/build.go#L100-L102) to set the default build target platform Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
32 lines
570 B
Go
32 lines
570 B
Go
package plancontext
|
|
|
|
import (
|
|
"github.com/containerd/containerd/platforms"
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
|
)
|
|
|
|
type platformContext struct {
|
|
platform *specs.Platform
|
|
}
|
|
|
|
func (c *platformContext) Get() specs.Platform {
|
|
return *c.platform
|
|
}
|
|
|
|
func (c *platformContext) SetString(platform string) error {
|
|
p, err := platforms.Parse(platform)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.platform = &p
|
|
return nil
|
|
}
|
|
|
|
func (c *platformContext) Set(p specs.Platform) {
|
|
c.platform = &p
|
|
}
|
|
|
|
func (c *platformContext) IsSet() bool {
|
|
return c.platform != nil
|
|
}
|