Merge branch 'fn-build-no-cache-support' into 'master'

Teach `fn build` `--no-cache` to avoid using cached steps

See merge request !114
This commit is contained in:
James Jeffrey
2017-07-20 09:54:14 -07:00
3 changed files with 25 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ func build() cli.Command {
type buildcmd struct { type buildcmd struct {
verbose bool verbose bool
noCache bool
} }
func (b *buildcmd) flags() []cli.Flag { func (b *buildcmd) flags() []cli.Flag {
@@ -29,6 +30,11 @@ func (b *buildcmd) flags() []cli.Flag {
Usage: "verbose mode", Usage: "verbose mode",
Destination: &b.verbose, Destination: &b.verbose,
}, },
cli.BoolFlag{
Name: "no-cache",
Usage: "Don't use docker cache",
Destination: &b.noCache,
},
} }
} }
@@ -45,7 +51,7 @@ func (b *buildcmd) build(c *cli.Context) error {
return err return err
} }
ff, err := buildfunc(verbwriter, fn) ff, err := buildfunc(verbwriter, fn, b.noCache)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -33,7 +33,7 @@ func verbwriter(verbose bool) io.Writer {
return verbwriter return verbwriter
} }
func buildfunc(verbwriter io.Writer, fn string) (*funcfile, error) { func buildfunc(verbwriter io.Writer, fn string, noCache bool) (*funcfile, error) {
funcfile, err := parsefuncfile(fn) funcfile, err := parsefuncfile(fn)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -57,7 +57,7 @@ func buildfunc(verbwriter io.Writer, fn string) (*funcfile, error) {
return nil, err return nil, err
} }
if err := dockerbuild(verbwriter, fn, funcfile); err != nil { if err := dockerbuild(verbwriter, fn, funcfile, noCache); err != nil {
return nil, err return nil, err
} }
@@ -78,7 +78,7 @@ func localbuild(verbwriter io.Writer, path string, steps []string) error {
return nil return nil
} }
func dockerbuild(verbwriter io.Writer, path string, ff *funcfile) error { func dockerbuild(verbwriter io.Writer, path string, ff *funcfile, noCache bool) error {
err := dockerVersionCheck() err := dockerVersionCheck()
if err != nil { if err != nil {
return err return err
@@ -115,13 +115,19 @@ func dockerbuild(verbwriter io.Writer, path string, ff *funcfile) error {
result := make(chan error, 1) result := make(chan error, 1)
go func(done chan<- error) { go func(done chan<- error) {
cmd := exec.Command("docker", "build", args := []string{
"build",
"-t", ff.FullName(), "-t", ff.FullName(),
"-f", dockerfile, "-f", dockerfile,
// "--no-cache", }
if noCache {
args = append(args, "--no-cache")
}
args = append(args,
"--build-arg", "HTTP_PROXY", "--build-arg", "HTTP_PROXY",
"--build-arg", "HTTPS_PROXY", "--build-arg", "HTTPS_PROXY",
".") ".")
cmd := exec.Command("docker", args...)
cmd.Dir = dir cmd.Dir = dir
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout

View File

@@ -39,6 +39,7 @@ type deploycmd struct {
verbose bool verbose bool
incremental bool incremental bool
skippush bool skippush bool
noCache bool
verbwriter io.Writer verbwriter io.Writer
} }
@@ -62,6 +63,11 @@ func (p *deploycmd) flags() []cli.Flag {
Usage: "uses incremental building", Usage: "uses incremental building",
Destination: &p.incremental, Destination: &p.incremental,
}, },
cli.BoolFlag{
Name: "no-cache",
Usage: "Don't use Docker cache for the build",
Destination: &p.noCache,
},
cli.BoolFlag{ cli.BoolFlag{
Name: "skip-push", Name: "skip-push",
Usage: "does not push Docker built images onto Docker Hub - useful for local development.", Usage: "does not push Docker built images onto Docker Hub - useful for local development.",
@@ -126,7 +132,7 @@ func (p *deploycmd) deploy(c *cli.Context, funcFilePath string) error {
return err return err
} }
funcfile, err := buildfunc(p.verbwriter, funcFileName) funcfile, err := buildfunc(p.verbwriter, funcFileName, p.noCache)
if err != nil { if err != nil {
return err return err
} }