github.com/quay/claircore@v1.5.28/alpine/testdata/fetchdists.go (about)

     1  //go:build tools
     2  // +build tools
     3  
     4  package main
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"log"
    10  	"os"
    11  	"os/exec"
    12  	"path/filepath"
    13  	"strconv"
    14  )
    15  
    16  func main() {
    17  	ctx := context.Background()
    18  	fs := make(map[int]map[string][]byte)
    19  	for min := 3; ; min++ {
    20  		f := make(map[string][]byte)
    21  		for _, p := range paths {
    22  			cmd := exec.CommandContext(ctx, `podman`, `run`, `--rm`, fmt.Sprintf("docker.io/library/alpine:3.%d", min), `cat`, p)
    23  			b, err := cmd.Output()
    24  			if err != nil {
    25  				log.Println(min, p, err)
    26  				continue
    27  			}
    28  			f[p] = b
    29  		}
    30  		if len(f) == 0 {
    31  			break
    32  		}
    33  		fs[min] = f
    34  	}
    35  	for min, f := range fs {
    36  		dir := `3.` + strconv.Itoa(min)
    37  		for fn, b := range f {
    38  			p := filepath.Join(dir, fn)
    39  			if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
    40  				log.Println(p, err)
    41  				continue
    42  			}
    43  			f, err := os.OpenFile(filepath.Join(dir, fn), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
    44  			if err != nil {
    45  				log.Println(fn, err)
    46  				continue
    47  			}
    48  			defer f.Close()
    49  			if _, err := f.Write(b); err != nil {
    50  				log.Println(fn, err)
    51  			}
    52  		}
    53  	}
    54  }
    55  
    56  var paths = []string{"etc/os-release", "etc/issue"}