diff --git a/config/build.go b/config/build.go index 2a0ad87..b70b9c9 100644 --- a/config/build.go +++ b/config/build.go @@ -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 @@ -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 } @@ -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 diff --git a/context/image.go b/context/image.go index 0e40764..6999ccb 100644 --- a/context/image.go +++ b/context/image.go @@ -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) diff --git a/image/build.go b/image/build.go index 2759ef8..43a47e7 100644 --- a/image/build.go +++ b/image/build.go @@ -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}) diff --git a/image/pull.go b/image/pull.go index 7c9fdd5..181f31e 100644 --- a/image/pull.go +++ b/image/pull.go @@ -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