summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/api/handlers/compat/images_build.go14
-rw-r--r--test/python/docker/build_labels/Dockerfile1
-rw-r--r--test/python/docker/compat/test_images.py8
3 files changed, 20 insertions, 3 deletions
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go
index d79b100e8..2b84c9a25 100644
--- a/pkg/api/handlers/compat/images_build.go
+++ b/pkg/api/handlers/compat/images_build.go
@@ -221,9 +221,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
// convert label formats
var labels = []string{}
if _, found := r.URL.Query()["labels"]; found {
- if err := json.Unmarshal([]byte(query.Labels), &labels); err != nil {
- utils.BadRequest(w, "labels", query.Labels, err)
- return
+ makeLabels := make(map[string]string)
+ err := json.Unmarshal([]byte(query.Labels), &makeLabels)
+ if err == nil {
+ for k, v := range makeLabels {
+ labels = append(labels, k+"="+v)
+ }
+ } else {
+ if err := json.Unmarshal([]byte(query.Labels), &labels); err != nil {
+ utils.BadRequest(w, "labels", query.Labels, err)
+ return
+ }
}
}
jobs := 1
diff --git a/test/python/docker/build_labels/Dockerfile b/test/python/docker/build_labels/Dockerfile
new file mode 100644
index 000000000..f6e07066c
--- /dev/null
+++ b/test/python/docker/build_labels/Dockerfile
@@ -0,0 +1 @@
+FROM quay.io/libpod/alpine:latest
diff --git a/test/python/docker/compat/test_images.py b/test/python/docker/compat/test_images.py
index 842e38f31..4a90069a9 100644
--- a/test/python/docker/compat/test_images.py
+++ b/test/python/docker/compat/test_images.py
@@ -149,6 +149,14 @@ class TestImages(unittest.TestCase):
self.assertEqual(len(self.client.images.list()), 2)
+ def test_build_image(self):
+ labels = {"apple": "red", "grape": "green"}
+ _ = self.client.images.build(path="test/python/docker/build_labels", labels=labels, tag="labels")
+ image = self.client.images.get("labels")
+ self.assertEqual(image.labels["apple"], labels["apple"])
+ self.assertEqual(image.labels["grape"], labels["grape"])
+
+
if __name__ == "__main__":
# Setup temporary space