vdev/testing/
build.rs

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
17/// Construct (but do not run) the `docker build` command for a test-runner image.
18/// - `image` is the full tag (e.g. `"vector-test-runner-1.86.0:latest"`).
19/// - `dockerfile` is the path to the Dockerfile (e.g. `tests/e2e/Dockerfile`).
20/// - `features` controls the `FEATURES` build-arg (pass `None` for an empty list).
21/// - `build` controls whether to build the Vector binary in the image.
22pub 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    // Start with `docker build`
30    let mut command = docker_command(["build"]);
31
32    // Ensure we run from the repo root (so `.` context is correct)
33    command.current_dir(app::path());
34
35    // If we're attached to a TTY, show fancy progress
36    if *utils::IS_A_TTY {
37        command.args(["--progress", "tty"]);
38    }
39
40    // Add all of the flags in one go
41    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
63/// Build the integration test‐runner image from `tests/e2e/Dockerfile`
64pub 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, // Integration tests don't pre-build Vector tests.
76    );
77    waiting!("Building {image}");
78    cmd.check_run()
79}