def __docker_stack( self, cli_context: CliContext, subcommand: Iterable[str] ) -> CompletedProcess: command = ["docker", "stack"] command.extend(subcommand) command.append(cli_context.get_project_name()) return self.__exec_command(command)
def __docker_stack(self, cli_context: CliContext, subcommand: Iterable[str]) -> CompletedProcess: # This is now broken since the Docker image no longer includes a Docker installation. # TODO: (GH-115) Replace this call with using the `docker` python library which only requires access to the docker.sock command = ["docker", "stack"] command.extend(subcommand) command.append(cli_context.get_project_name()) return self.__exec_command(command)
def execute_compose( cli_context: CliContext, command: Iterable[str], docker_compose_file_relative_path: Path, docker_compose_override_directory_relative_path: Path, stdin_input: str = None, ) -> CompletedProcess: """Builds and executes a docker-compose command. Args: cli_context (CliContext): The current CLI context. command (Iterable[str]): The command to execute with docker-compose. docker_compose_file_relative_path (Path): The relative path to the docker-compose file. Path is relative to the generated configuration directory. docker_compose_override_directory_relative_path (Path): The relative path to a directory containing docker-compose override files. Path is relative to the generated configuration directory. stdin_input (str): Optional - defaults to None. String passed through to the subprocess via stdin. Returns: CompletedProcess: The completed process and its exit code. """ docker_compose_command = [ "docker-compose", "--project-name", cli_context.get_project_name(), ] compose_files = decrypt_docker_compose_files( cli_context, docker_compose_file_relative_path, docker_compose_override_directory_relative_path, ) if len(compose_files) == 0: logger.error( "No valid docker compose files were found. Expected file [%s] or files in directory [%s]", docker_compose_file_relative_path, docker_compose_override_directory_relative_path, ) return CompletedProcess(args=None, returncode=1) for compose_file in compose_files: docker_compose_command.extend(("--file", str(compose_file))) if command is not None: docker_compose_command.extend(command) logger.debug(docker_compose_command) logger.debug("Running [%s]", " ".join(docker_compose_command)) encoded_input = stdin_input.encode("utf-8") if stdin_input is not None else None logger.debug(f"Encoded input: [{encoded_input}]") result = subprocess.run( docker_compose_command, capture_output=True, input=encoded_input ) return result
def execute_compose( cli_context: CliContext, command: Iterable[str], docker_compose_file_relative_path: Path, docker_compose_override_directory_relative_path: Path, ) -> CompletedProcess: """Builds and executes a docker-compose command. Args: cli_context (CliContext): The current CLI context. command (Iterable[str]): The command to execute with docker-compose. docker_compose_file_relative_path (Path): The relative path to the docker-compose file. Path is relative to the generated configuration directory. docker_compose_override_directory_relative_path (Path): The relative path to a directory containing docker-compose override files. Path is relative to the generated configuration directory. Returns: CompletedProcess: The completed process and its exit code. """ docker_compose_command = [ "docker-compose", "--project-name", cli_context.get_project_name(), ] compose_files = decrypt_docker_compose_files( cli_context, docker_compose_file_relative_path, docker_compose_override_directory_relative_path, ) if len(compose_files) == 0: logger.error( "No valid docker compose files were found. Expected file [%s] or files in directory [%s]", docker_compose_file_relative_path, docker_compose_override_directory_relative_path, ) return CompletedProcess(args=None, returncode=1) for compose_file in compose_files: docker_compose_command.extend(("--file", str(compose_file))) if command is not None: docker_compose_command.extend(command) logger.debug("Running [%s]", " ".join(docker_compose_command)) result = run(docker_compose_command) return result