Skip to content

Commit

Permalink
export --build argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ltalirz committed Sep 1, 2021
1 parent 1895e64 commit e0be578
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,35 @@ Manages ssl configuration for an app.

### dokku_clone

Clone repository and deploy app.
Clone a git repository and deploy app.

#### Parameters

|Parameter|Choices/Defaults|Comments|
|---------|----------------|--------|
|app<br /><sup>*required*</sup>||The name of the app|
|build|*Default:* True|Whether to build the app after cloning.|
|repository<br /><sup>*required*</sup>||Git repository url|
|version||Git tree (tag or branch name). If not provided, default branch is used.|

#### Example

```yaml
- name: clone a git repository
- name: clone a git repository and build app
dokku_clone:
app: hello-world
repository: https://github.com/hello-world/hello-world.git
- name: clone specific tag of a git repository
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
- name: clone specific tag from git repository and build app
dokku_clone:
app: hello-world
repository: https://github.com/hello-world/hello-world.git
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
- name: sync git repository without building app
dokku_clone:
app: example-app
repository: https://github.com/heroku/node-js-getting-started
build: false
```

### dokku_config
Expand Down
51 changes: 27 additions & 24 deletions library/dokku_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DOCUMENTATION = """
---
module: dokku_clone
short_description: Clone repository and deploy app.
short_description: Clone a git repository and deploy app.
options:
app:
description:
Expand All @@ -30,18 +30,32 @@
required: False
default: null
aliases: []
build:
description:
- Whether to build the app after cloning.
required: False
default: true
aliases: []
author: Jose Diaz-Gonzalez
"""

EXAMPLES = """
- name: clone a git repository
- name: clone a git repository and build app
dokku_clone:
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
- name: clone specific tag from git repository and build app
dokku_clone:
app: hello-world
repository: https://github.com/hello-world/hello-world.git
- name: clone specific tag of a git repository
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
- name: sync git repository without building app
dokku_clone:
app: hello-world
repository: https://github.com/hello-world/hello-world.git
app: example-app
repository: https://github.com/heroku/node-js-getting-started
build: false
"""


Expand Down Expand Up @@ -77,9 +91,10 @@ def dokku_clone(data):
)
if data["version"]:
command_git_sync += " {version}".format(version=data["version"])
if data["build"]:
command_git_sync += " --build"
try:
subprocess.check_output(command_git_sync, stderr=subprocess.STDOUT, shell=True)
is_error = False
except subprocess.CalledProcessError as e:
is_error = True
if "is not a dokku command" in str(e.output):
Expand All @@ -89,25 +104,12 @@ def dokku_clone(data):
else:
meta["error"] = str(e.output)
return (is_error, has_changed, meta)
finally:
meta["present"] = True # meaning: requested *version* of app is present

sha_new = dokku_git_sha(data)
if sha_new == sha_old:
meta["present"] = True
return (is_error, has_changed, meta)
else:
if data["build"] or dokku_git_sha(data) != sha_old:
has_changed = True

# rebuild app
command_ps_rebuild = "dokku ps:rebuild {app}".format(app=data["app"])
try:
subprocess.check_output(
command_ps_rebuild, stderr=subprocess.STDOUT, shell=True
)
meta["present"] = True
except subprocess.CalledProcessError as e:
is_error = True
meta["error"] = e.output

return (is_error, has_changed, meta)


Expand All @@ -116,6 +118,7 @@ def main():
"app": {"required": True, "type": "str"},
"repository": {"required": True, "type": "str"},
"version": {"required": False, "type": "str"},
"build": {"required": False, "type": "bool"},
}

module = AnsibleModule(argument_spec=fields, supports_check_mode=False)
Expand Down
1 change: 1 addition & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
build: false
register: example_app

- name: Check that re-cloning example app did not change anything
Expand Down

0 comments on commit e0be578

Please sign in to comment.