From dfe70229c1fafc9b6ca39663c2044d25ffc88a62 Mon Sep 17 00:00:00 2001 From: tylen Date: Tue, 8 Jul 2025 22:34:34 +0300 Subject: [PATCH] services: build clis --- services/tools/build_cli.sh | 28 ++++++++++++++++++++++ services/tools/cli/docker_service.py | 35 ++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 services/tools/build_cli.sh diff --git a/services/tools/build_cli.sh b/services/tools/build_cli.sh new file mode 100755 index 0000000..0f08647 --- /dev/null +++ b/services/tools/build_cli.sh @@ -0,0 +1,28 @@ +#!/bin/bash + + +SOURCE_DIR="$(git rev-parse --show-toplevel)/services/tools/cli" +OUTPUT_DIR="$HOME/.local/bin" + +mkdir -p "$OUTPUT_DIR" + +SCRIPTS=( + "${SOURCE_DIR}/docker_service.py" + "${SOURCE_DIR}/create_hardlinks.py" +) + +for script in "${SCRIPTS[@]}"; do + script_name=$(basename "$script" .py | tr '_' '-') + pyinstaller --onefile --distpath "${OUTPUT_DIR}" "${script}" --name "${script_name}" + + if [ $? -eq 0 ]; then + echo "Successfully built $script_name and distributed to $OUTPUT_DIR" + else + echo "Failed to build $script_name" + fi +done + +rm -rf build/ dist/ *.spec + +echo "Build and distribution process completed." + diff --git a/services/tools/cli/docker_service.py b/services/tools/cli/docker_service.py index 8386182..c71c66b 100755 --- a/services/tools/cli/docker_service.py +++ b/services/tools/cli/docker_service.py @@ -16,6 +16,24 @@ defined in a services file. The services file can be supplied as an argument, with a default value of ../services.yaml. ''' +COMPOSE_ACTIONS = [ + "up", + "down", + "build", + "start", + "stop", + "restart", + "logs", + "exec", + "ps", + "config", + "scale", + "pull", + "push", + "rm", + "version" +] + class DockerServiceCLI(BaseCli): def configure_args(self, parser: ArgumentParser): @@ -29,10 +47,18 @@ class DockerServiceCLI(BaseCli): parser.add_argument( '-n', '--service-name', - help='Name of the service to run (default: all)', + help='Name of the service to run (Possibly: all)', required=True, type=str ) + parser.add_argument( + '-a', + '--action', + help='Compose action. default "up". Options: [' + ', '.join(COMPOSE_ACTIONS) + ']', + choices=COMPOSE_ACTIONS, + default=COMPOSE_ACTIONS[0], + type=str + ) def process_args(self, parser: ArgumentParser): args = parser.parse_args() @@ -75,9 +101,10 @@ class DockerServiceCLI(BaseCli): if service.env_file: command_str.append('--env-file') command_str.append(f'{service.env_file}') - command_str.append('up') - command_str.append('--build') - command_str.append('-d') + command_str.append(self.args.action) + if self.args.action == 'up': + command_str.append('--build') + command_str.append('-d') self.info(f"Executing command: {' '.join(command_str)}") return command_str