diff --git a/commands/build.go b/commands/build.go index e0a04d4c..7556da24 100644 --- a/commands/build.go +++ b/commands/build.go @@ -82,7 +82,7 @@ func (b *buildcmd) build(c *cli.Context) error { } buildArgs := c.StringSlice("build-arg") - ff, err = common.BuildFuncV20180708(c.GlobalBool("verbose"), fpath, ff, buildArgs, b.noCache) + ff, err = common.BuildFuncV20180708(buildArgs, c.GlobalBool("verbose"), b.noCache, fpath, ff) if err != nil { return err } @@ -97,7 +97,9 @@ func (b *buildcmd) build(c *cli.Context) error { } buildArgs := c.StringSlice("build-arg") - ff, err = common.BuildFunc(c.GlobalBool("verbose"), fpath, ff, buildArgs, b.noCache) + verbpse := c.GlobalBool("verbose") + + ff, err = common.BuildFunc(buildArgs, verbpse, b.noCache, fpath, ff) if err != nil { return err } diff --git a/commands/deploy.go b/commands/deploy.go index 7afc255e..fc1e66a0 100644 --- a/commands/deploy.go +++ b/commands/deploy.go @@ -139,26 +139,33 @@ func (p *deploycmd) deploy(c *cli.Context) error { return errors.New("App name must be provided, try `--app APP_NAME`") } - buildArgs := c.StringSlice("build-arg") - verbose := c.GlobalBool("verbose") - noBump := p.noBump - isLocal := p.local - noCache := p.noCache + deployConfig := &DeployConfig{ + c.StringSlice("build-arg"), + c.GlobalBool("verbose"), + p.noBump, + p.local, + p.noCache} + appDir := c.String("dir") if p.all { - return DeployAll( - p.client, buildArgs, - verbose, noBump, - isLocal, noCache, - appDir, appName, appf) + return DeployAll(p.client, deployConfig, appDir, appName, appf) } - return p.deploySingle(c, appName, appf) + + return p.deploySingle(c, deployConfig, appName, appf) +} + +type DeployConfig struct { + BuildArgs []string + Verbose bool + NoBump bool + IsLocal bool + NoCache bool } // deploySingle deploys a single function, either the current directory or if in the context // of an app and user provides relative path as the first arg, it will deploy that function. -func (p *deploycmd) deploySingle(c *cli.Context, appName string, appf *common.AppFile) error { +func (p *deploycmd) deploySingle(c *cli.Context, deployConfig *DeployConfig, appName string, appf *common.AppFile) error { var dir string wd := common.GetWd() @@ -175,14 +182,7 @@ func (p *deploycmd) deploySingle(c *cli.Context, appName string, appf *common.Ap dir = filepath.Join(wd, fpath) } - buildArgs := c.StringSlice("build-arg") - verbose := c.GlobalBool("verbose") - noBump := p.noBump - isLocal := p.local - noCache := p.noCache - - return DeploySingle(p.client, p.clientV2, buildArgs, verbose, - noBump, isLocal, noCache, dir, appName, appf) + return DeploySingle(p.client, p.clientV2, deployConfig, dir, appName, appf) } func setRootFuncInfo(ff *common.FuncFile, appName string) { diff --git a/commands/deploy_api.go b/commands/deploy_api.go index 6164e2f4..3f55e08a 100644 --- a/commands/deploy_api.go +++ b/commands/deploy_api.go @@ -12,7 +12,7 @@ import ( v2Client "github.com/fnproject/fn_go/clientv2" ) -func DeploySingle(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, buildArgs []string, verbose bool, noBump, isLocal, noCache bool, dir, appName string, appf *common.AppFile) error { +func DeploySingle(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, deployConfig *DeployConfig, dir, appName string, appf *common.AppFile) error { wd := common.GetWd() err := os.Chdir(dir) @@ -45,8 +45,7 @@ func DeploySingle(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, buildArgs []stri } } - return DeployFuncV20180708(clientV1, clientV2, buildArgs, verbose, noBump, - isLocal, noCache, appName, fpath, ff) + return DeployFuncV20180708(clientV1, clientV2, deployConfig, appName, fpath, ff) default: fpath, ff, err := common.FindAndParseFuncfile(dir) if err != nil { @@ -65,11 +64,11 @@ func DeploySingle(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, buildArgs []stri } } - return DeployFunc(clientV1, buildArgs, verbose, noBump, isLocal, noCache, appName, fpath, ff) + return DeployFunc(clientV1, deployConfig, appName, fpath, ff) } } -func DeployAll(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, isLocal, noCache bool, appDir, appName string, appf *common.AppFile) error { +func DeployAll(client *fnclient.Fn, deployConfig *DeployConfig, appDir, appName string, appf *common.AppFile) error { if appf != nil { err := UpdateAppConfig(client, appf) if err != nil { @@ -111,7 +110,7 @@ func DeployAll(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, is } } - err = DeployFunc(client, buildArgs, verbose, noBump, isLocal, noCache, appName, path, ff) + err = DeployFunc(client, deployConfig, appName, path, ff) if err != nil { return fmt.Errorf("deploy error on %s: %v", path, err) } @@ -132,7 +131,7 @@ func DeployAll(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, is // Parse func.yaml file, bump version, build image, push to registry, and // finally it will update function's route. Optionally, // the route can be overriden inside the func.yaml file. -func DeployFunc(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, isLocal, noCache bool, appName, funcfilePath string, funcfile *common.FuncFile) error { +func DeployFunc(client *fnclient.Fn, deployConfig *DeployConfig, appName, funcfilePath string, funcfile *common.FuncFile) error { dir := filepath.Dir(funcfilePath) // get name from directory if it's not defined if funcfile.Name == "" { @@ -148,7 +147,7 @@ func DeployFunc(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, i } var err error - if !noBump { + if !deployConfig.NoBump { funcfile2, err := common.BumpIt(funcfilePath, common.Patch) if err != nil { return err @@ -158,13 +157,13 @@ func DeployFunc(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, i } // p.noCache - _, err = common.BuildFunc(verbose, funcfilePath, funcfile, buildArgs, noCache) + _, err = common.BuildFunc(deployConfig.BuildArgs, deployConfig.Verbose, deployConfig.NoCache, funcfilePath, funcfile) if err != nil { return err } // p.local - if !isLocal { + if !deployConfig.IsLocal { if err := common.DockerPush(funcfile); err != nil { return err } @@ -173,13 +172,13 @@ func DeployFunc(client *fnclient.Fn, buildArgs []string, verbose bool, noBump, i return updateRoute(client, appName, funcfile) } -func DeployFuncV20180708(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, buildArgs []string, verbose bool, noBump, isLocal, noCache bool, appName, funcfilePath string, funcfile *common.FuncFileV20180708) error { +func DeployFuncV20180708(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, deployConfig *DeployConfig, appName, funcfilePath string, funcfile *common.FuncFileV20180708) error { if funcfile.Name == "" { funcfile.Name = filepath.Base(filepath.Dir(funcfilePath)) // todo: should probably make a copy of ff before changing it } var err error - if !noBump { + if !deployConfig.NoBump { funcfile2, err := common.BumpItV20180708(funcfilePath, common.Patch) if err != nil { return err @@ -188,12 +187,13 @@ func DeployFuncV20180708(clientV1 *fnclient.Fn, clientV2 *v2Client.Fn, buildArgs // TODO: this whole funcfile handling needs some love, way too confusing. Only bump makes permanent changes to it. } - _, err = common.BuildFuncV20180708(verbose, funcfilePath, funcfile, buildArgs, noCache) + _, err = common.BuildFuncV20180708(deployConfig.BuildArgs, deployConfig.Verbose, + deployConfig.NoCache, funcfilePath, funcfile) if err != nil { return err } - if !isLocal { + if !deployConfig.IsLocal { if err := common.DockerPushV20180708(funcfile); err != nil { return err } diff --git a/common/common.go b/common/common.go index a766e722..318a9085 100644 --- a/common/common.go +++ b/common/common.go @@ -56,7 +56,7 @@ func GetDir(c *cli.Context) string { } // BuildFunc bumps version and builds function. -func BuildFunc(verbose bool, fpath string, funcfile *FuncFile, buildArg []string, noCache bool) (*FuncFile, error) { +func BuildFunc(buildArg []string, verbose, noCache bool, fpath string, funcfile *FuncFile) (*FuncFile, error) { var err error if funcfile.Version == "" { funcfile, err = BumpIt(fpath, Patch) @@ -77,7 +77,7 @@ func BuildFunc(verbose bool, fpath string, funcfile *FuncFile, buildArg []string } // BuildFunc bumps version and builds function. -func BuildFuncV20180708(verbose bool, fpath string, funcfile *FuncFileV20180708, buildArg []string, noCache bool) (*FuncFileV20180708, error) { +func BuildFuncV20180708(buildArg []string, verbose, noCache bool, fpath string, funcfile *FuncFileV20180708) (*FuncFileV20180708, error) { var err error if funcfile.Version == "" { diff --git a/run/run.go b/run/run.go index 9d320fff..6e9d7690 100644 --- a/run/run.go +++ b/run/run.go @@ -146,7 +146,10 @@ func PreRun(c *cli.Context) (string, *common.FuncFile, []string, error) { } buildArgs := c.StringSlice("build-arg") - _, err = common.BuildFunc(c.GlobalBool("verbose"), fpath, ff, buildArgs, c.Bool("no-cache")) + verbose := c.GlobalBool("verbose") + noCache := c.Bool("no-cache") + + _, err = common.BuildFunc(buildArgs, verbose, noCache, fpath, ff) if err != nil { return fpath, nil, nil, err } @@ -207,7 +210,10 @@ func PreRunV20180708(c *cli.Context) (string, *common.FuncFileV20180708, []strin } buildArgs := c.StringSlice("build-arg") - _, err = common.BuildFuncV20180708(c.GlobalBool("verbose"), fpath, ff, buildArgs, c.Bool("no-cache")) + verbose := c.GlobalBool("verbose") + noCache := c.Bool("no-cache") + + _, err = common.BuildFuncV20180708(buildArgs, verbose, noCache, fpath, ff) if err != nil { return fpath, nil, nil, err }