Merge pull request #2772 from ijc/linuxkit-pkg-push-no-build

linuxkit pkg: allow skipping build before push
This commit is contained in:
Ian Campbell 2017-11-24 13:51:49 +00:00 committed by GitHub
commit c003d0c44f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,14 +7,23 @@ import (
)
type buildOpts struct {
force bool
push bool
release string
skipBuild bool
force bool
push bool
release string
}
// 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,34 +104,36 @@ func (p Pkg) Build(bos ...BuildOpt) error {
fmt.Println("No image pulled, continuing with build")
}
var args []string
if !bo.skipBuild {
var args []string
if p.git != nil && p.gitRepo != "" {
args = append(args, "--label", "org.opencontainers.image.source="+p.gitRepo)
}
if p.git != nil && !p.dirty {
commit, err := p.git.commitHash("HEAD")
if err != nil {
return err
if p.git != nil && p.gitRepo != "" {
args = append(args, "--label", "org.opencontainers.image.source="+p.gitRepo)
}
if p.git != nil && !p.dirty {
commit, err := p.git.commitHash("HEAD")
if err != nil {
return err
}
args = append(args, "--label", "org.opencontainers.image.revision="+commit)
}
args = append(args, "--label", "org.opencontainers.image.revision="+commit)
}
if !p.network {
args = append(args, "--network=none")
}
if !p.network {
args = append(args, "--network=none")
}
if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil {
return err
}
if !bo.push {
if err := d.tag(p.Tag()+suffix, p.Tag()); err != nil {
if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil {
return err
}
fmt.Printf("Build complete, not pushing, all done.\n")
return nil
if !bo.push {
if err := d.tag(p.Tag()+suffix, p.Tag()); err != nil {
return err
}
fmt.Printf("Build complete, not pushing, all done.\n")
return nil
}
}
if p.dirty {