vdev/testing/
build.rs

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
18/// Construct (but do not run) the `docker build` command for a test-runner image.
19/// - `image` is the full tag (e.g. `"vector-test-runner-1.86.0:latest"`).
20/// - `dockerfile` is the path to the Dockerfile (e.g. `scripts/integration/Dockerfile`).
21/// - `features` controls the `FEATURES` build-arg (pass `None` for an empty list).
22pub fn prepare_build_command(
23    image: &str,
24    dockerfile: &Path,
25    features: Option<&[String]>,
26    config_environment_variables: &Environment,
27) -> Command {
28    // Start with `docker build`
29    let mut command = docker_command(["build"]);
30
31    // Ensure we run from the repo root (so `.` context is correct)
32    command.current_dir(app::path());
33
34    // If we're attached to a TTY, show fancy progress
35    if *IS_A_TTY {
36        command.args(["--progress", "tty"]);
37    }
38
39    // Add all of the flags in one go
40    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)]
61/// Build the integration test‐runner image from `scripts/integration/Dockerfile`
62pub 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}