Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull command support multiples platforms #2340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ linux-arm64: clean
build-in-docker:
docker run --rm -v ${PWD}:/usr/src/sealer -w /usr/src/sealer registry.cn-qingdao.aliyuncs.com/sealer-io/sealer-build:v1 make linux

podman-build:
sudo podman run --rm -v $(shell pwd):/usr/src/sealer -w /usr/src/sealer registry.cn-qingdao.aliyuncs.com/sealer-io/sealer-build:v1 make linux

## clean: Remove all files that are created by building.
.PHONY: clean
clean:
Expand Down
5 changes: 5 additions & 0 deletions build/kubefile/parser/image_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (testImageEngine) Tag(opts *options.TagOptions) error {
panic("implement me")
}

func (testImageEngine) Untag(name string) error {
//TODO implement me
panic("implement me")
}

func (testImageEngine) CreateWorkingContainer(opts *options.BuildRootfsOptions) (string, error) {
//TODO implement me
panic("implement me")
Expand Down
49 changes: 43 additions & 6 deletions cmd/sealer/cmd/image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import (

var pullOpts *options.PullOptions

var pullPlatforms []string

var longNewPullCmdDescription = ``

var exampleForPullCmd = `
sealer pull docker.io/sealerio/kubernetes:v1-22-15-sealerio-2
sealer pull docker.io/sealerio/kubernetes:v1-22-15-sealerio-2 --platform linux/amd64
sealer pull docker.io/sealerio/kubernetes:v1-22-15-sealerio-2 --platform linux/amd64,linux/arm64
`

// NewPullCmd pullCmd represents the pull command
Expand All @@ -48,17 +51,51 @@ func NewPullCmd() *cobra.Command {
return err
}
pullOpts.Image = args[0]
imageID, err := engine.Pull(pullOpts)
if err != nil {
return fmt.Errorf("failed to pull image: %s: %v", pullOpts.Image, err)

if len(pullPlatforms) == 0 {
pullPlatforms = []string{parse.DefaultPlatform()}
}

if len(pullPlatforms) == 1 {
pullOpts.Platform = pullPlatforms[0]
imageID, err := engine.Pull(pullOpts)
if err != nil {
return fmt.Errorf("failed to pull image: %s: %w", pullOpts.Image, err)
}

logrus.Infof("successful pull %s with the image ID: %s", pullOpts.Image, imageID)
return err
}

logrus.Infof("successful pull %s with the image ID: %s", pullOpts.Image, imageID)
return err
imageIDList := make([]string, 0)
for _, p := range pullPlatforms {
pullOpts.Platform = p
imageID, err := engine.Pull(pullOpts)
if err != nil {
return fmt.Errorf("failed to pull image: %s for %s: %w", pullOpts.Image, p, err)
}
imageIDList = append(imageIDList, imageID)

if err := engine.Untag(args[0]); err != nil {
return fmt.Errorf("failed to pull image: %s for %s: untag: %w", pullOpts.Image, p, err)
}
}

if _, err := engine.CreateManifest(args[0], &options.ManifestCreateOpts{}); err != nil {
return fmt.Errorf("failed to pull image: %s: create image list: %w", pullOpts.Image, err)
}

if err := engine.AddToManifest(args[0], imageIDList, &options.ManifestAddOpts{All: true}); err != nil {
return fmt.Errorf("failed to pull image: %s: fill image list: %w", pullOpts.Image, err)
}

return nil
},
}

pullOpts = &options.PullOptions{}
pullCmd.Flags().StringVar(&pullOpts.Platform, "platform", parse.DefaultPlatform(), "prefer OS/ARCH instead of the current operating system and architecture for choosing images")
pullCmd.Flags().StringSliceVar(&pullPlatforms, "platform", []string{parse.DefaultPlatform()}, "prefer OS/ARCH instead of the current"+
" operating system and architecture for choosing images, use a comma spereated list to pull muiltple platforms")
pullCmd.Flags().StringVar(&pullOpts.PullPolicy, "policy", "always", "missing, always, ifnewer or never.")
pullCmd.Flags().BoolVarP(&pullOpts.Quiet, "quiet", "q", false, "don't output progress information when pulling images")
pullCmd.Flags().BoolVar(&pullOpts.SkipTLSVerify, "skip-tls-verify", false, "default is requiring HTTPS and verify certificates when accessing the registry.")
Expand Down
11 changes: 11 additions & 0 deletions pkg/imageengine/buildah/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ func (engine *Engine) Tag(opts *options.TagOptions) error {

return nil
}

func (engine *Engine) Untag(name string) error {

lookupOptions := &libimage.LookupImageOptions{ManifestList: true}
existImage, _, err := engine.ImageRuntime().LookupImage(name, lookupOptions)
if err != nil {
return fmt.Errorf("failed to lookup image: %v", err)
}

return existImage.Untag(name)
}
2 changes: 2 additions & 0 deletions pkg/imageengine/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Interface interface {

Tag(opts *options.TagOptions) error

Untag(name string) error

Inspect(opts *options.InspectOptions) (*v1.ImageSpec, error)

LookupManifest(name string) (*libimage.ManifestList, error)
Expand Down
Loading