Skip to content

Commit

Permalink
Add create_worker_build api method
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarva committed Feb 17, 2017
1 parent a49a4af commit 65cef4c
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 19 deletions.
38 changes: 38 additions & 0 deletions inputs/worker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"apiVersion": "v1",
"kind": "BuildConfig",
"metadata": {
"name": "{{NAME}}",
"labels": {}
},
"spec": {
"source": {
"type": "Git",
"git": {
"uri": "{{GIT_URI}}",
"ref": "{{GIT_REF}}"
}
},
"output": {
"to": {
"kind": "DockerImage",
"name": "{{REGISTRY_URI}}/{{OUTPUT_IMAGE_TAG}}"
}
},
"strategy": {
"type": "Custom",
"customStrategy": {
"from": {
"kind": "DockerImage",
"name": "{{BUILD_IMAGE}}"
},
"exposeDockerSocket": true,
"env": [{
"name": "ATOMIC_REACTOR_PLUGINS",
"value": "TBD"
}],
"secrets": []
}
}
}
}
7 changes: 7 additions & 0 deletions inputs/worker_customize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"disable_plugins": [
],

"enable_plugins": [
]
}
150 changes: 150 additions & 0 deletions inputs/worker_inner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"client_version": "{{VERSION}}",
"prebuild_plugins": [
{
"name": "add_filesystem",
"args": {
"koji_hub": "{{KOJI_HUB}}",
"repos": []
}
},
{
"name": "pull_base_image",
"args": {
"parent_registry": "{{REGISTRY_URI}}",
"parent_registry_insecure": true
}
},
{
"name": "bump_release",
"args": {
"hub": "{{KOJI_HUB}}"
}
},
{
"name": "add_labels_in_dockerfile",
"args": {
"labels": "{{IMPLICIT_LABELS}}"
}
},
{
"name": "change_from_in_dockerfile"
},
{
"name": "add_help",
"required": false
},
{
"name": "add_dockerfile"
},
{
"name": "distgit_fetch_artefacts",
"args": {
"command": "{{SOURCES_COMMAND}}"
}
},
{
"name": "koji",
"args": {
"root": "{{KOJI_ROOT}}",
"target": "{{KOJI_TARGET}}",
"hub": "{{KOJI_HUB}}"
}
},
{
"name": "add_yum_repo_by_url",
"args": {
"repourls": []
}
},
{
"name": "inject_yum_repo"
},
{
"name": "distribution_scope"
}
],
"prepublish_plugins": [
{
"name": "squash"
}
],
"postbuild_plugins": [
{
"name": "all_rpm_packages",
"args": {
"image_id": "BUILT_IMAGE_ID"
}
},
{
"name": "tag_by_labels"
},
{
"name": "tag_from_config"
},
{
"name": "tag_and_push",
"args": {
"registries": {
"{{REGISTRY_URI}}": { "insecure": true }
}
}
},
{
"name": "pulp_push",
"args": {
"pulp_registry_name": "{{PULP_REGISTRY_NAME}}",
"load_exported_image": true,
"dockpulp_loglevel": "INFO"
}
},
{
"name": "pulp_sync",
"args": {
"pulp_registry_name": "{{PULP_REGISTRY_NAME}}",
"docker_registry": "{{DOCKER_REGISTRY}}",
"dockpulp_loglevel": "INFO"
}
},
{
"name": "compress",
"args": {
"load_exported_image": true,
"method": "gzip"
}
},
{
"name": "pulp_pull",
"args": {}
}
],
"exit_plugins": [
{
"name": "delete_from_registry",
"args": {
"registries": {}
}
},
{
"name": "koji_promote",
"args": {
"kojihub": "{{KOJI_HUB}}",
"url": "{{OPENSHIFT_URI}}",
"verify_ssl": false,
"blocksize": 10485760,
"koji_keytab": false,
"koji_principal": false
}
},
{
"name": "store_metadata_in_osv3",
"args": {
"url": "{{OPENSHIFT_URI}}",
"verify_ssl": false
}
},
{
"name": "remove_built_image"
}
]
}
56 changes: 52 additions & 4 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from osbs.build.build_request import BuildRequest
from osbs.build.build_response import BuildResponse
from osbs.build.pod_response import PodResponse
from osbs.constants import BUILD_RUNNING_STATES
from osbs.constants import (BUILD_RUNNING_STATES, WORKER_OUTER_TEMPLATE,
WORKER_INNER_TEMPLATE, WORKER_CUSTOMIZE_CONF)
from osbs.core import Openshift
from osbs.exceptions import OsbsException, OsbsValidationException, OsbsResponseException
# import utils in this way, so that we can mock standalone functions with flexmock
Expand Down Expand Up @@ -141,17 +142,25 @@ def get_pod_for_build(self, build_id):
return pod_list[0]

