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