Skip to content

Commit

Permalink
Merge pull request #3660 from balopat/new_init_format
Browse files Browse the repository at this point in the history
a hidden flag for simpler access to new init format
  • Loading branch information
tejal29 authored Feb 7, 2020
2 parents c6bbc3e + a3bef15 commit 12581fe
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cmd/skaffold/app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
analyze bool
enableJibInit bool
enableBuildpacksInit bool
enableNewInitFormat bool
buildpacksBuilder string
)

Expand All @@ -56,6 +57,8 @@ func NewCmdInit() *cobra.Command {
f.StringArrayVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited Dockerfile/image pair, or JSON string, to generate build artifact\n(example: --artifact='{\"builder\":\"Docker\",\"payload\":{\"path\":\"/web/Dockerfile.web\"},\"image\":\"gcr.io/web-project/image\"}')")
f.StringArrayVarP(&cliKubernetesManifests, "kubernetes-manifest", "k", nil, "a path or a glob pattern to kubernetes manifests (can be non-existent) to be added to the kubectl deployer (overrides detection of kubernetes manifests). Repeat the flag for multiple entries. E.g.: skaffold init -k pod.yaml -k k8s/*.yml")
f.BoolVar(&analyze, "analyze", false, "Print all discoverable Dockerfiles and images in JSON format to stdout")
f.BoolVar(&enableNewInitFormat, "XXenableNewInitFormat", false, "")
f.MarkHidden("XXenableNewInitFormat")
f.BoolVar(&enableJibInit, "XXenableJibInit", false, "")
f.MarkHidden("XXenableJibInit")
f.BoolVar(&enableBuildpacksInit, "XXenableBuildpacksInit", false, "")
Expand All @@ -77,6 +80,7 @@ func doInit(ctx context.Context, out io.Writer) error {
Analyze: analyze,
EnableJibInit: enableJibInit,
EnableBuildpacksInit: enableBuildpacksInit,
EnableNewInitFormat: enableNewInitFormat || enableBuildpacksInit || enableJibInit,
BuildpacksBuilder: buildpacksBuilder,
Opts: opts,
})
Expand Down
47 changes: 47 additions & 0 deletions cmd/skaffold/app/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func TestFlagsToConfigVersion(t *testing.T) {
Analyze: false,
EnableJibInit: false,
EnableBuildpacksInit: false,
EnableNewInitFormat: false,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},

{
name: "no error + non-default values for flags mapped to config values",
args: []string{
Expand All @@ -70,6 +72,7 @@ func TestFlagsToConfigVersion(t *testing.T) {
"--analyze",
"--XXenableJibInit",
"--XXenableBuildpacksInit",
"--XXenableNewInitFormat",
"--XXdefaultBuildpacksBuilder", "buildpacks/builder",
},
expectedConfig: initializer.Config{
Expand All @@ -82,10 +85,54 @@ func TestFlagsToConfigVersion(t *testing.T) {
Analyze: true,
EnableJibInit: true,
EnableBuildpacksInit: true,
EnableNewInitFormat: true,
BuildpacksBuilder: "buildpacks/builder",
Opts: opts,
},
},

{
name: "enableJibInit implies enableNewInitFormat",
args: []string{
"init",
"--XXenableJibInit",
},
expectedConfig: initializer.Config{
ComposeFile: "",
CliArtifacts: nil,
CliKubernetesManifests: nil,
SkipBuild: false,
SkipDeploy: false,
Force: false,
Analyze: false,
EnableJibInit: true,
EnableBuildpacksInit: false,
EnableNewInitFormat: true,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},
{
name: "enableBuildpackInit implies enableNewInitFormat",
args: []string{
"init",
"--XXenableBuildpacksInit",
},
expectedConfig: initializer.Config{
ComposeFile: "",
CliArtifacts: nil,
CliKubernetesManifests: nil,
SkipBuild: false,
SkipDeploy: false,
Force: false,
Analyze: false,
EnableJibInit: false,
EnableBuildpacksInit: true,
EnableNewInitFormat: true,
BuildpacksBuilder: "heroku/buildpacks",
Opts: opts,
},
},
}
for _, test := range tests {
testutil.Run(t, test.name, func(t *testutil.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/initializer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Config struct {
Analyze bool
EnableJibInit bool // TODO: Remove this parameter
EnableBuildpacksInit bool
EnableNewInitFormat bool
BuildpacksBuilder string
Opts config.SkaffoldOptions
}
Expand Down Expand Up @@ -109,8 +110,8 @@ func DoInit(ctx context.Context, out io.Writer, c Config) error {

if c.Analyze {
// TODO: Remove backwards compatibility block
if !c.EnableJibInit && !c.EnableBuildpacksInit {
return printAnalyzeJSONNoJib(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
if !c.EnableNewInitFormat {
return printAnalyzeOldFormat(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
}

return printAnalyzeJSON(out, c.SkipBuild, pairs, unresolvedBuilderConfigs, unresolvedImages)
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/initializer/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func TestDoInitAnalyze(t *testing.T) {
name: "analyze microservices new format",
dir: "testdata/init/microservices",
config: Config{
Analyze: true,
EnableJibInit: true,
Analyze: true,
EnableNewInitFormat: true,
},
expectedOut: strip(`{
"builders":[
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
)

func printAnalyzeJSONNoJib(out io.Writer, skipBuild bool, pairs []builderImagePair, unresolvedBuilders []InitBuilder, unresolvedImages []string) error {
func printAnalyzeOldFormat(out io.Writer, skipBuild bool, pairs []builderImagePair, unresolvedBuilders []InitBuilder, unresolvedImages []string) error {
if !skipBuild && len(unresolvedBuilders) == 0 {
return errors.New("one or more valid Dockerfiles must be present to build images with skaffold; please provide at least one Dockerfile and try again, or run `skaffold init --skip-build`")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestPrintAnalyzeJSONNoJib(t *testing.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
var out bytes.Buffer

err := printAnalyzeJSONNoJib(&out, test.skipBuild, test.pairs, test.builders, test.images)
err := printAnalyzeOldFormat(&out, test.skipBuild, test.pairs, test.builders, test.images)

t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, out.String())
})
Expand Down

0 comments on commit 12581fe

Please sign in to comment.