mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
@@ -20,6 +20,7 @@ func build() cli.Command {
|
||||
|
||||
type buildcmd struct {
|
||||
verbose bool
|
||||
noCache bool
|
||||
}
|
||||
|
||||
func (b *buildcmd) flags() []cli.Flag {
|
||||
@@ -29,6 +30,11 @@ func (b *buildcmd) flags() []cli.Flag {
|
||||
Usage: "verbose mode",
|
||||
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
|
||||
}
|
||||
|
||||
ff, err := buildfunc(verbwriter, fn)
|
||||
ff, err := buildfunc(verbwriter, fn, b.noCache)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
16
fn/common.go
16
fn/common.go
@@ -33,7 +33,7 @@ func verbwriter(verbose bool) io.Writer {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -57,7 +57,7 @@ func buildfunc(verbwriter io.Writer, fn string) (*funcfile, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := dockerbuild(verbwriter, fn, funcfile); err != nil {
|
||||
if err := dockerbuild(verbwriter, fn, funcfile, noCache); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func localbuild(verbwriter io.Writer, path string, steps []string) error {
|
||||
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()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -115,13 +115,19 @@ func dockerbuild(verbwriter io.Writer, path string, ff *funcfile) error {
|
||||
result := make(chan error, 1)
|
||||
|
||||
go func(done chan<- error) {
|
||||
cmd := exec.Command("docker", "build",
|
||||
args := []string{
|
||||
"build",
|
||||
"-t", ff.FullName(),
|
||||
"-f", dockerfile,
|
||||
// "--no-cache",
|
||||
}
|
||||
if noCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args,
|
||||
"--build-arg", "HTTP_PROXY",
|
||||
"--build-arg", "HTTPS_PROXY",
|
||||
".")
|
||||
cmd := exec.Command("docker", args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
@@ -39,6 +39,7 @@ type deploycmd struct {
|
||||
verbose bool
|
||||
incremental bool
|
||||
skippush bool
|
||||
noCache bool
|
||||
|
||||
verbwriter io.Writer
|
||||
}
|
||||
@@ -62,6 +63,11 @@ func (p *deploycmd) flags() []cli.Flag {
|
||||
Usage: "uses incremental building",
|
||||
Destination: &p.incremental,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-cache",
|
||||
Usage: "Don't use Docker cache for the build",
|
||||
Destination: &p.noCache,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-push",
|
||||
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
|
||||
}
|
||||
|
||||
funcfile, err := buildfunc(p.verbwriter, funcFileName)
|
||||
funcfile, err := buildfunc(p.verbwriter, funcFileName, p.noCache)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user