linuxkit pkg: allow skipping build before push

If doing the build separately from pushing (as I am intending in
https://github.com/linuxkit/kubernetes/pull/8/) it is desirable to avoid a
second build when pushing.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell 2017-11-24 09:47:38 +00:00
parent 61ce897d72
commit ae53577078
2 changed files with 46 additions and 26 deletions

View File

@ -21,6 +21,7 @@ func pkgPush(args []string) {
force := flags.Bool("force", false, "Force rebuild")
release := flags.String("release", "", "Release the given version")
nobuild := flags.Bool("nobuild", false, "Skip the build")
p, err := pkglib.NewFromCLI(flags, args...)
if err != nil {
@ -32,16 +33,24 @@ func pkgPush(args []string) {
setupContentTrustPassphrase()
}
fmt.Printf("Building and pushing %q\n", p.Tag())
var opts []pkglib.BuildOpt
opts = append(opts, pkglib.WithBuildPush())
if *force {
opts = append(opts, pkglib.WithBuildForce())
}
if *nobuild {
opts = append(opts, pkglib.WithBuildSkip())
}
if *release != "" {
opts = append(opts, pkglib.WithRelease(*release))
}
if *nobuild {
fmt.Printf("Pushing %q without building\n", p.Tag())
} else {
fmt.Printf("Building and pushing %q\n", p.Tag())
}
if err := p.Build(opts...); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)

View File

@ -7,6 +7,7 @@ import (
)
type buildOpts struct {
skipBuild bool
force bool
push bool
release string
@ -15,6 +16,14 @@ type buildOpts struct {
// BuildOpt allows callers to specify options to Build
type BuildOpt func(bo *buildOpts) error
// WithBuildSkip skips the actual build and only pushes/releases (if configured)
func WithBuildSkip() BuildOpt {
return func(bo *buildOpts) error {
bo.skipBuild = true
return nil
}
}
// WithBuildForce forces a build even if an image already exists
func WithBuildForce() BuildOpt {
return func(bo *buildOpts) error {
@ -95,6 +104,7 @@ func (p Pkg) Build(bos ...BuildOpt) error {
fmt.Println("No image pulled, continuing with build")
}
if !bo.skipBuild {
var args []string
if p.git != nil && p.gitRepo != "" {
@ -124,6 +134,7 @@ func (p Pkg) Build(bos ...BuildOpt) error {
fmt.Printf("Build complete, not pushing, all done.\n")
return nil
}
}
if p.dirty {
return fmt.Errorf("build complete, refusing to push dirty package")