mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 01:29:07 +00:00
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:
parent
61ce897d72
commit
ae53577078
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user