From 8d4ce999225854797b34ad05cbd405a92e55e92a Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Thu, 27 Mar 2025 20:10:35 +0100 Subject: [PATCH] refactor(container): streamline container command execution Simplified the process of constructing and executing container commands to enhance maintainability and reduce redundancy. - Removed redundant appending of image_tag and action to docker_opts in run.cr. - Modified command construction in docker_engine.cr to use pre-built cmd array, enhancing clarity. - Updated podman_engine.cr to utilize cmd array for process execution, ensuring consistency across container engines. Signed-off-by: Glenn Y. Rolland --- src/build/run.cr | 5 +---- src/container/docker_engine.cr | 2 +- src/container/podman_engine.cr | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/build/run.cr b/src/build/run.cr index 10f11b5..9db3586 100644 --- a/src/build/run.cr +++ b/src/build/run.cr @@ -182,11 +182,8 @@ module DocMachine::Build Log.info { "Slides: no slides directory detected." } end - docker_opts << @config.image_tag - docker_opts << @config.action - Log.info { - docker_str = [@config.container_runtime].concat(docker_opts).join(" ").colorize(:yellow) + docker_str = [@config.container_runtime, "run"].concat(docker_opts).join(" ").colorize(:yellow) "#{@config.container_runtime.capitalize}: #{docker_str}" } diff --git a/src/container/docker_engine.cr b/src/container/docker_engine.cr index 1b82fbb..bb4227e 100644 --- a/src/container/docker_engine.cr +++ b/src/container/docker_engine.cr @@ -57,7 +57,7 @@ module DocMachine::Container Log.debug { "Docker run command: #{cmd.join(" ")}" } # Start the Docker container process - process = Process.new("docker", ["run"] + docker_opts + [image_tag, action], input: STDIN, output: STDOUT, error: STDERR) + process = Process.new(cmd.first, cmd.skip(1), input: STDIN, output: STDOUT, error: STDERR) Log.info { "Docker container #{docker_name} started." } diff --git a/src/container/podman_engine.cr b/src/container/podman_engine.cr index 0b02904..3a223e7 100644 --- a/src/container/podman_engine.cr +++ b/src/container/podman_engine.cr @@ -55,7 +55,7 @@ module DocMachine::Container Log.debug { "Podman run command: #{cmd.join(" ")}" } # Start the Podman container process - process = Process.new("podman", ["run"] + docker_opts + [image_tag, action], input: STDIN, output: STDOUT, error: STDERR) + process = Process.new(cmd.first, cmd.skip(1), input: STDIN, output: STDOUT, error: STDERR) Log.info { "Podman container #{docker_name} started." }