Repository: cekit/cekit

Issue:
Docker builder does not tag built image with all advertised tags
```
2019-03-12 20:05:28,393 cekit        INFO     Image built and available under following tags: example/rhel8:1.0, example/rhel8:latest
2019-03-12 20:05:28,393 cekit        INFO     Finished!
```

But the image is available under `example/rhel8:latest`, only.

Discussion:

Patch:
diff --git a/cekit/builders/docker_builder.py b/cekit/builders/docker_builder.py
index f3896fd..5bccc72 100644
--- a/cekit/builders/docker_builder.py
+++ b/cekit/builders/docker_builder.py
@@ -161,7 +161,7 @@ class DockerBuilder(Builder):
         return squash.run()
 
     def _tag(self, docker_client, image_id, tags):
-        for tag in tags[1:]:
+        for tag in tags:
             if ':' in tag:
                 img_repo, img_tag = tag.split(":")
                 docker_client.tag(image_id, img_repo, tag=img_tag)


Test patch:
diff --git a/tests/test_builder.py b/tests/test_builder.py
index d45a40e..234a255 100644
--- a/tests/test_builder.py
+++ b/tests/test_builder.py
@@ -460,6 +460,27 @@ def test_docker_builder_defaults():
     assert builder.params.tags == ['foo', 'bar']
 
 
+def test_docker_build_default_tags(mocker):
+    builder = DockerBuilder(Map({'target': 'something'}), Map())
+
+    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
+    docker_client = docker_client_class.return_value
+    mock_generator = mocker.patch.object(builder, 'generator')
+    mock_generator.get_tags.return_value = ["image/test:1.0", "image/test:latest"]
+    mocker.patch.object(builder, '_build_with_docker')
+    mocker.patch.object(builder, '_squash', return_value="112321312imageID")
+
+    builder._build_with_docker.return_value = "1654234sdf56"
+
+    builder.run()
+
+    builder._build_with_docker.assert_called_once_with(docker_client)
+
+    tag_calls = [mocker.call('112321312imageID', 'image/test', tag='1.0'),
+                 mocker.call('112321312imageID', 'image/test', tag='latest')]
+    docker_client.tag.assert_has_calls(tag_calls)
+
+
 def test_docker_squashing_enabled(mocker):
     builder = DockerBuilder(Map({'target': 'something'}), Map({'tags': ['foo', 'bar']}))