Skip to content

Commit

Permalink
simple builds: enable setting image tag
Browse files Browse the repository at this point in the history
Closes #35.
  • Loading branch information
mmilata committed Oct 29, 2015
1 parent 54ded1f commit c6fee84
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def create_prod_without_koji_build(self, git_uri, git_ref, git_branch, user, com
namespace=namespace, **kwargs)

@osbsapi
def create_simple_build(self, git_uri, git_ref, user, component,
def create_simple_build(self, git_uri, git_ref, user, component, tag,
yum_repourls=None, namespace=DEFAULT_NAMESPACE,
**kwargs):
build_request = self.get_build_request(SIMPLE_BUILD_TYPE)
Expand All @@ -320,6 +320,7 @@ def create_simple_build(self, git_uri, git_ref, user, component,
git_ref=git_ref,
user=user,
component=component,
tag=tag,
registry_uris=self.build_conf.get_registry_uris(),
source_registry_uri=self.build_conf.get_source_registry_uri(),
openshift_uri=self.os_conf.get_openshift_base_uri(),
Expand Down
9 changes: 7 additions & 2 deletions osbs/build/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,13 @@ def set_params(self, sources_command=None, architecture=None, vendor=None,
class SimpleSpec(CommonSpec):
image_tag = BuildParam("image_tag")

def set_params(self, **kwargs):
def set_params(self, tag=None, **kwargs):
super(SimpleSpec, self).set_params(**kwargs)
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
self.name.value = "build-%s" % timestamp
self.image_tag.value = "%s/%s:%s" % (self.user.value, self.component.value, timestamp)

self.image_tag.value = "%s/%s:%s" % (
self.user.value,
self.component.value,
tag or timestamp
)
3 changes: 3 additions & 0 deletions osbs/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def cmd_build(args, osbs):
git_branch=osbs.build_conf.get_git_branch(),
user=osbs.build_conf.get_user(),
component=osbs.build_conf.get_component(),
tag=osbs.build_conf.get_tag(),
target=osbs.build_conf.get_koji_target(),
architecture=osbs.build_conf.get_architecture(),
yum_repourls=osbs.build_conf.get_yum_repourls(),
Expand Down Expand Up @@ -383,6 +384,8 @@ def cli():
help="prefix for docker image repository")
build_parser.add_argument("-c", "--component", action='store', required=True,
help="name of component")
build_parser.add_argument("-A", "--tag", action='store', required=False,
help="tag of the built image (simple builds only)")
build_parser.add_argument("--no-logs", action='store_true', required=False, default=False,
help="don't print logs after submitting build")
build_parser.add_argument("--add-yum-repo", action='append', metavar="URL",
Expand Down
3 changes: 3 additions & 0 deletions osbs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def get_user(self):
def get_component(self):
return self._get_value("component", self.conf_section, "component")

def get_tag(self):
return self._get_value("tag", self.conf_section, "tag")

def get_yum_repourls(self):
return self._get_value("yum_repourls", self.conf_section, "yum_repourls")

Expand Down
18 changes: 14 additions & 4 deletions tests/build/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def test_render_simple_request_incorrect_postbuild(self, tmpdir):
assert plugin_value_get(plugins, "postbuild_plugins", "store_metadata_in_osv3", "args", "url") == \
"http://openshift/"

def test_render_simple_request(self):
@pytest.mark.parametrize('tag', [
None,
"some_tag",
])
def test_render_simple_request(self, tag):
bm = BuildManager(INPUTS_PATH)
build_request = bm.get_build_request_by_type("simple")
name_label = "fedora/resultingimage"
Expand All @@ -118,6 +122,7 @@ def test_render_simple_request(self):
'registry_uri': "http://registry.example.com:5000",
'openshift_uri': "http://openshift/",
'builder_openshift_url': "http://openshift/",
'tag': tag,
}
build_request.set_params(**kwargs)
build_json = build_request.render()
Expand All @@ -126,9 +131,14 @@ def test_render_simple_request(self):
assert "triggers" not in build_json["spec"]
assert build_json["spec"]["source"]["git"]["uri"] == TEST_GIT_URI
assert build_json["spec"]["source"]["git"]["ref"] == TEST_GIT_REF
assert build_json["spec"]["output"]["to"]["name"].startswith(
"registry.example.com:5000/john-foo/component:"
)

if tag:
assert build_json["spec"]["output"]["to"]["name"] == \
("registry.example.com:5000/john-foo/component:%s" % tag)
else:
assert build_json["spec"]["output"]["to"]["name"].startswith(
"registry.example.com:5000/john-foo/component:20"
)

env_vars = build_json['spec']['strategy']['customStrategy']['env']
plugins_json = None
Expand Down

0 comments on commit c6fee84

Please sign in to comment.