-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: anshlykov <andrew.shlykov@ya.ru>
- Loading branch information
Showing
6 changed files
with
171 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package stack | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/logging" | ||
) | ||
|
||
func NewStackCmd(logger logging.Logger) *cobra.Command { | ||
command := cobra.Command{ | ||
Use: "stack", | ||
Short: "Displays stack information", | ||
RunE: nil, | ||
} | ||
|
||
command.AddCommand(newSuggestCmd(logger)) | ||
return &command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package stack | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"sort" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/logging" | ||
) | ||
|
||
type suggestedStack struct { | ||
ID string | ||
Description string | ||
Maintainer string | ||
BuildImage string | ||
RunImage string | ||
} | ||
|
||
var suggestedStacks = []suggestedStack{ | ||
{ | ||
ID: "heroku-18", | ||
Description: "The official Heroku stack based on Ubuntu 18.04", | ||
Maintainer: "Heroku", | ||
BuildImage: "heroku/pack:18-build", | ||
RunImage: "heroku/pack:18", | ||
}, | ||
{ | ||
ID: "io.buildpacks.stacks.bionic", | ||
Description: "A minimal Paketo stack based on Ubuntu 18.04", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:base-cnb", | ||
RunImage: "paketobuildpacks/run:base-cnb", | ||
}, | ||
{ | ||
ID: "io.buildpacks.stacks.bionic", | ||
Description: "A large Paketo stack based on Ubuntu 18.04", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:full-cnb", | ||
RunImage: "paketobuildpacks/run:full-cnb", | ||
}, | ||
{ | ||
ID: "io.paketo.stacks.tiny", | ||
Description: "A tiny Paketo stack based on Ubuntu 18.04, similar to distroless", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:tiny-cnb", | ||
RunImage: "paketobuildpacks/run:tiny-cnb", | ||
}, | ||
} | ||
|
||
func newSuggestCmd(logger logging.Logger) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "suggest", | ||
Args: cobra.NoArgs, | ||
Short: "Display list of recommended stacks", | ||
Example: "pack stacks suggest", | ||
Run: func(*cobra.Command, []string) { | ||
Suggest(logger) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func Suggest(log logging.Logger) { | ||
sort.Slice(suggestedStacks, func(i, j int) bool { return suggestedStacks[i].ID < suggestedStacks[j].ID }) | ||
tmpl := template.Must(template.New("").Parse(`Stacks maintained by the community: | ||
{{- range . }} | ||
Stack ID: {{ .ID }} | ||
Description: {{ .Description }} | ||
Maintainer: {{ .Maintainer }} | ||
Build Image: {{ .BuildImage }} | ||
Run Image: {{ .RunImage }} | ||
{{- end }} | ||
`)) | ||
|
||
buf := &bytes.Buffer{} | ||
tmpl.Execute(buf, suggestedStacks) | ||
log.Info(buf.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package stack | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/internal/logging" | ||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
func TestSuggestStacksCommand(t *testing.T) { | ||
spec.Run(t, "Commands", testSuggestStacksCommand, spec.Parallel(), spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testSuggestStacksCommand(t *testing.T, when spec.G, it spec.S) { | ||
var ( | ||
command *cobra.Command | ||
outBuf bytes.Buffer | ||
) | ||
|
||
it.Before(func() { | ||
command = newSuggestCmd(logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
}) | ||
|
||
when("#SuggestStacks", func() { | ||
it("displays stack information", func() { | ||
command.SetArgs([]string{}) | ||
h.AssertNil(t, command.Execute()) | ||
h.AssertEq(t, outBuf.String(), `Stacks maintained by the community: | ||
Stack ID: heroku-18 | ||
Description: The official Heroku stack based on Ubuntu 18.04 | ||
Maintainer: Heroku | ||
Build Image: heroku/pack:18-build | ||
Run Image: heroku/pack:18 | ||
Stack ID: io.buildpacks.stacks.bionic | ||
Description: A minimal Paketo stack based on Ubuntu 18.04 | ||
Maintainer: Paketo Project | ||
Build Image: paketobuildpacks/build:base-cnb | ||
Run Image: paketobuildpacks/run:base-cnb | ||
Stack ID: io.buildpacks.stacks.bionic | ||
Description: A large Paketo stack based on Ubuntu 18.04 | ||
Maintainer: Paketo Project | ||
Build Image: paketobuildpacks/build:full-cnb | ||
Run Image: paketobuildpacks/run:full-cnb | ||
Stack ID: io.paketo.stacks.tiny | ||
Description: A tiny Paketo stack based on Ubuntu 18.04, similar to distroless | ||
Maintainer: Paketo Project | ||
Build Image: paketobuildpacks/build:tiny-cnb | ||
Run Image: paketobuildpacks/run:tiny-cnb | ||
`) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,26 @@ | ||
package commands | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"sort" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/internal/commands/stack" | ||
|
||
"github.com/buildpacks/pack/logging" | ||
) | ||
|
||
type suggestedStack struct { | ||
ID string | ||
Description string | ||
Maintainer string | ||
BuildImage string | ||
RunImage string | ||
} | ||
|
||
var suggestedStacks = []suggestedStack{ | ||
{ | ||
ID: "heroku-18", | ||
Description: "The official Heroku stack based on Ubuntu 18.04", | ||
Maintainer: "Heroku", | ||
BuildImage: "heroku/pack:18-build", | ||
RunImage: "heroku/pack:18", | ||
}, | ||
{ | ||
ID: "io.buildpacks.stacks.bionic", | ||
Description: "A minimal Paketo stack based on Ubuntu 18.04", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:base-cnb", | ||
RunImage: "paketobuildpacks/run:base-cnb", | ||
}, | ||
{ | ||
ID: "io.buildpacks.stacks.bionic", | ||
Description: "A large Paketo stack based on Ubuntu 18.04", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:full-cnb", | ||
RunImage: "paketobuildpacks/run:full-cnb", | ||
}, | ||
{ | ||
ID: "io.paketo.stacks.tiny", | ||
Description: "A tiny Paketo stack based on Ubuntu 18.04, similar to distroless", | ||
Maintainer: "Paketo Project", | ||
BuildImage: "paketobuildpacks/build:tiny-cnb", | ||
RunImage: "paketobuildpacks/run:tiny-cnb", | ||
}, | ||
} | ||
|
||
func SuggestStacks(logger logging.Logger) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "suggest-stacks", | ||
Args: cobra.NoArgs, | ||
Short: "Display list of recommended stacks", | ||
Example: "pack suggest-stacks", | ||
Run: func(*cobra.Command, []string) { | ||
suggestStacks(logger) | ||
logger.Warn("Command 'pack suggest-stacks' has been deprecated, please use 'pack stack suggest' instead") | ||
stack.Suggest(logger) | ||
}, | ||
Hidden: true, | ||
} | ||
|
||
AddHelpFlag(cmd, "suggest-stacks") | ||
return cmd | ||
} | ||
|
||
func suggestStacks(log logging.Logger) { | ||
sort.Slice(suggestedStacks, func(i, j int) bool { return suggestedStacks[i].ID < suggestedStacks[j].ID }) | ||
tmpl := template.Must(template.New("").Parse(`Stacks maintained by the community: | ||
{{- range . }} | ||
Stack ID: {{ .ID }} | ||
Description: {{ .Description }} | ||
Maintainer: {{ .Maintainer }} | ||
Build Image: {{ .BuildImage }} | ||
Run Image: {{ .RunImage }} | ||
{{- end }} | ||
`)) | ||
|
||
buf := &bytes.Buffer{} | ||
tmpl.Execute(buf, suggestedStacks) | ||
log.Info(buf.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters