Repository: cekit/cekit

Issue:
Add support for overriding target in OSBS builder
We should be able to override the build target using the `--target` parameter to `rhpkg`.

Discussion:

Patch:
diff --git a/bash_completion/cekit b/bash_completion/cekit
index efdb39c..e1465c3 100755
--- a/bash_completion/cekit
+++ b/bash_completion/cekit
@@ -20,6 +20,7 @@ _cekit_build_options()
     options+='--build-osbs-user '
     options+='--build-osbs-nowait '
     options+='--build-osbs-stage '
+    options+='--build-osbs-target '
     options+='--build-tech-preview '
     echo "$options"
 }
@@ -73,6 +74,7 @@ _cekit_complete()
 	options+='--verbose '
 	options+='--version '
 	options+='--config '
+	options+='--redhat '
 	COMPREPLY=( $( compgen -W "$options" -- $cur ) )
 	return
 
diff --git a/cekit/builders/osbs.py b/cekit/builders/osbs.py
index b61a34c..f4c1372 100644
--- a/cekit/builders/osbs.py
+++ b/cekit/builders/osbs.py
@@ -18,6 +18,7 @@ class OSBSBuilder(Builder):
         self._user = params.get('user')
         self._nowait = params.get('nowait', False)
         self._release = params.get('release', False)
+        self._target = params.get('target')
 
         self._stage = params.get('stage', False)
 
@@ -119,9 +120,14 @@ class OSBSBuilder(Builder):
 
     def build(self):
         cmd = [self._rhpkg]
+
         if self._user:
             cmd += ['--user', self._user]
         cmd.append("container-build")
+
+        if self._target:
+            cmd += ['--target', self._target]
+
         if self._nowait:
             cmd += ['--nowait']
 
diff --git a/cekit/cli.py b/cekit/cli.py
index 54646be..55f9dd6 100644
--- a/cekit/cli.py
+++ b/cekit/cli.py
@@ -104,6 +104,10 @@ class Cekit(object):
                                  action='store_true',
                                  help='use rhpkg-stage instead of rhpkg')
 
+        build_group.add_argument('--build-osbs-target',
+                                 dest='build_osbs_target',
+                                 help='overrides the default rhpkg target')
+
         build_group.add_argument('--build-tech-preview',
                                  action='store_true',
                                  help='perform tech preview build')
@@ -200,7 +204,8 @@ class Cekit(object):
                           'release': self.args.build_osbs_release,
                           'tags': self.args.tags,
                           'pull': self.args.build_pull,
-                          'redhat': tools.cfg['common']['redhat']
+                          'redhat': tools.cfg['common']['redhat'],
+                          'target': self.args.build_osbs_target
                           }
 
                 builder = Builder(self.args.build_engine,
diff --git a/cekit/generator/base.py b/cekit/generator/base.py
index e55f7dc..b39cb7e 100644
--- a/cekit/generator/base.py
+++ b/cekit/generator/base.py
@@ -51,6 +51,7 @@ class Generator(object):
 
         self.image = Image(descriptor, os.path.dirname(os.path.abspath(descriptor_path)))
         self.target = target
+        self._params = params
 
         if overrides:
             self.image = self.override(overrides)
diff --git a/docs/build.rst b/docs/build.rst
index 8702b58..78d1f6d 100644
--- a/docs/build.rst
+++ b/docs/build.rst
@@ -25,6 +25,7 @@ You can execute an container image build by running:
 * ``--build-osbs-stage`` -- use ``rhpkg-stage`` tool instead of ``rhpkg``
 * ``--build-osbs-release`` [#f2]_ -- perform a OSBS release build
 * ``--build-osbs-user`` -- alternative user passed to `rhpkg --user`
+* ``--build-osbs-target`` -- overrides the default ``rhpkg`` target
 * ``--build-osbs-nowait`` -- run `rhpkg container-build` with `--nowait` option specified
 * ``--build-tech-preview`` [#f2]_ -- updates image descriptor ``name`` key to contain ``-tech-preview`` suffix in family part of the image name
   


Test patch:
diff --git a/tests/test_builder.py b/tests/test_builder.py
index 88ba3ec..b3dd769 100644
--- a/tests/test_builder.py
+++ b/tests/test_builder.py
@@ -114,6 +114,17 @@ def test_osbs_builder_run_rhpkg_user(mocker):
     check_call.assert_called_once_with(['rhpkg', '--user', 'Foo', 'container-build', '--scratch'])
 
 
+def test_osbs_builder_run_rhpkg_target(mocker):
+    params = {'target': 'Foo',
+              'redhat': True}
+
+    check_call = mocker.patch.object(subprocess, 'check_call')
+    builder = create_osbs_build_object(mocker, 'osbs', params)
+    builder.build()
+
+    check_call.assert_called_once_with(['rhpkg', 'container-build', '--target', 'Foo', '--scratch'])
+
+
 def test_docker_builder_defaults():
     params = {'tags': ['foo', 'bar']}
     builder = Builder('docker', 'tmp', params)
diff --git a/tests/test_unit_args.py b/tests/test_unit_args.py
index 1e221f1..fdb2042 100644
--- a/tests/test_unit_args.py
+++ b/tests/test_unit_args.py
@@ -90,6 +90,15 @@ def test_args_config(mocker):
     assert Cekit().parse().args.config == 'whatever'
 
 
+def test_args_target(mocker):
+    mocker.patch.object(sys, 'argv', ['cekit',
+                                      'build',
+                                      '--target',
+                                      'foo'])
+
+    assert Cekit().parse().args.target == 'foo'
+
+
 def test_args_redhat(mocker):
     mocker.patch.object(sys, 'argv', ['cekit',
                                       '--redhat',