...

Source file src/edge-infra.dev/hack/build/rules/container/archsupport/main.go

Documentation: edge-infra.dev/hack/build/rules/container/archsupport

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"flag"
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	oci "github.com/opencontainers/image-spec/specs-go/v1"
    11  )
    12  
    13  func main() {
    14  	os.Exit(run())
    15  }
    16  
    17  func run() int {
    18  	flag.Parse()
    19  
    20  	// open and parse the image index json file
    21  	imageLayout := flag.Arg(0)
    22  	imageLayoutAbs, err := filepath.Abs(imageLayout)
    23  	if err != nil {
    24  		fmt.Println(err)
    25  		return 1
    26  	}
    27  	layoutFS := os.DirFS(imageLayoutAbs)
    28  	manifestFile := "manifest_list.new.json"
    29  	file, err := layoutFS.Open(manifestFile)
    30  	if err != nil {
    31  		fmt.Println(err)
    32  		return 1
    33  	}
    34  	defer file.Close()
    35  
    36  	dec := json.NewDecoder(file)
    37  	idx := &oci.Index{}
    38  	if err := dec.Decode(idx); err != nil {
    39  		fmt.Println(err)
    40  		return 1
    41  	}
    42  
    43  	// search manifest list for all required platforms
    44  	foundPltfs := map[string]bool{
    45  		"linux/amd64": false,
    46  		"linux/arm64": false,
    47  	}
    48  	for _, desc := range idx.Manifests {
    49  		foundPltfs[fmt.Sprintf("%s/%s", desc.Platform.OS, desc.Platform.Architecture)] = true
    50  	}
    51  	for platform, found := range foundPltfs {
    52  		if !found {
    53  			fmt.Printf("failed to find required platform: %s\n", platform)
    54  			os.Exit(1)
    55  		}
    56  	}
    57  
    58  	return 0
    59  }
    60  

View as plain text