Repository: cekit/cekit

Issue:
Labels with a very large value break container builds
**Describe the bug**
If the image.yaml descriptor has a very huge label value it will make cekit build fails (tested with docker and osbs and podman).

Apparently, the label string value are being parsed to bytes somewhere and this issue happens: 
https://pastebin.com/fG2EdUKP

I tried to do this, but the build failed with "Docker unknown instruction":

`if line != build_log[-1]:
    if isinstance(line, bytes): 
        line = line.decode('utf-8') `

With podman, this issue happens:

> Error: error building at step {Env:[USER_NAME=apb USER_UID=1001 BASE_DIR=/opt/apb HOME=/opt/apb PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin container=oci JBOSS_IMAGE_NAME=rhpam-7/rhpam-apb JBOSS_IMAGE_VERSION=1.1] Command:label Args:[] Flags:[] Attrs:map[] Message:LABEL  Original:LABEL }: LABEL requires at least one argument

**To reproduce**
use a image.yaml file descriptor with this label:
https://pastebin.com/CbbxgMGm

**Logs**
Paste any logs you have, use CEKit verbose output: `cekit -v`.
https://pastebin.com/fG2EdUKP


**Environment information:**
 - Operating system: Fedora 29
 - CEKit version: 3.0.1

**Additional context**
This label is a requirement to work with APB (ansible playbook bundle)


Discussion:

Patch:
diff --git a/cekit/generator/base.py b/cekit/generator/base.py
index 3029050..318c38a 100644
--- a/cekit/generator/base.py
+++ b/cekit/generator/base.py
@@ -2,6 +2,7 @@
 
 import logging
 import os
+import re
 import platform
 import shutil
 
@@ -116,6 +117,11 @@ class Generator(object):
         # was used to build the image
         image_labels.append(Label({'name': 'io.cekit.version', 'value': cekit_version}))
 
+        for label in image_labels:
+            if len(label.value) > 128:
+                # breaks the line each time it reaches 128 characters
+                label.value = "\\\n".join(re.findall("(?s).{,128}", label.value))[:]
+
         # If we define the label in the image descriptor
         # we should *not* override it with value from
         # the root's key


Test patch:
diff --git a/tests/test_unit_generator_docker.py b/tests/test_unit_generator_docker.py
index 69c863f..bb2adf6 100644
--- a/tests/test_unit_generator_docker.py
+++ b/tests/test_unit_generator_docker.py
@@ -8,10 +8,12 @@ import os
 from contextlib import contextmanager
 
 import pytest
+import yaml
 
 from cekit.config import Config
 from cekit.errors import CekitError
 from cekit.generator.docker import DockerGenerator
+from cekit.descriptor import Image
 
 
 odcs_fake_resp = {
@@ -104,6 +106,22 @@ def test_prepare_content_sets_should_not_fail_when_cs_is_empty(tmpdir):
             assert generator._prepare_content_sets({}) is False
 
 
+def test_large_labels_should_break_lines(tmpdir):
+    image = Image(yaml.safe_load("""
+    from: foo
+    name: test/foo
+    version: 1.9
+    labels:
+      - name: 'the.large.label'
+        value: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium finibus lorem vitae pellentesque. Maecenas tincidunt amet.
+    """), 'foo')
+    with docker_generator(tmpdir) as generator:
+        generator.image = image
+        with cekit_config(redhat=True):
+            generator.add_build_labels()
+            assert image.labels[0].value == "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium finibus lorem vitae pellentesque. Maecenas tincidunt amet\\\n.\\\n"
+
+
 def test_prepare_content_sets_should_fail_when_cs_are_note_defined_for_current_platform(tmpdir, mocker):
     mocker.patch('cekit.generator.base.platform.machine',
                  return_value="current_platform")