This commit is contained in:
@@ -7,6 +7,9 @@ from subprocess import run
|
|||||||
|
|
||||||
SOURCE = os.environ.get("PLUGIN_SOURCE", ".")
|
SOURCE = os.environ.get("PLUGIN_SOURCE", ".")
|
||||||
TARGET = os.environ['PLUGIN_TARGET']
|
TARGET = os.environ['PLUGIN_TARGET']
|
||||||
|
HOST = os.environ.get("PLUGIN_HOST", "")
|
||||||
|
PRE_COMMAND = os.environ.get("PLUGIN_PRE", "")
|
||||||
|
POST_COMMAND = os.environ.get("PLUGIN_POST", "")
|
||||||
|
|
||||||
def is_target_http(target):
|
def is_target_http(target):
|
||||||
return target.startswith("http://") or target.startswith("https://")
|
return target.startswith("http://") or target.startswith("https://")
|
||||||
@@ -26,6 +29,9 @@ def apply_key_permissions(keyfile):
|
|||||||
run(["Icacls", keyfile, "/c", "/t", "/Remove:g", other_user])
|
run(["Icacls", keyfile, "/c", "/t", "/Remove:g", other_user])
|
||||||
run(["Icacls", keyfile])
|
run(["Icacls", keyfile])
|
||||||
|
|
||||||
|
def run_command(host, command, auth):
|
||||||
|
run(["ssh", "-i", auth, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "sh", "-c", command], check=True)
|
||||||
|
|
||||||
def make_parent_dirs(target, auth):
|
def make_parent_dirs(target, auth):
|
||||||
if is_target_http(target):
|
if is_target_http(target):
|
||||||
return
|
return
|
||||||
@@ -46,6 +52,18 @@ def deploy_file(source_file, target, auth):
|
|||||||
|
|
||||||
temp_file_name = None
|
temp_file_name = None
|
||||||
auth = None
|
auth = None
|
||||||
|
|
||||||
|
if HOST:
|
||||||
|
if is_target_http(HOST):
|
||||||
|
TARGET = f"{HOST}/{TARGET}"
|
||||||
|
else:
|
||||||
|
TARGET = f"{HOST}:{TARGET}"
|
||||||
|
else:
|
||||||
|
if is_target_http(TARGET):
|
||||||
|
HOST = TARGET.split("/")[0]
|
||||||
|
else:
|
||||||
|
HOST = TARGET.split(":")[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if 'PLUGIN_KEY' in os.environ:
|
if 'PLUGIN_KEY' in os.environ:
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
||||||
@@ -59,8 +77,14 @@ try:
|
|||||||
else:
|
else:
|
||||||
auth = os.environ['PLUGIN_AUTHENTICATION']
|
auth = os.environ['PLUGIN_AUTHENTICATION']
|
||||||
|
|
||||||
|
if PRE_COMMAND:
|
||||||
|
run_command(HOST, PRE_COMMAND, auth)
|
||||||
|
|
||||||
#make_parent_dirs(TARGET, auth)
|
#make_parent_dirs(TARGET, auth)
|
||||||
deploy(SOURCE, TARGET, auth)
|
deploy(SOURCE, TARGET, auth)
|
||||||
|
|
||||||
|
if POST_COMMAND:
|
||||||
|
run_command(HOST, POST_COMMAND, auth)
|
||||||
finally:
|
finally:
|
||||||
if temp_file_name is not None:
|
if temp_file_name is not None:
|
||||||
os.remove(temp_file_name)
|
os.remove(temp_file_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user