github.com/anchore/syft@v1.38.2/examples/source_from_registry/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	_ "modernc.org/sqlite" // required for rpmdb and other features
     8  
     9  	"github.com/anchore/syft/syft"
    10  	"github.com/anchore/syft/syft/format/syftjson"
    11  )
    12  
    13  // This example demonstrates how to create an SBOM, pulling only from "registry", with error handling omitted
    14  func main() {
    15  	image := "alpine:3.19"
    16  
    17  	src, _ := syft.GetSource(context.Background(), image, syft.DefaultGetSourceConfig().WithSources("registry"))
    18  	defer src.Close()
    19  
    20  	sbom, _ := syft.CreateSBOM(context.Background(), src, syft.DefaultCreateSBOMConfig())
    21  
    22  	_ = syftjson.NewFormatEncoder().Encode(os.Stdout, *sbom)
    23  }