Skip to content

Commit

Permalink
Make git tagger the default for both dev and run
Browse files Browse the repository at this point in the history
Fixes GoogleContainerTools#425

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Apr 27, 2018
1 parent 48b267c commit c7592d1
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 68 deletions.
8 changes: 4 additions & 4 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func SetUpLogs(out io.Writer, level string) error {
return nil
}

func readConfiguration(filename string, dev bool) (*config.SkaffoldConfig, error) {
func readConfiguration(filename string) (*config.SkaffoldConfig, error) {
buf, err := util.ReadConfiguration(filename)
if err != nil {
return nil, errors.Wrap(err, "read skaffold config")
Expand All @@ -104,7 +104,7 @@ func readConfiguration(filename string, dev bool) (*config.SkaffoldConfig, error
return nil, errors.New("Config version out of date: run `skaffold fix`")
}

cfg, err := config.GetConfig(buf, true, dev)
cfg, err := config.GetConfig(buf, true)
if err != nil {
return nil, errors.Wrap(err, "parsing skaffold config")
}
Expand All @@ -121,12 +121,12 @@ func readConfiguration(filename string, dev bool) (*config.SkaffoldConfig, error
return latestConfig, nil
}

func runSkaffold(out io.Writer, dev bool, filename string, action func(context.Context, *runner.SkaffoldRunner) error) error {
func runSkaffold(out io.Writer, filename string, action func(context.Context, *runner.SkaffoldRunner) error) error {
ctx := context.Background()

opts.Output = out

config, err := readConfiguration(filename, dev)
config, err := readConfiguration(filename)
if err != nil {
return errors.Wrap(err, "reading configuration")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewCmdDev(out io.Writer) *cobra.Command {
Short: "Runs a pipeline file in development mode",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runSkaffold(out, true, filename, func(ctx context.Context, r *runner.SkaffoldRunner) error {
return runSkaffold(out, filename, func(ctx context.Context, r *runner.SkaffoldRunner) error {
return r.Dev(ctx)
})
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewCmdFix(out io.Writer) *cobra.Command {
if err != nil {
logrus.Errorf("fix: %s", err)
}
cfg, err := config.GetConfig(contents, false, true)
cfg, err := config.GetConfig(contents, false)
if err != nil {
logrus.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewCmdRun(out io.Writer) *cobra.Command {
Short: "Runs a pipeline file",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runSkaffold(out, false, filename, func(ctx context.Context, r *runner.SkaffoldRunner) error {
return runSkaffold(out, filename, func(ctx context.Context, r *runner.SkaffoldRunner) error {
return r.Run(ctx)
})
},
Expand Down
47 changes: 4 additions & 43 deletions pkg/skaffold/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,22 @@ func TestParseConfig(t *testing.T) {
var tests = []struct {
description string
config string
dev bool
expected util.VersionedConfig
badReader bool
shouldErr bool
}{
{
description: "Minimal config for dev",
description: "Minimal config",
config: minimalConfig,
dev: true,
expected: config(
withLocalBuild(
withTagPolicy(v1alpha2.TagPolicy{ShaTagger: &v1alpha2.ShaTagger{}}),
),
),
},
{
description: "Minimal config for run",
config: minimalConfig,
dev: false,
expected: config(
withLocalBuild(
withTagPolicy(v1alpha2.TagPolicy{GitTagger: &v1alpha2.GitTagger{}}),
),
),
},
{
description: "Simple config for dev",
description: "Simple config",
config: simpleConfig,
dev: true,
expected: config(
withLocalBuild(
withTagPolicy(v1alpha2.TagPolicy{ShaTagger: &v1alpha2.ShaTagger{}}),
withDockerArtifact("example", ".", "Dockerfile"),
),
withDeploy("example"),
),
},
{
description: "Simple config for run",
config: simpleConfig,
dev: false,
expected: config(
withLocalBuild(
withTagPolicy(v1alpha2.TagPolicy{GitTagger: &v1alpha2.GitTagger{}}),
Expand All @@ -115,22 +90,8 @@ func TestParseConfig(t *testing.T) {
),
},
{
description: "Complete config for dev",
config: completeConfig,
dev: true,
expected: config(
withGCBBuild("ID",
withTagPolicy(v1alpha2.TagPolicy{ShaTagger: &v1alpha2.ShaTagger{}}),
withDockerArtifact("image1", "./examples/app1", "Dockerfile.dev"),
withBazelArtifact("image2", "./examples/app2", "//:example.tar"),
),
withDeploy("example"),
),
},
{
description: "Complete config for run",
description: "Complete config",
config: completeConfig,
dev: false,
expected: config(
withGCBBuild("ID",
withTagPolicy(v1alpha2.TagPolicy{ShaTagger: &v1alpha2.ShaTagger{}}),
Expand All @@ -149,7 +110,7 @@ func TestParseConfig(t *testing.T) {

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
cfg, err := GetConfig([]byte(test.config), true, test.dev)
cfg, err := GetConfig([]byte(test.config), true)
testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, test.expected, cfg)
})
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/skaffold/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ import (
// Ordered list of all schema versions
var Versions = []string{v1alpha1.Version, v1alpha2.Version}

var schemaVersions map[string]func([]byte, bool, bool) (util.VersionedConfig, error) = map[string]func([]byte, bool, bool) (util.VersionedConfig, error){
v1alpha1.Version: func(contents []byte, useDefault bool, dev bool) (util.VersionedConfig, error) {
var schemaVersions = map[string]func([]byte, bool) (util.VersionedConfig, error){
v1alpha1.Version: func(contents []byte, useDefault bool) (util.VersionedConfig, error) {
config := new(v1alpha1.SkaffoldConfig)
err := config.Parse(contents, useDefault, dev)
err := config.Parse(contents, useDefault)
return config, err
},
v1alpha2.Version: func(contents []byte, useDefault bool, dev bool) (util.VersionedConfig, error) {
v1alpha2.Version: func(contents []byte, useDefault bool) (util.VersionedConfig, error) {
config := new(v1alpha2.SkaffoldConfig)
err := config.Parse(contents, useDefault, dev)
err := config.Parse(contents, useDefault)
return config, err
},
}

func GetConfig(contents []byte, useDefault bool, dev bool) (util.VersionedConfig, error) {
func GetConfig(contents []byte, useDefault bool) (util.VersionedConfig, error) {
for _, version := range Versions {
if cfg, err := schemaVersions[version](contents, useDefault, dev); err == nil {
if cfg, err := schemaVersions[version](contents, useDefault); err == nil {
// successfully parsed, but make sure versions match
if cfg.GetVersion() == version {
return cfg, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package util

type VersionedConfig interface {
GetVersion() string
Parse([]byte, bool, bool) error
Parse([]byte, bool) error
}

type Config interface {
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/schema/v1alpha1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ var defaultRunSkaffoldConfig = &SkaffoldConfig{
// Parse reads from an io.Reader and unmarshals the result into a SkaffoldConfig.
// The default config argument provides default values for the config,
// which can be overridden if present in the config file.
func (config *SkaffoldConfig) Parse(contents []byte, useDefault bool, mode bool) error {
func (config *SkaffoldConfig) Parse(contents []byte, useDefault bool) error {
if useDefault {
*config = *config.getDefaultForMode(mode)
*config = *config.getDefaultForMode(false)
} else {
*config = SkaffoldConfig{}
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/skaffold/schema/v1alpha2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,12 @@ func defaultToDockerArtifacts(cfg *SkaffoldConfig) {
}
}

func setDefaultTagger(cfg *SkaffoldConfig, dev bool) {
func setDefaultTagger(cfg *SkaffoldConfig) {
if cfg.Build.TagPolicy != (TagPolicy{}) {
return
}

if dev {
cfg.Build.TagPolicy = TagPolicy{ShaTagger: &ShaTagger{}}
} else {
cfg.Build.TagPolicy = TagPolicy{GitTagger: &GitTagger{}}
}
cfg.Build.TagPolicy = TagPolicy{GitTagger: &GitTagger{}}
}

func setDefaultDockerfiles(cfg *SkaffoldConfig) {
Expand Down Expand Up @@ -248,14 +244,14 @@ func profilesByName(profiles []Profile) map[string]Profile {
return byName
}

func (config *SkaffoldConfig) Parse(contents []byte, useDefaults bool, mode bool) error {
func (config *SkaffoldConfig) Parse(contents []byte, useDefaults bool) error {
if err := yaml.Unmarshal(contents, config); err != nil {
return err
}
if useDefaults {
defaultToLocalBuild(config)
defaultToDockerArtifacts(config)
setDefaultTagger(config, mode)
setDefaultTagger(config)
setDefaultDockerfiles(config)
setDefaultWorkspaces(config)
}
Expand Down

0 comments on commit c7592d1

Please sign in to comment.