Skip to content

Commit

Permalink
Merge pull request #9550 from baude/issue9517
Browse files Browse the repository at this point in the history
Support label type dict on compat build
  • Loading branch information
openshift-merge-robot authored Mar 4, 2021
2 parents 7b76340 + 2c8c539 commit 7a92de4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,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
Expand Down
1 change: 1 addition & 0 deletions test/python/docker/build_labels/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM quay.io/libpod/alpine:latest
8 changes: 8 additions & 0 deletions test/python/docker/compat/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def test_load_image(self):

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
Expand Down

0 comments on commit 7a92de4

Please sign in to comment.