diff --git a/main.py b/main.py index da2fa66..e80707d 100755 --- a/main.py +++ b/main.py @@ -16,6 +16,8 @@ import time import base64 import shutil import requests +import tempfile +import subprocess from portainer.api import PortainerApi from git import Repo from concurrent.futures import ThreadPoolExecutor @@ -224,6 +226,37 @@ def wl(msg): if args.debug: print(msg) +def run(cmd, cwd=None): + result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True) + if result.returncode != 0: + raise RuntimeError(result.stderr) + return result.stdout.strip() + +def get_compose_files(): + #git clone --depth=1 --filter=blob:none --no-checkout https://github.com/user/repo.git + with tempfile.TemporaryDirectory() as tmpdir: + repo_path = os.path.join(tmpdir, "repo") + + # Clone with minimal data (no checkout, no blobs) + run([ + "git", "clone", + "--depth=1", + "--filter=blob:none", + "--no-checkout", + "git@gitlab.sectorq.eu:/jaydee/docker-compose.git", + repo_path + ]) + + # List files in HEAD + output = run([ + "git", "ls-tree", + "-r", + "HEAD", + "--name-only" + ], cwd=repo_path) + + print(output) + def prompt_missing_args(args_in, defaults_in, fields, action=None,stacks=None): """ @@ -259,6 +292,7 @@ def prompt_missing_args(args_in, defaults_in, fields, action=None,stacks=None): elif field == "stack": if args.action == "create_stack": # input(json.dumps(stacks, indent=2)) + get_compose_files() commands = [ 'api_server', 'authentik', 'bitwarden', 'bookstack', 'databasus', 'dockermon', 'duplicati', 'fail2ban', 'filebrowser', 'gitea', 'gitlab', 'grafana', 'grocy', 'hashicorp', 'home-assistant', 'homebox','homepage', 'immich', 'influxdb', 'jupyter', 'kestra', 'kopia', 'linkding', 'linkwarden', 'mailu3', diff --git a/portainer/api.py b/portainer/api.py index f691821..72675f1 100644 --- a/portainer/api.py +++ b/portainer/api.py @@ -13,6 +13,8 @@ import tabulate from git import Repo import requests import hvac +import subprocess +import tempfile from prompt_toolkit import prompt from prompt_toolkit.completion import WordCompleter from prompt_toolkit.shortcuts import checkboxlist_dialog