vdev/testing/
build.rs

1use crate::app;
2use crate::app::CommandExt;
3use crate::testing::config::RustToolchainConfig;
4use crate::testing::docker::docker_command;
5use crate::util::IS_A_TTY;
6use anyhow::Result;
7use std::path::PathBuf;
8use std::{path::Path, process::Command};
9
10pub const ALL_INTEGRATIONS_FEATURE_FLAG: &str = "all-integration-tests";
11
12/// Construct (but do not run) the `docker build` command for a test-runner image.
13/// - `image` is the full tag (e.g. `"vector-test-runner-1.86.0:latest"`).
14/// - `dockerfile` is the path to the Dockerfile (e.g. `scripts/integration/Dockerfile`).
15/// - `features` controls the `FEATURES` build-arg (pass `None` for an empty list).
16pub fn prepare_build_command(
17    image: &str,
18    dockerfile: &Path,
19    features: Option<&[String]>,
20) -> Command {
21    // Start with `docker build`
22    let mut cmd = docker_command(["build"]);
23
24    // Ensure we run from the repo root (so `.` context is correct)
25    cmd.current_dir(app::path());
26
27    // If we're attached to a TTY, show fancy progress
28    if *IS_A_TTY {
29        cmd.args(["--progress", "tty"]);
30    }
31
32    // Add all of the flags in one go
33    cmd.args([
34        "--pull",
35        "--tag",
36        image,
37        "--file",
38        dockerfile.to_str().unwrap(),
39        "--label",
40        "vector-test-runner=true",
41        "--build-arg",
42        &format!("RUST_VERSION={}", RustToolchainConfig::rust_version()),
43        "--build-arg",
44        &format!("FEATURES={}", features.unwrap_or(&[]).join(",")),
45        ".",
46    ]);
47
48    cmd
49}
50
51#[allow(dead_code)]
52/// Build the integration test‐runner image from `scripts/integration/Dockerfile`
53pub fn build_integration_image() -> Result<()> {
54    let dockerfile: PathBuf = [app::path(), "scripts", "integration", "Dockerfile"]
55        .iter()
56        .collect();
57    let image = format!("vector-test-runner-{}", RustToolchainConfig::rust_version());
58    let mut cmd = prepare_build_command(
59        &image,
60        &dockerfile,
61        Some(&[ALL_INTEGRATIONS_FEATURE_FLAG.to_string()]),
62    );
63    waiting!("Building {image}");
64    cmd.check_run()
65}