@osbsapi
def get_build_request(self, build_type=None):
def get_build_request(self, build_type=None, inner_template=None,
outer_template=None, customize_conf=None):
"""
return instance of BuildRequest
:param build_type: str, unused
:param inner_template: str, name of inner template for BuildRequest
:param outer_template: str, name of outer template for BuildRequest
:param customize_conf: str, name of customization config for BuildRequest
:return: instance of BuildRequest
"""
if build_type is not None:
warnings.warn("build types are deprecated, do not use the build_type argument")

build_request = BuildRequest(build_json_store=self.os_conf.get_build_json_store())
build_request = BuildRequest(
build_json_store=self.os_conf.get_build_json_store(),
inner_template=inner_template,
outer_template=outer_template,
customize_conf=customize_conf)

# Apply configured resource limits.
cpu_limit = self.build_conf.get_cpu_limit()
Expand Down Expand Up @@ -392,6 +401,11 @@ def create_prod_build(self, git_uri, git_ref,
architecture=None, yum_repourls=None,
koji_task_id=None,
scratch=None,
platform=None,
release=None,
inner_template=None,
outer_template=None,
customize_conf=None,
**kwargs):
"""
Create a production build
Expand All @@ -406,11 +420,18 @@ def create_prod_build(self, git_uri, git_ref,
:param yum_repourls: list, URLs for yum repos
:param koji_task_id: int, koji task ID requesting build
:param scratch: bool, this is a scratch build
:param platform: str, the platform name
:param release: str, the release value to use
:param inner_template: str, name of inner template for BuildRequest
:param outer_template: str, name of outer template for BuildRequest
:param customize_conf: str, name of customization config for BuildRequest
:return: BuildResponse instance
"""

df_parser = utils.get_df_parser(git_uri, git_ref, git_branch=git_branch)
build_request = self.get_build_request()
build_request = self.get_build_request(inner_template=inner_template,
outer_template=outer_template,
customize_conf=customize_conf)
labels = utils.Labels(df_parser.labels)

