Skip to content

Commit c0a4bb2

Browse files
committed
embed dockerfile
1 parent e7c3090 commit c0a4bb2

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/docker_util.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ async fn image_exists(docker: &Docker, image_name: &str) -> bool {
2121
}
2222

2323
/// Build the custom Grafana image if it doesn't exist
24-
async fn build_grafana_image_if_needed(docker: &Docker, image_name: &str) {
24+
async fn build_grafana_image_if_needed(
25+
docker: &Docker,
26+
image_name: &str,
27+
dockerfile_content: &str,
28+
) {
2529
if image_exists(docker, image_name).await {
2630
println!("[*] Using cached Grafana image: {}", image_name);
2731
return;
2832
}
2933

30-
let build_context = "docker/grafana";
34+
let build_context = embed_files::setup_dockerfile(dockerfile_content);
35+
let build_context_str = build_context.to_str().unwrap();
3136

3237
println!("[*] Building custom Grafana image...");
3338
let output = Command::new("docker")
34-
.args(["build", "-t", image_name, build_context])
39+
.args(["build", "-t", image_name, build_context_str])
3540
.output()
3641
.expect("[-] Failed to execute docker build");
3742

@@ -51,6 +56,7 @@ pub async fn start_container<'a>(
5156
report_db_path: &Path,
5257
embedded_dir: &Dir<'a>,
5358
embedded_file: &str,
59+
dockerfile_content: &str,
5460
) {
5561
if !report_db_path.exists() {
5662
eprintln!("[*] Error: The specified report.db path does not exist.");
@@ -103,7 +109,7 @@ pub async fn start_container<'a>(
103109

104110
// Build the custom Grafana image if it doesn't exist
105111
let image_name = "wuppiefuzz-grafana:latest";
106-
build_grafana_image_if_needed(docker, image_name).await;
112+
build_grafana_image_if_needed(docker, image_name, dockerfile_content).await;
107113

108114
// Create the container
109115
let mut create_options = ContainerCreateOptions::new(image_name);

src/embed_files.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ pub fn setup_embedded_files(embedded_dir: &Dir, embedded_file: &str) -> std::pat
5353

5454
temp_dir
5555
}
56+
57+
/// Setup Dockerfile in a temporary build context directory
58+
pub fn setup_dockerfile(dockerfile_content: &str) -> std::path::PathBuf {
59+
let build_context = std::env::temp_dir().join("grafana_build");
60+
fs::create_dir_all(&build_context).expect("Failed to create build context directory");
61+
let dockerfile_path = build_context.join("Dockerfile");
62+
write_embedded_file(&dockerfile_path, dockerfile_content.as_bytes());
63+
build_context
64+
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod embed_files;
1010
// Global variables
1111
pub const CONTAINER_NAME: &str = "grafana-dashboard";
1212
pub const GRAFANA_INI: &str = include_str!("../grafana.ini");
13+
pub const GRAFANA_DOCKERFILE: &str = include_str!("../docker/grafana/Dockerfile");
1314
pub static PROVISIONING_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/provisioning");
1415

1516
#[tokio::main]
@@ -38,6 +39,7 @@ async fn main() {
3839
report_db_path,
3940
&PROVISIONING_DIR,
4041
GRAFANA_INI,
42+
GRAFANA_DOCKERFILE,
4143
)
4244
.await;
4345
}

0 commit comments

Comments
 (0)