Skip to content

Commit

Permalink
add support for preserving the container on exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouthworth committed Nov 20, 2019
1 parent 42cfdf5 commit b697bc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions buildimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Builder struct {
srcDir string
pkgDir string

cleanContainer bool

containerID string
}

Expand Down Expand Up @@ -62,9 +64,16 @@ func PreferredPackageDirectory(pkgDir string) MakeBuilderOption {
}
}

func RemoveContainer(remove bool) MakeBuilderOption {
return func(b *Builder) {
b.cleanContainer = remove
}
}

func MakeBuilder(opts ...MakeBuilderOption) (*Builder, error) {
b := new(Builder)
b.version = "latest"
b.cleanContainer = true
for _, opt := range opts {
opt(b)
}
Expand Down Expand Up @@ -184,6 +193,10 @@ func (b *Builder) deleteEnvironment() error {
if b.containerID == "" {
return nil
}
if !b.cleanContainer {
log.Println("preserved environment", b.containerID)
return nil
}
log.Println("deleting environment", b.containerID)
return b.cli.ContainerRemove(
b.ctx,
Expand Down
3 changes: 3 additions & 0 deletions cmd/danos-buildimage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

var srcDir, destDir, pkgDir, version string
var noClean bool

func init() {
flag.StringVar(&srcDir, "src", "", "source directory")
flag.StringVar(&destDir, "dest", "..", "destination directory")
flag.StringVar(&pkgDir, "pkg", "", "preferred package directory")
flag.StringVar(&version, "version", "latest", "version of danos to build for")
flag.BoolVar(&noClean, "no-clean", false, "don't delete the container when done")
}

func resolvePath(in string) string {
Expand All @@ -36,6 +38,7 @@ func main() {
bimg.SourceDirectory(resolvePath(srcDir)),
bimg.DestinationDirectory(resolvePath(destDir)),
bimg.PreferredPackageDirectory(resolvePath(pkgDir)),
bimg.RemoveContainer(!noClean),
bimg.Version(version),
)
if err != nil {
Expand Down

0 comments on commit b697bc5

Please sign in to comment.