-
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.
Merge branch 'main' into fix/run-image-multi-arch
Signed-off-by: Joe Kutner <[email protected]>
- Loading branch information
Showing
19 changed files
with
565 additions
and
50 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
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
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
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 |
---|---|---|
|
@@ -5,21 +5,25 @@ import ( | |
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/internal/style" | ||
"github.com/buildpacks/pack/internal/target" | ||
"github.com/buildpacks/pack/pkg/client" | ||
"github.com/buildpacks/pack/pkg/dist" | ||
"github.com/buildpacks/pack/pkg/logging" | ||
) | ||
|
||
// BuildpackNewFlags define flags provided to the BuildpackNew command | ||
type BuildpackNewFlags struct { | ||
API string | ||
Path string | ||
API string | ||
Path string | ||
// Deprecated: Stacks are deprecated | ||
Stacks []string | ||
Targets []string | ||
Version string | ||
} | ||
|
||
|
@@ -66,11 +70,24 @@ func BuildpackNew(logger logging.Logger, creator BuildpackCreator) *cobra.Comman | |
}) | ||
} | ||
|
||
var targets []dist.Target | ||
if len(flags.Targets) == 0 && len(flags.Stacks) == 0 { | ||
targets = []dist.Target{{ | ||
OS: runtime.GOOS, | ||
Arch: runtime.GOARCH, | ||
}} | ||
} else { | ||
if targets, err = target.ParseTargets(flags.Targets, logger); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := creator.NewBuildpack(cmd.Context(), client.NewBuildpackOptions{ | ||
API: flags.API, | ||
ID: id, | ||
Path: path, | ||
Stacks: stacks, | ||
Targets: targets, | ||
Version: flags.Version, | ||
}); err != nil { | ||
return err | ||
|
@@ -84,7 +101,14 @@ func BuildpackNew(logger logging.Logger, creator BuildpackCreator) *cobra.Comman | |
cmd.Flags().StringVarP(&flags.API, "api", "a", "0.8", "Buildpack API compatibility of the generated buildpack") | ||
cmd.Flags().StringVarP(&flags.Path, "path", "p", "", "Path to generate the buildpack") | ||
cmd.Flags().StringVarP(&flags.Version, "version", "V", "1.0.0", "Version of the generated buildpack") | ||
cmd.Flags().StringSliceVarP(&flags.Stacks, "stacks", "s", []string{"io.buildpacks.stacks.jammy"}, "Stack(s) this buildpack will be compatible with"+stringSliceHelp("stack")) | ||
cmd.Flags().StringSliceVarP(&flags.Stacks, "stacks", "s", nil, "Stack(s) this buildpack will be compatible with"+stringSliceHelp("stack")) | ||
cmd.Flags().MarkDeprecated("stacks", "prefer `--targets` instead: https://github.com/buildpacks/rfcs/blob/main/text/0096-remove-stacks-mixins.md") | ||
cmd.Flags().StringSliceVarP(&flags.Targets, "targets", "t", nil, | ||
`Targets are the list platforms that one targeting, these are generated as part of scaffolding inside buildpack.toml file. one can provide target platforms in format [os][/arch][/variant]:[distroname@osversion@anotherversion];[distroname@osversion] | ||
- Base case for two different architectures : '--targets "linux/amd64" --targets "linux/arm64"' | ||
- case for distribution version: '--targets "windows/amd64:[email protected]"' | ||
- case for different architecture with distributed versions : '--targets "linux/arm/v6:[email protected]" --targets "linux/arm/v6:[email protected]"' | ||
`) | ||
|
||
AddHelpFlag(cmd, "new") | ||
return cmd | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/buildpacks/pack/pkg/client" | ||
|
@@ -36,6 +37,10 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) { | |
mockClient *testmocks.MockPackClient | ||
tmpDir string | ||
) | ||
targets := []dist.Target{{ | ||
OS: runtime.GOOS, | ||
Arch: runtime.GOARCH, | ||
}} | ||
|
||
it.Before(func() { | ||
var err error | ||
|
@@ -60,10 +65,7 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) { | |
ID: "example/some-cnb", | ||
Path: filepath.Join(tmpDir, "some-cnb"), | ||
Version: "1.0.0", | ||
Stacks: []dist.Stack{{ | ||
ID: "io.buildpacks.stacks.jammy", | ||
Mixins: []string{}, | ||
}}, | ||
Targets: targets, | ||
}).Return(nil).MaxTimes(1) | ||
|
||
path := filepath.Join(tmpDir, "some-cnb") | ||
|
@@ -82,5 +84,121 @@ func testBuildpackNewCommand(t *testing.T, when spec.G, it spec.S) { | |
h.AssertNotNil(t, err) | ||
h.AssertContains(t, outBuf.String(), "ERROR: directory") | ||
}) | ||
|
||
when("target flag is specified, ", func() { | ||
it("it uses target to generate artifacts", func() { | ||
mockClient.EXPECT().NewBuildpack(gomock.Any(), client.NewBuildpackOptions{ | ||
API: "0.8", | ||
ID: "example/targets", | ||
Path: filepath.Join(tmpDir, "targets"), | ||
Version: "1.0.0", | ||
Targets: []dist.Target{{ | ||
OS: "linux", | ||
Arch: "arm", | ||
ArchVariant: "v6", | ||
Distributions: []dist.Distribution{{ | ||
Name: "ubuntu", | ||
Versions: []string{"14.04", "16.04"}, | ||
}}, | ||
}}, | ||
}).Return(nil).MaxTimes(1) | ||
|
||
path := filepath.Join(tmpDir, "targets") | ||
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:[email protected]@16.04"}) | ||
|
||
err := command.Execute() | ||
h.AssertNil(t, err) | ||
}) | ||
it("it should show error when invalid [os]/[arch] passed", func() { | ||
mockClient.EXPECT().NewBuildpack(gomock.Any(), client.NewBuildpackOptions{ | ||
API: "0.8", | ||
ID: "example/targets", | ||
Path: filepath.Join(tmpDir, "targets"), | ||
Version: "1.0.0", | ||
Targets: []dist.Target{{ | ||
OS: "os", | ||
Arch: "arm", | ||
ArchVariant: "v6", | ||
Distributions: []dist.Distribution{{ | ||
Name: "ubuntu", | ||
Versions: []string{"14.04", "16.04"}, | ||
}}, | ||
}}, | ||
}).Return(nil).MaxTimes(1) | ||
|
||
path := filepath.Join(tmpDir, "targets") | ||
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "os/arm/v6:[email protected]@16.04"}) | ||
|
||
err := command.Execute() | ||
h.AssertNotNil(t, err) | ||
}) | ||
when("it should", func() { | ||
it("support format [os][/arch][/variant]:[name@version@version2];[some-name@version@version2]", func() { | ||
mockClient.EXPECT().NewBuildpack(gomock.Any(), client.NewBuildpackOptions{ | ||
API: "0.8", | ||
ID: "example/targets", | ||
Path: filepath.Join(tmpDir, "targets"), | ||
Version: "1.0.0", | ||
Targets: []dist.Target{ | ||
{ | ||
OS: "linux", | ||
Arch: "arm", | ||
ArchVariant: "v6", | ||
Distributions: []dist.Distribution{ | ||
{ | ||
Name: "ubuntu", | ||
Versions: []string{"14.04", "16.04"}, | ||
}, | ||
{ | ||
Name: "debian", | ||
Versions: []string{"8.10", "10.9"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
OS: "windows", | ||
Arch: "amd64", | ||
Distributions: []dist.Distribution{ | ||
{ | ||
Name: "windows-nano", | ||
Versions: []string{"10.0.19041.1415"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}).Return(nil).MaxTimes(1) | ||
|
||
path := filepath.Join(tmpDir, "targets") | ||
command.SetArgs([]string{"--path", path, "example/targets", "--targets", "linux/arm/v6:[email protected]@16.04;[email protected]@10.9", "-t", "windows/amd64:[email protected]"}) | ||
|
||
err := command.Execute() | ||
h.AssertNil(t, err) | ||
}) | ||
}) | ||
when("stacks ", func() { | ||
it("flag should show deprecated message when used", func() { | ||
mockClient.EXPECT().NewBuildpack(gomock.Any(), client.NewBuildpackOptions{ | ||
API: "0.8", | ||
ID: "example/stacks", | ||
Path: filepath.Join(tmpDir, "stacks"), | ||
Version: "1.0.0", | ||
Stacks: []dist.Stack{{ | ||
ID: "io.buildpacks.stacks.jammy", | ||
Mixins: []string{}, | ||
}}, | ||
}).Return(nil).MaxTimes(1) | ||
|
||
path := filepath.Join(tmpDir, "stacks") | ||
output := new(bytes.Buffer) | ||
command.SetOut(output) | ||
command.SetErr(output) | ||
command.SetArgs([]string{"--path", path, "example/stacks", "--stacks", "io.buildpacks.stacks.jammy"}) | ||
|
||
err := command.Execute() | ||
h.AssertNil(t, err) | ||
h.AssertContains(t, output.String(), "Flag --stacks has been deprecated,") | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.