grim/convey

e81e4e5b9d2f
Parents 10deaf1107c4
Children d6d02e624801
Support multiple tags for docker build command.
--- a/REFERENCE.md Mon Sep 25 21:10:12 2017 -0500
+++ b/REFERENCE.md Tue Sep 26 09:51:15 2017 -0500
@@ -46,7 +46,7 @@
This example shows how to expand an environment variable into a list in the context of a extended task.
## login-logout.yml
-
+
This example shows how you can login and logout of a Docker registry by using environment variables.
## script.yml
@@ -178,7 +178,11 @@
| dockerfile | Yes | | The dockerfile to use while building |
| files | | | A list of files that should be made available for the build |
| labels | | | A list of labels to set on the image being built |
-| tag | Yes | | The tag to apply to the image |
+| tag | | | The tag to apply to the image |
+| tags | | | The list of tags as described above |
+
+At least one tag must be supplied by either the `tag` or `tags` attribute. If both are
+supplied, `tag` is inserted to the front of `tags`.
#### Example
--- a/docker/build.go Mon Sep 25 21:10:12 2017 -0500
+++ b/docker/build.go Tue Sep 26 09:51:15 2017 -0500
@@ -18,6 +18,7 @@
package docker
import (
+ "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -34,13 +35,14 @@
Dockerfile string `yaml:"dockerfile"`
Files yaml.StringOrSlice `yaml:"files"`
Tag string `yaml:"tag"`
+ Tags yaml.StringOrSlice `yaml:"tags"`
Labels yaml.StringOrSlice `yaml:"labels"`
Arguments yaml.StringOrSlice `yaml:"arguments"`
}
const buildTemplate = `build
-f {{.dockerfile}}
-{{if .tag}} -t {{.tag}}{{end}}
+{{range .Tags}} -t {{.}}{{end}}
{{range .Labels}} --label '{{.}}'{{end}}
{{range .Arguments}} --build-arg {{.}}{{end}}
{{.buildContext}}`
@@ -80,15 +82,16 @@
"workspace": st.Workspace.Name(),
}
- err = Docker(name, exportTemplate, params, st)
+ if err := Docker(name, exportTemplate, params, st); err != nil {
+ return err
+ }
+
+ tags, err := st.MapSlice(b.Tags, fullEnv)
if err != nil {
return err
}
- tag, err := environment.Mapper(b.Tag, fullEnv)
- if err != nil {
- return err
- }
+ fmt.Printf("Tags: %#v :: %#v\n", b.Tags, tags)
labels, err := st.MapSlice(b.Labels, fullEnv)
if err != nil {
@@ -103,8 +106,8 @@
// now run the build
params = map[string]interface{}{
"dockerfile": filepath.Join(tmpDir, filepath.Base(b.Dockerfile)),
- "tag": tag,
"buildContext": tmpDir,
+ "Tags": tags,
"Labels": labels,
"Arguments": arguments,
}
@@ -121,7 +124,11 @@
return errNoDockerFile
}
- if b.Tag == "" {
+ if b.Tag != "" {
+ b.Tags = append([]string{b.Tag}, b.Tags...)
+ }
+
+ if len(b.Tags) == 0 {
return errNoTag
}