github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/build/layerutils/manifests/manifests.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 manifest
    16  
    17  import (
    18  	"fmt"
    19  	"io/ioutil"
    20  	"path/filepath"
    21  
    22  	"github.com/alibaba/sealer/build/layerutils"
    23  )
    24  
    25  type Manifests struct{}
    26  
    27  // ListImages List all the containers images in manifest files
    28  func (manifests *Manifests) ListImages(yamlFile string) ([]string, error) {
    29  	var list []string
    30  
    31  	yamlBytes, err := ioutil.ReadFile(filepath.Clean(yamlFile))
    32  	if err != nil {
    33  		return nil, fmt.Errorf("read file failed %s", err)
    34  	}
    35  
    36  	images := layerutils.DecodeImages(string(yamlBytes))
    37  	if len(images) != 0 {
    38  		list = append(list, images...)
    39  	}
    40  
    41  	if err != nil {
    42  		return list, fmt.Errorf("filepath walk failed %s", err)
    43  	}
    44  
    45  	return list, nil
    46  }
    47  
    48  func NewManifests() (layerutils.Interface, error) {
    49  	return &Manifests{}, nil
    50  }