try:
Expand Down Expand Up @@ -445,6 +466,8 @@ def create_prod_build(self, git_uri, git_ref,
koji_kerberos_keytab=self.build_conf.get_koji_kerberos_keytab(),
koji_kerberos_principal=self.build_conf.get_koji_kerberos_principal(),
architecture=architecture,
platform=platform,
release=release,
vendor=self.build_conf.get_vendor(),
build_host=self.build_conf.get_build_host(),
authoritative_registry=self.build_conf.get_authoritative_registry(),
Expand Down Expand Up @@ -501,6 +524,31 @@ def create_build(self, **kwargs):
kwargs.setdefault('git_branch', None)
return self.create_prod_build(**kwargs)

@osbsapi
def create_worker_build(self, *args, **kwargs):
"""
Create a worker build
Pass through method to create_prod_build with the following
modifications:
- platform param is required
- release param is required
- inner template set to worker_inner.json if not set
- outer template set to worker.json if not set
- customize configuration set to worker_customize.json if not set
:return: BuildResponse instance
"""
for required in ('platform', 'release'):
if not kwargs.get(required):
raise ValueError('Worker build requires %s param' % required)

kwargs.setdefault('inner_template', WORKER_INNER_TEMPLATE)
kwargs.setdefault('outer_template', WORKER_OUTER_TEMPLATE)
kwargs.setdefault('customize_conf', WORKER_CUSTOMIZE_CONF)

return self.create_prod_build(*args, **kwargs)

@osbsapi
def get_build_logs(self, build_id, follow=False, build_json=None, wait_if_missing=False):
"""
Expand Down
15 changes: 11 additions & 4 deletions osbs/build/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ class BuildRequest(object):
Wraps logic for creating build inputs
"""

def __init__(self, build_json_store):
def __init__(self, build_json_store, inner_template=None,
outer_template=None, customize_conf=None):
"""
:param build_json_store: str, path to directory with JSON build files
:param inner_template: str, path to inner template JSON
:param outer_template: str, path to outer template JSON
:param customize_conf: str, path to customize configuration JSON
"""
self.spec = BuildSpec()
self.build_json_store = build_json_store
self._inner_template_path = inner_template or DEFAULT_INNER_TEMPLATE
self._outer_template_path = outer_template or DEFAULT_OUTER_TEMPLATE
self._customize_conf_path = customize_conf or DEFAULT_CUSTOMIZE_CONF
self.build_json = None # rendered template
self._template = None # template loaded from filesystem
self._inner_template = None # dock json
Expand Down Expand Up @@ -117,7 +124,7 @@ def build_id(self):
@property
def template(self):
if self._template is None:
path = os.path.join(self.build_json_store, DEFAULT_OUTER_TEMPLATE)
path = os.path.join(self.build_json_store, self._outer_template_path)
logger.debug("loading template from path %s", path)
try:
with open(path, "r") as fp:
Expand All @@ -130,7 +137,7 @@ def template(self):
@property
def inner_template(self):
if self._inner_template is None:
path = os.path.join(self.build_json_store, DEFAULT_INNER_TEMPLATE)
path = os.path.join(self.build_json_store, self._inner_template_path)
logger.debug("loading inner template from path %s", path)
with open(path, "r") as fp:
self._inner_template = json.load(fp)
Expand All @@ -139,7 +146,7 @@ def inner_template(self):
@property
def customize_conf(self):
if self._customize_conf is None:
path = os.path.join(self.build_json_store, DEFAULT_CUSTOMIZE_CONF)
path = os.path.join(self.build_json_store, self._customize_conf_path)
logger.debug("loading customize conf from path %s", path)
try:
with open(path, "r") as fp:
Expand Down
6 changes: 5 additions & 1 deletion osbs/build/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class BuildSpec(object):
nfs_dest_dir = BuildParam("nfs_dest_dir", allow_none=True)
builder_build_json_dir = BuildParam("builder_build_json_dir", allow_none=True)
unique_tag_only = BuildParam("unique_tag_only", allow_none=True)
platform = BuildParam("platform", allow_none=True)
release = BuildParam("release", allow_none=True)

def __init__(self):
self.required_params = [
Expand Down Expand Up @@ -203,7 +205,7 @@ def set_params(self, git_uri=None, git_ref=None,
nfs_dest_dir=None, git_branch=None, base_image=None,
name_label=None,
builder_build_json_dir=None, registry_api_versions=None,
unique_tag_only=None,
unique_tag_only=None, platform=None, release=None,
**kwargs):
self.git_uri.value = git_uri
self.git_ref.value = git_ref
Expand Down Expand Up @@ -287,6 +289,8 @@ def set_params(self, git_uri=None, git_ref=None,
)

self.unique_tag_only.value = unique_tag_only
self.platform.value = platform
self.release.value = release

def validate(self):
logger.info("Validating params of %s", self.__class__.__name__)
Expand Down
Loading

0 comments on commit 65cef4c

Please sign in to comment.