Support label type dict on compat build
The compatibility endpoint for build labels should be of type dict (not list). For backwards compatibility, we support both. Fixes: #9517 Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
		
							parent
							
								
									7497dcba6c
								
							
						
					
					
						commit
						2c8c5393a4
					
				| 
						 | 
				
			
			@ -221,11 +221,19 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
 | 
			
		|||
	// convert label formats
 | 
			
		||||
	var labels = []string{}
 | 
			
		||||
	if _, found := r.URL.Query()["labels"]; found {
 | 
			
		||||
		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
 | 
			
		||||
	if _, found := r.URL.Query()["jobs"]; found {
 | 
			
		||||
		jobs = query.Jobs
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
FROM quay.io/libpod/alpine:latest
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue