mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 01:29:07 +00:00
Merge pull request #2772 from ijc/linuxkit-pkg-push-no-build
linuxkit pkg: allow skipping build before push
This commit is contained in:
commit
c003d0c44f
@ -21,6 +21,7 @@ func pkgPush(args []string) {
|
|||||||
|
|
||||||
force := flags.Bool("force", false, "Force rebuild")
|
force := flags.Bool("force", false, "Force rebuild")
|
||||||
release := flags.String("release", "", "Release the given version")
|
release := flags.String("release", "", "Release the given version")
|
||||||
|
nobuild := flags.Bool("nobuild", false, "Skip the build")
|
||||||
|
|
||||||
p, err := pkglib.NewFromCLI(flags, args...)
|
p, err := pkglib.NewFromCLI(flags, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -32,16 +33,24 @@ func pkgPush(args []string) {
|
|||||||
setupContentTrustPassphrase()
|
setupContentTrustPassphrase()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Building and pushing %q\n", p.Tag())
|
|
||||||
|
|
||||||
var opts []pkglib.BuildOpt
|
var opts []pkglib.BuildOpt
|
||||||
opts = append(opts, pkglib.WithBuildPush())
|
opts = append(opts, pkglib.WithBuildPush())
|
||||||
if *force {
|
if *force {
|
||||||
opts = append(opts, pkglib.WithBuildForce())
|
opts = append(opts, pkglib.WithBuildForce())
|
||||||
}
|
}
|
||||||
|
if *nobuild {
|
||||||
|
opts = append(opts, pkglib.WithBuildSkip())
|
||||||
|
}
|
||||||
if *release != "" {
|
if *release != "" {
|
||||||
opts = append(opts, pkglib.WithRelease(*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 {
|
if err := p.Build(opts...); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type buildOpts struct {
|
type buildOpts struct {
|
||||||
|
skipBuild bool
|
||||||
force bool
|
force bool
|
||||||
push bool
|
push bool
|
||||||
release string
|
release string
|
||||||
@ -15,6 +16,14 @@ type buildOpts struct {
|
|||||||
// BuildOpt allows callers to specify options to Build
|
// BuildOpt allows callers to specify options to Build
|
||||||
type BuildOpt func(bo *buildOpts) error
|
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
|
// WithBuildForce forces a build even if an image already exists
|
||||||
func WithBuildForce() BuildOpt {
|
func WithBuildForce() BuildOpt {
|
||||||
return func(bo *buildOpts) error {
|
return func(bo *buildOpts) error {
|
||||||
@ -95,6 +104,7 @@ func (p Pkg) Build(bos ...BuildOpt) error {
|
|||||||
fmt.Println("No image pulled, continuing with build")
|
fmt.Println("No image pulled, continuing with build")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !bo.skipBuild {
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
if p.git != nil && p.gitRepo != "" {
|
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")
|
fmt.Printf("Build complete, not pushing, all done.\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if p.dirty {
|
if p.dirty {
|
||||||
return fmt.Errorf("build complete, refusing to push dirty package")
|
return fmt.Errorf("build complete, refusing to push dirty package")
|
||||||
|
Loading…
Reference in New Issue
Block a user