Skip to content

Commit

Permalink
pull/build only when necessary, and fix flags
Browse files Browse the repository at this point in the history
  • Loading branch information
oclaussen committed Apr 5, 2018
1 parent 6911b47 commit c75eed0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
14 changes: 10 additions & 4 deletions config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

// TODO: add inline dockerfile steps
type BuildConfig struct {
Context string
Dockerfile string
Args map[string]*string
NoCache bool
Context string
Dockerfile string
Args map[string]*string
NoCache bool
ForceRebuild bool
}

// TODO: clean up, this is copied from libcompose
Expand All @@ -31,6 +32,9 @@ func (b BuildConfig) MarshalYAML() (interface{}, error) {
if b.NoCache {
m["cache"] = false
}
if b.ForceRebuild {
m["force_rebuild"] = true
}
return m, nil
}

Expand All @@ -57,6 +61,8 @@ func (b *BuildConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
b.Args = args
case "cache":
b.NoCache = !mapValue.(bool)
case "force_rebuild":
b.ForceRebuild = mapValue.(bool)
default:
// Ignore unknown keys
continue
Expand Down
1 change: 0 additions & 1 deletion context/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func (context *Context) ensureImage() error {
if err := context.ensureClient(); err != nil {
return err;
}
// TODO: check if pulling/building is necessary, implement force pull

if context.Config.Build != nil {
image, err := image.BuildImage(context.Client, context.Config)
Expand Down
10 changes: 10 additions & 0 deletions image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import (
)

func BuildImage(client *docker.Client, config *config.ContextConfig) (string, error) {
if config.Image != "" && !config.Build.ForceRebuild {
images, err := client.ListImages(docker.ListImagesOptions{
Filter: config.Image,
})
if err == nil && len(images) > 0 {
// TODO: log error
return config.Image, nil
}
}

args := []docker.BuildArg{}
for key, value := range config.Build.Args {
args = append(args, docker.BuildArg{Name: key, Value: *value})
Expand Down
11 changes: 10 additions & 1 deletion image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ import (
)

func PullImage(client *docker.Client, config *config.ContextConfig) (string, error) {
// TODO: validate that the image is actually normalized named
if !config.Pull {
images, err := client.ListImages(docker.ListImagesOptions{
Filter: config.Image,
})
if err == nil && len(images) > 0 {
// TODO: log error
return config.Image, nil
}
}

ref, err := reference.ParseNormalizedNamed(config.Image)
if err != nil {
return "", err
Expand Down

0 comments on commit c75eed0

Please sign in to comment.