mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 17:49:10 +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,14 +7,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type buildOpts struct {
|
type buildOpts struct {
|
||||||
force bool
|
skipBuild bool
|
||||||
push bool
|
force bool
|
||||||
release string
|
push bool
|
||||||
|
release string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,34 +104,36 @@ func (p Pkg) Build(bos ...BuildOpt) error {
|
|||||||
fmt.Println("No image pulled, continuing with build")
|
fmt.Println("No image pulled, continuing with build")
|
||||||
}
|
}
|
||||||
|
|
||||||
var args []string
|
if !bo.skipBuild {
|
||||||
|
var args []string
|
||||||
|
|
||||||
if p.git != nil && p.gitRepo != "" {
|
if p.git != nil && p.gitRepo != "" {
|
||||||
args = append(args, "--label", "org.opencontainers.image.source="+p.gitRepo)
|
args = append(args, "--label", "org.opencontainers.image.source="+p.gitRepo)
|
||||||
}
|
}
|
||||||
if p.git != nil && !p.dirty {
|
if p.git != nil && !p.dirty {
|
||||||
commit, err := p.git.commitHash("HEAD")
|
commit, err := p.git.commitHash("HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
args = append(args, "--label", "org.opencontainers.image.revision="+commit)
|
||||||
}
|
}
|
||||||
args = append(args, "--label", "org.opencontainers.image.revision="+commit)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !p.network {
|
if !p.network {
|
||||||
args = append(args, "--network=none")
|
args = append(args, "--network=none")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil {
|
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 {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Build complete, not pushing, all done.\n")
|
if !bo.push {
|
||||||
return nil
|
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 {
|
if p.dirty {
|
||||||
|
Loading…
Reference in New Issue
Block a user