From e7b1ec4ce21b889782e4499377f0031c275de89c Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 1 Apr 2019 18:14:34 -0700 Subject: [PATCH] More Cloudbuild Trigger Step support (#223) /cc @chrisst --- .../cloud/google/gcp_cloudbuild_trigger.py | 237 +++++++++++++++++- .../google/gcp_cloudbuild_trigger_facts.py | 87 +++++++ 2 files changed, 321 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger.py b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger.py index f37e6b67bb5394..13759a8401427a 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger.py @@ -176,6 +176,82 @@ define an entrypoint, the first element in args is used as the entrypoint, and the remainder will be used as arguments. required: false + env: + description: + - A list of environment variable definitions to be used when running a + step. + - The elements are of the form "KEY=VALUE" for the environment variable + "KEY" being given the value "VALUE". + required: false + id: + description: + - Unique identifier for this build step, used in `wait_for` to reference + this build step as a dependency. + required: false + entrypoint: + description: + - Entrypoint to be used instead of the build step image's default entrypoint. + - If unset, the image's default entrypoint is used . + required: false + dir: + description: + - Working directory to use when running this step's container. + - If this value is a relative path, it is relative to the build's working + directory. If this value is absolute, it may be outside the build's + working directory, in which case the contents of the path may not be + persisted across build step executions, unless a `volume` for that path + is specified. + - If the build specifies a `RepoSource` with `dir` and a step with a `dir`, + which specifies an absolute path, the `RepoSource` `dir` is ignored + for the step's execution. + required: false + secret_env: + description: + - A list of environment variables which are encrypted using a Cloud Key + Management Service crypto key. These values must be specified in the + build's `Secret`. + required: false + timeout: + description: + - Time limit for executing this build step. If not defined, the step has + no time limit and will be allowed to continue to run until either it + completes or the build itself times out. + required: false + timing: + description: + - Output only. Stores timing information for executing this build step. + required: false + volumes: + description: + - List of volumes to mount into the build step. + - Each volume is created as an empty volume prior to execution of the + build step. Upon completion of the build, volumes and their contents + are discarded. + - Using a named volume in only one step is not valid as it is indicative + of a build request with an incorrect configuration. + required: false + suboptions: + name: + description: + - Name of the volume to mount. + - Volume names must be unique per build step and must be valid names + for Docker volumes. Each named volume must be used by at least two + build steps. + required: false + path: + description: + - Path at which to mount the volume. + - Paths must be absolute and cannot conflict with other volume paths + on the same build step or with certain reserved volume paths. + required: false + wait_for: + description: + - The ID(s) of the step(s) that this build step depends on. + - This build step will not start until all the build steps in `wait_for` + have completed successfully. If `wait_for` is empty, this build step + will start when all previous build steps in the `Build.Steps` list have + completed successfully. + required: false extends_documentation_fragment: gcp notes: - 'API Reference: U(https://cloud.google.com/cloud-build/docs/api/reference/rest/)' @@ -359,6 +435,90 @@ the remainder will be used as arguments. returned: success type: list + env: + description: + - A list of environment variable definitions to be used when running a step. + - The elements are of the form "KEY=VALUE" for the environment variable + "KEY" being given the value "VALUE". + returned: success + type: list + id: + description: + - Unique identifier for this build step, used in `wait_for` to reference + this build step as a dependency. + returned: success + type: str + entrypoint: + description: + - Entrypoint to be used instead of the build step image's default entrypoint. + - If unset, the image's default entrypoint is used . + returned: success + type: str + dir: + description: + - Working directory to use when running this step's container. + - If this value is a relative path, it is relative to the build's working + directory. If this value is absolute, it may be outside the build's working + directory, in which case the contents of the path may not be persisted + across build step executions, unless a `volume` for that path is specified. + - If the build specifies a `RepoSource` with `dir` and a step with a `dir`, + which specifies an absolute path, the `RepoSource` `dir` is ignored for + the step's execution. + returned: success + type: str + secretEnv: + description: + - A list of environment variables which are encrypted using a Cloud Key + Management Service crypto key. These values must be specified in the build's + `Secret`. + returned: success + type: list + timeout: + description: + - Time limit for executing this build step. If not defined, the step has + no time limit and will be allowed to continue to run until either it completes + or the build itself times out. + returned: success + type: str + timing: + description: + - Output only. Stores timing information for executing this build step. + returned: success + type: str + volumes: + description: + - List of volumes to mount into the build step. + - Each volume is created as an empty volume prior to execution of the build + step. Upon completion of the build, volumes and their contents are discarded. + - Using a named volume in only one step is not valid as it is indicative + of a build request with an incorrect configuration. + returned: success + type: complex + contains: + name: + description: + - Name of the volume to mount. + - Volume names must be unique per build step and must be valid names + for Docker volumes. Each named volume must be used by at least two + build steps. + returned: success + type: str + path: + description: + - Path at which to mount the volume. + - Paths must be absolute and cannot conflict with other volume paths + on the same build step or with certain reserved volume paths. + returned: success + type: str + waitFor: + description: + - The ID(s) of the step(s) that this build step depends on. + - This build step will not start until all the build steps in `wait_for` + have completed successfully. If `wait_for` is empty, this build step will + start when all previous build steps in the `Build.Steps` list have completed + successfully. + returned: success + type: list ''' ################################################################################ @@ -402,7 +562,23 @@ def main(): options=dict( tags=dict(type='list', elements='str'), images=dict(type='list', elements='str'), - steps=dict(type='list', elements='dict', options=dict(name=dict(type='str'), args=dict(type='list', elements='str'))), + steps=dict( + type='list', + elements='dict', + options=dict( + name=dict(type='str'), + args=dict(type='list', elements='str'), + env=dict(type='list', elements='str'), + id=dict(type='str'), + entrypoint=dict(type='str'), + dir=dict(type='str'), + secret_env=dict(type='list', elements='str'), + timeout=dict(type='str'), + timing=dict(type='str'), + volumes=dict(type='list', elements='dict', options=dict(name=dict(type='str'), path=dict(type='str'))), + wait_for=dict(type='list', elements='str'), + ), + ), ), ), ), @@ -627,10 +803,65 @@ def from_response(self): return items def _request_for_item(self, item): - return remove_nones_from_dict({u'name': item.get('name'), u'args': item.get('args')}) + return remove_nones_from_dict( + { + u'name': item.get('name'), + u'args': item.get('args'), + u'env': item.get('env'), + u'id': item.get('id'), + u'entrypoint': item.get('entrypoint'), + u'dir': item.get('dir'), + u'secretEnv': item.get('secret_env'), + u'timeout': item.get('timeout'), + u'timing': item.get('timing'), + u'volumes': TriggerVolumesArray(item.get('volumes', []), self.module).to_request(), + u'waitFor': item.get('wait_for'), + } + ) + + def _response_from_item(self, item): + return remove_nones_from_dict( + { + u'name': item.get(u'name'), + u'args': item.get(u'args'), + u'env': item.get(u'env'), + u'id': item.get(u'id'), + u'entrypoint': item.get(u'entrypoint'), + u'dir': item.get(u'dir'), + u'secretEnv': item.get(u'secretEnv'), + u'timeout': item.get(u'timeout'), + u'timing': item.get(u'timing'), + u'volumes': TriggerVolumesArray(item.get(u'volumes', []), self.module).from_response(), + u'waitFor': item.get(u'waitFor'), + } + ) + + +class TriggerVolumesArray(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = [] + + def to_request(self): + items = [] + for item in self.request: + items.append(self._request_for_item(item)) + return items + + def from_response(self): + items = [] + for item in self.request: + items.append(self._response_from_item(item)) + return items + + def _request_for_item(self, item): + return remove_nones_from_dict({u'name': item.get('name'), u'path': item.get('path')}) def _response_from_item(self, item): - return remove_nones_from_dict({u'name': item.get(u'name'), u'args': item.get(u'args')}) + return remove_nones_from_dict({u'name': item.get(u'name'), u'path': item.get(u'path')}) if __name__ == '__main__': diff --git a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_facts.py b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_facts.py index ac40c6e7e7efef..05faee00714a3e 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_facts.py @@ -214,6 +214,93 @@ and the remainder will be used as arguments. returned: success type: list + env: + description: + - A list of environment variable definitions to be used when running + a step. + - The elements are of the form "KEY=VALUE" for the environment variable + "KEY" being given the value "VALUE". + returned: success + type: list + id: + description: + - Unique identifier for this build step, used in `wait_for` to reference + this build step as a dependency. + returned: success + type: str + entrypoint: + description: + - Entrypoint to be used instead of the build step image's default entrypoint. + - If unset, the image's default entrypoint is used . + returned: success + type: str + dir: + description: + - Working directory to use when running this step's container. + - If this value is a relative path, it is relative to the build's working + directory. If this value is absolute, it may be outside the build's + working directory, in which case the contents of the path may not + be persisted across build step executions, unless a `volume` for that + path is specified. + - If the build specifies a `RepoSource` with `dir` and a step with a + `dir`, which specifies an absolute path, the `RepoSource` `dir` is + ignored for the step's execution. + returned: success + type: str + secretEnv: + description: + - A list of environment variables which are encrypted using a Cloud + Key Management Service crypto key. These values must be specified + in the build's `Secret`. + returned: success + type: list + timeout: + description: + - Time limit for executing this build step. If not defined, the step + has no time limit and will be allowed to continue to run until either + it completes or the build itself times out. + returned: success + type: str + timing: + description: + - Output only. Stores timing information for executing this build step. + returned: success + type: str + volumes: + description: + - List of volumes to mount into the build step. + - Each volume is created as an empty volume prior to execution of the + build step. Upon completion of the build, volumes and their contents + are discarded. + - Using a named volume in only one step is not valid as it is indicative + of a build request with an incorrect configuration. + returned: success + type: complex + contains: + name: + description: + - Name of the volume to mount. + - Volume names must be unique per build step and must be valid names + for Docker volumes. Each named volume must be used by at least + two build steps. + returned: success + type: str + path: + description: + - Path at which to mount the volume. + - Paths must be absolute and cannot conflict with other volume paths + on the same build step or with certain reserved volume paths. + returned: success + type: str + waitFor: + description: + - The ID(s) of the step(s) that this build step depends on. + - This build step will not start until all the build steps in `wait_for` + have completed successfully. If `wait_for` is empty, this build step + will start when all previous build steps in the `Build.Steps` list + have completed successfully. + returned: success + type: list ''' ################################################################################