github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/stack_suggest.go (about)

     1  package commands
     2  
     3  import (
     4  	"bytes"
     5  	"html/template"
     6  	"sort"
     7  
     8  	"github.com/spf13/cobra"
     9  
    10  	"github.com/buildpacks/pack/pkg/logging"
    11  )
    12  
    13  type suggestedStack struct {
    14  	ID          string
    15  	Description string
    16  	Maintainer  string
    17  	BuildImage  string
    18  	RunImage    string
    19  }
    20  
    21  var suggestedStacks = []suggestedStack{
    22  	{
    23  		ID:          "Deprecation Notice",
    24  		Description: "Stacks are deprecated in favor of using BuildImages and RunImages directly, but will continue to be supported throughout all of 2023 and 2024 if not longer. Please see our docs for more details- https://buildpacks.io/docs/concepts/components/stack",
    25  		Maintainer:  "CNB",
    26  	},
    27  	{
    28  		ID:          "heroku-20",
    29  		Description: "The official Heroku stack based on Ubuntu 20.04",
    30  		Maintainer:  "Heroku",
    31  		BuildImage:  "heroku/heroku:20-cnb-build",
    32  		RunImage:    "heroku/heroku:20-cnb",
    33  	},
    34  	{
    35  		ID:          "io.buildpacks.stacks.jammy",
    36  		Description: "A minimal Paketo stack based on Ubuntu 22.04",
    37  		Maintainer:  "Paketo Project",
    38  		BuildImage:  "paketobuildpacks/build-jammy-base",
    39  		RunImage:    "paketobuildpacks/run-jammy-base",
    40  	},
    41  	{
    42  		ID:          "io.buildpacks.stacks.jammy",
    43  		Description: "A large Paketo stack based on Ubuntu 22.04",
    44  		Maintainer:  "Paketo Project",
    45  		BuildImage:  "paketobuildpacks/build-jammy-full",
    46  		RunImage:    "paketobuildpacks/run-jammy-full",
    47  	},
    48  	{
    49  		ID:          "io.buildpacks.stacks.jammy.tiny",
    50  		Description: "A tiny Paketo stack based on Ubuntu 22.04, similar to distroless",
    51  		Maintainer:  "Paketo Project",
    52  		BuildImage:  "paketobuildpacks/build-jammy-tiny",
    53  		RunImage:    "paketobuildpacks/run-jammy-tiny",
    54  	},
    55  	{
    56  		ID:          "io.buildpacks.stacks.jammy.static",
    57  		Description: "A static Paketo stack based on Ubuntu 22.04, similar to distroless",
    58  		Maintainer:  "Paketo Project",
    59  		BuildImage:  "paketobuildpacks/build-jammy-static",
    60  		RunImage:    "paketobuildpacks/run-jammy-static",
    61  	},
    62  }
    63  
    64  func stackSuggest(logger logging.Logger) *cobra.Command {
    65  	cmd := &cobra.Command{
    66  		Use:     "suggest",
    67  		Args:    cobra.NoArgs,
    68  		Short:   "(deprecated) List the recommended stacks",
    69  		Example: "pack stack suggest",
    70  		RunE: logError(logger, func(*cobra.Command, []string) error {
    71  			Suggest(logger)
    72  			return nil
    73  		}),
    74  	}
    75  
    76  	return cmd
    77  }
    78  
    79  func Suggest(log logging.Logger) {
    80  	sort.Slice(suggestedStacks, func(i, j int) bool { return suggestedStacks[i].ID < suggestedStacks[j].ID })
    81  	tmpl := template.Must(template.New("").Parse(`Stacks maintained by the community:
    82  {{- range . }}
    83  
    84      Stack ID: {{ .ID }}
    85      Description: {{ .Description }}
    86      Maintainer: {{ .Maintainer }}
    87      Build Image: {{ .BuildImage }}
    88      Run Image: {{ .RunImage }}
    89  {{- end }}
    90  `))
    91  
    92  	buf := &bytes.Buffer{}
    93  	tmpl.Execute(buf, suggestedStacks)
    94  	log.Info(buf.String())
    95  }