1use std::{path::Path, process::Command};
2
3use anyhow::Result;
4
5use crate::{
6 app,
7 app::CommandExt,
8 testing::{config::RustToolchainConfig, docker::docker_command, test_runner_dockerfile},
9 utils::{
10 self,
11 environment::{Environment, extract_present},
12 },
13};
14
15pub const ALL_INTEGRATIONS_FEATURE_FLAG: &str = "all-integration-tests";
16
17pub fn prepare_build_command(
23 image: &str,
24 dockerfile: &Path,
25 features: Option<&[String]>,
26 config_environment_variables: &Environment,
27 build: bool,
28) -> Command {
29 let mut command = docker_command(["build"]);
31
32 command.current_dir(app::path());
34
35 if *utils::IS_A_TTY {
37 command.args(["--progress", "tty"]);
38 }
39
40 command.args([
42 "--pull",
43 "--tag",
44 image,
45 "--file",
46 dockerfile.to_str().unwrap(),
47 "--label",
48 "vector-test-runner=true",
49 "--build-arg",
50 &format!("RUST_VERSION={}", RustToolchainConfig::rust_version()),
51 "--build-arg",
52 &format!("FEATURES={}", features.unwrap_or(&[]).join(",")),
53 "--build-arg",
54 &format!("BUILD={}", if build { "true" } else { "false" }),
55 ]);
56
57 command.envs(extract_present(config_environment_variables));
58
59 command.args(["."]);
60 command
61}
62
63pub fn build_integration_image() -> Result<()> {
65 let dockerfile = test_runner_dockerfile();
66 let image = format!("vector-test-runner-{}", RustToolchainConfig::rust_version());
67 let mut cmd = prepare_build_command(
68 &image,
69 &dockerfile,
70 Some(&[
71 ALL_INTEGRATIONS_FEATURE_FLAG.to_string(),
72 "vendored".to_string(),
73 ]),
74 &Environment::default(),
75 false, );
77 waiting!("Building {image}");
78 cmd.check_run()
79}