Skip to content

Commit

Permalink
Update dokku_clone.py
Browse files Browse the repository at this point in the history
First try at implementing dokku#163
  • Loading branch information
robotski authored Apr 2, 2024
1 parent 1b47f2f commit aa4883c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions library/dokku_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@
description:
- Whether to build the app after cloning.
required: False
default: true
default: if-changes
choices: [ "if-changes", "false", "true" ]
aliases: []
author: Jose Diaz-Gonzalez
"""

EXAMPLES = """
- name: clone a git repository and build app
- name: clone a git repository and build app if necessary
dokku_clone:
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
build: if-changes
- name: clone specific tag from git repository and build app
dokku_clone:
app: example-app
repository: https://github.com/heroku/node-js-getting-started
version: b10a4d7a20a6bbe49655769c526a2b424e0e5d0b
build: true
- name: sync git repository without building app
dokku_clone:
app: example-app
Expand All @@ -74,8 +76,10 @@ def dokku_clone(data):
)
if data["version"]:
command_git_sync += " {version}".format(version=data["version"])
if data["build"]:
if data["build"] == "true":
command_git_sync += " --build"
elif data["build"] == "if-changes":
command_git_sync += " --build-if-changes"
try:
subprocess.check_output(command_git_sync, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
Expand All @@ -90,7 +94,7 @@ def dokku_clone(data):
finally:
meta["present"] = True # meaning: requested *version* of app is present

if data["build"] or dokku_git_sha(data["app"]) != sha_old:
if data["build"] == "true" or dokku_git_sha(data["app"]) != sha_old:
has_changed = True

return (is_error, has_changed, meta)
Expand All @@ -101,7 +105,12 @@ def main():
"app": {"required": True, "type": "str"},
"repository": {"required": True, "type": "str"},
"version": {"required": False, "type": "str"},
"build": {"default": True, "required": False, "type": "bool"},
"build": {
"required": False,
"default": "if-changes",
"choices": ["if-changes", "false", "true"],
"type": "str",
},
}

module = AnsibleModule(argument_spec=fields, supports_check_mode=False)
Expand Down

0 comments on commit aa4883c

Please sign in to comment.