use std::{path::Path, process::Command};
use anyhow::Result;
use crate::{
app,
app::CommandExt,
testing::{config::RustToolchainConfig, docker::docker_command, test_runner_dockerfile},
utils::{
self,
environment::{Environment, extract_present},
},
};
pub const ALL_INTEGRATIONS_FEATURE_FLAG: &str = "all-integration-tests";
pub fn prepare_build_command(
image: &str,
dockerfile: &Path,
features: Option<&[String]>,
config_environment_variables: &Environment,
build: bool,
) -> Command {
let mut command = docker_command(["build"]);
command.current_dir(app::path());
if *utils::IS_A_TTY {
command.args(["--progress", "tty"]);
}
command.args([
"--pull",
"--tag",
image,
"--file",
dockerfile.to_str().unwrap(),
"--label",
"vector-test-runner=true",
"--build-arg",
&format!("RUST_VERSION={}", RustToolchainConfig::rust_version()),
"--build-arg",
&format!("FEATURES={}", features.unwrap_or(&[]).join(",")),
"--build-arg",
&format!("BUILD={}", if build { "true" } else { "false" }),
]);
command.envs(extract_present(config_environment_variables));
command.args(["."]);
command
}
pub fn build_integration_image() -> Result<()> {
let dockerfile = test_runner_dockerfile();
let image = format!("vector-test-runner-{}", RustToolchainConfig::rust_version());
let mut cmd = prepare_build_command(
&image,
&dockerfile,
Some(&[
ALL_INTEGRATIONS_FEATURE_FLAG.to_string(),
"vendored".to_string(),
]),
&Environment::default(),
false, );
waiting!("Building {image}");
cmd.check_run()
}