github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/image/save/interface.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package save
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/docker/docker/pkg/progress"
    21  	v1 "github.com/sealerio/sealer/types/api/v1"
    22  )
    23  
    24  // ImageSave can save a list of images of the specified platform
    25  type ImageSave interface {
    26  	// SaveImages is not concurrently safe
    27  	SaveImages(images []string, dir string, platform v1.Platform) error
    28  }
    29  
    30  type Section struct {
    31  	Registry string             `json:"registry,omitempty"`
    32  	Username string             `json:"username,omitempty"`
    33  	Password string             `json:"password,omitempty"`
    34  	Images   map[string][]Named `json:"images,omitempty"`
    35  }
    36  
    37  type ImageListWithAuth []Section
    38  
    39  type DefaultImageSaver struct {
    40  	ctx            context.Context
    41  	domainToImages map[string][]Named
    42  	progressOut    progress.Output
    43  }
    44  
    45  func NewImageSaver(ctx context.Context) ImageSave {
    46  	if ctx == nil {
    47  		ctx = context.Background()
    48  	}
    49  	return &DefaultImageSaver{
    50  		ctx:            ctx,
    51  		domainToImages: make(map[string][]Named),
    52  	}
    53  }