Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/lib/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type ImageCopyOpts struct {
DestSkipTLS bool
Progress io.Writer
Context context.Context
OverrideOS string
OverrideArch string
}

func ImageCopy(opts ImageCopyOpts) error {
Expand Down Expand Up @@ -90,7 +92,10 @@ func ImageCopy(opts ImageCopyOpts) error {
RemoveSignatures: true,
}

args.SourceCtx = &types.SystemContext{}
args.SourceCtx = &types.SystemContext{
ArchitectureChoice: opts.OverrideArch,
OSChoice: opts.OverrideOS,
}

if opts.SrcSkipTLS {
args.SourceCtx.DockerInsecureSkipTLSVerify = types.OptionalBoolTrue
Expand All @@ -104,7 +109,10 @@ func ImageCopy(opts ImageCopyOpts) error {
}
}

args.DestinationCtx = &types.SystemContext{}
args.DestinationCtx = &types.SystemContext{
ArchitectureChoice: opts.OverrideArch,
OSChoice: opts.OverrideOS,
}

if opts.DestSkipTLS {
args.DestinationCtx.DockerInsecureSkipTLSVerify = types.OptionalBoolTrue
Expand Down
24 changes: 18 additions & 6 deletions pkg/stacker/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetBase(o BaseLayerOpts) error {
case types.OCILayer:
fallthrough
case types.DockerLayer:
err := importContainersImage(o.Layer.From, o.Config, o.Progress)
err := importContainersImage(o.Layer, o.Config, o.Progress)
if o.Layer.Bom != nil && o.Layer.Bom.Generate && (o.Layer.From.Type == types.DockerLayer) {
bomPath := path.Join(o.Config.StackerDir, "artifacts", o.Name)
err = getArtifact(bomPath, "application/spdx+json", o.Layer.From.Url, "", "", o.Layer.From.Insecure)
Expand Down Expand Up @@ -105,7 +105,8 @@ func SetupRootfs(o BaseLayerOpts) error {
}
}

func importContainersImage(is types.ImageSource, config types.StackerConfig, progress bool) error {
func importContainersImage(layer types.Layer, config types.StackerConfig, progress bool) error {
is := layer.From
toImport, err := is.ContainersImageURL()
if err != nil {
return err
Expand Down Expand Up @@ -138,12 +139,23 @@ func importContainersImage(is types.ImageSource, config types.StackerConfig, pro
progressWriter = os.Stderr
}

os := ""
if layer.OS != nil {
os = *layer.OS
}
arch := ""
if layer.Arch != nil {
arch = *layer.Arch
}

log.Infof("loading %s", toImport)
err = lib.ImageCopy(lib.ImageCopyOpts{
Src: toImport,
Dest: fmt.Sprintf("oci:%s:%s", cacheDir, tag),
SrcSkipTLS: is.Insecure,
Progress: progressWriter,
Src: toImport,
Dest: fmt.Sprintf("oci:%s:%s", cacheDir, tag),
SrcSkipTLS: is.Insecure,
Progress: progressWriter,
OverrideOS: os,
OverrideArch: arch,
})
if err != nil {
return errors.Wrapf(err, "couldn't import base layer %s", tag)
Expand Down
Loading