github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/imageengine/buildah/tag.go (about) 1 // Copyright © 2022 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 buildah 16 17 import ( 18 "fmt" 19 20 "github.com/sealerio/sealer/pkg/define/options" 21 22 "github.com/containers/common/libimage" 23 "github.com/pkg/errors" 24 ) 25 26 func (engine *Engine) Tag(opts *options.TagOptions) error { 27 name := opts.ImageNameOrID 28 if len(name) == 0 { 29 return errors.New("at least the image name or id should be specified") 30 } 31 if len(opts.Tags) == 0 { 32 return errors.New("at least one new tag should be provided") 33 } 34 35 lookupOptions := &libimage.LookupImageOptions{ManifestList: true} 36 existImage, _, err := engine.ImageRuntime().LookupImage(name, lookupOptions) 37 if err != nil { 38 return fmt.Errorf("failed to lookup image: %v", err) 39 } 40 41 for _, tag := range opts.Tags { 42 if err := existImage.Tag(tag); err != nil { 43 return err 44 } 45 } 46 47 return nil 48 }