Start to thread through arguments

This commit is contained in:
Luke Murphy 2020-04-13 10:26:21 +02:00
parent 714f18e8c0
commit 236705d1e3
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 47 additions and 5 deletions

View File

@ -100,11 +100,16 @@ dokku-ansible-deploy-pre-deploy() {
declare desc="run the pre-deploy hook to setup an app" declare desc="run the pre-deploy hook to setup an app"
declare APP="$1" declare APP="$1"
declare APP_CONFIG_PATH="$DOKKU_LIB_ROOT/data/deploy.d/$APP"
declare PLUGIN_PATH="$PLUGIN_CORE_AVAILABLE_PATH/ansible-deploy"
declare PREDEPLOY="$PLUGIN_CORE_AVAILABLE_PATH/ansible-deploy/scripts/predeploy.py" declare PREDEPLOY="$PLUGIN_CORE_AVAILABLE_PATH/ansible-deploy/scripts/predeploy.py"
dokku_col_log_info1_quiet "Running pre-deploy steps" dokku_col_log_info1_quiet "Running pre-deploy steps"
/usr/bin/python3 "$PREDEPLOY"
/usr/bin/python3 "$PREDEPLOY"
--app "$APP" \
--app-config-path "$APP_CONFIG_PATH" \
--plugin-path "$PLUGIN_PATH"
} }
dokku-ansible-deploy-post-deploy() { dokku-ansible-deploy-post-deploy() {
@ -126,5 +131,5 @@ dokku-ansible-deploy-post-delete() {
declare POSTDELETE="$PLUGIN_CORE_AVAILABLE_PATH/ansible-deploy/scripts/postdelete.py" declare POSTDELETE="$PLUGIN_CORE_AVAILABLE_PATH/ansible-deploy/scripts/postdelete.py"
dokku_col_log_info1_quiet "Running post-delete steps" dokku_col_log_info1_quiet "Running post-delete steps"
/usr/bin/python3 "$POSTDELETE" "$APP" /usr/bin/python3 "$POSTDELETE"
} }

View File

@ -1,10 +1,47 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from subprocess import check_output
from os.path import exists
from ruamel.yaml import YAML
from argparse import ArgumentParser
def predeploy(): yaml = YAML()
def yaml_load_file(target):
"""Load a YAML file."""
try:
with open(target, "r") as handle:
return yaml.load(handle.read())
except Exception as exception:
msg = "-----> Failed to load {}, saw {}".format(target, str(exception))
print(msg)
def load_config(app_config_path):
"""Load the config.yml if it exists."""
config = "{}/vault/config.yml".format(app_config_path)
if exists(config):
print("-----> Loading {}".format(config))
return yaml_load_file(config)
print("-----> No {} discovered, moving on".format(config))
def pre_deploy(app, app_config_path, plugin_path):
"""Pre-deploy steps.""" """Pre-deploy steps."""
pass config = load_config(app_config_path)
cmd = [
"ansible-playbook",
""
]
if __name__ == '__main__': if __name__ == '__main__':
predeploy() parser = ArgumentParser()
parser.add_argument("--app", help="app name")
parser.add_argument("--app-config-path", help="app config path")
parser.add_argument("--plugin-path", help="plugin path")
args = parser.parse_args()
pre_deploy(args.app, args.app_config_path, args.plugin_path)