Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use COMPOSE_FILE env var #86

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions crates/cli/src/docker_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ use eyre::Result;

macro_rules! run_docker_compose {
($compose_path:expr, $($arg:expr),*) => {{
let cmd = determine_docker_compose_command();
match cmd {
Some(mut command) => {
match command.arg("-f").arg($compose_path).args(&[$($arg),*]).output() {
let cmd_info = determine_docker_compose_command();
match cmd_info {
Some((mut command, _version)) => {
// Set the COMPOSE_FILE environment variable
command.env("COMPOSE_FILE", $compose_path);

match command.args(&[$($arg),*]).output() {
Ok(output) => {
if !output.status.success() {
let stderr = str::from_utf8(&output.stderr).unwrap_or("");
Expand All @@ -34,21 +37,27 @@ macro_rules! run_docker_compose {
}};
}

fn determine_docker_compose_command() -> Option<Command> {
fn determine_docker_compose_command() -> Option<(Command, &'static str)> {
if is_command_available("docker compose") {
let mut docker: Command = Command::new("docker");
Some(mem::replace(
docker.arg("compose").stdout(Stdio::inherit()).stderr(Stdio::inherit()),
Command::new("docker"),
Some((
mem::replace(
docker.arg("compose").stdout(Stdio::inherit()).stderr(Stdio::inherit()),
Command::new("docker"),
),
"v2",
))
} else if is_command_available("docker-compose") {
println!(
"using docker-compose. the command is being deprecated, install docker compose plugin"
);
let mut docker: Command = Command::new("docker-compose");
Some(mem::replace(
docker.stdout(Stdio::inherit()).stderr(Stdio::inherit()),
Command::new("docker"),
Some((
mem::replace(
docker.stdout(Stdio::inherit()).stderr(Stdio::inherit()),
Command::new("docker"),
),
"v1",
))
} else {
None
Expand Down
Loading