MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / build_proxy

Method build_proxy

src/docker/proxy_manager.rs:276–337  ·  view source on GitHub ↗

Builds the generic proxy Docker image. The image is always built without custom squid.conf baked in. Per-configuration squid.conf is mounted at container start time via bind mount. # Arguments `no_cache` - Whether to build without using Docker's cache `logger` - Task logger for build output

(&self, no_cache: bool, logger: &TaskLogger)

Source from the content-addressed store, hash-verified

274 /// * `no_cache` - Whether to build without using Docker's cache
275 /// * `logger` - Task logger for build output
276 pub async fn build_proxy(&self, no_cache: bool, logger: &TaskLogger) -> Result<()> {
277 logger.log(LogLine::tsk_message(format!(
278 "Building proxy image: {PROXY_IMAGE}"
279 )));
280
281 use crate::assets::utils::extract_dockerfile_to_temp;
282
283 // Warn about deprecated legacy squid.conf file
284 let legacy_squid_conf = self.tsk_env.config_dir().join("squid.conf");
285 if legacy_squid_conf.exists() {
286 logger.log(LogLine::tsk_warning(format!(
287 "Warning: {} is deprecated. Use squid_conf or squid_conf_path in tsk.toml instead.",
288 legacy_squid_conf.display()
289 )));
290 }
291
292 // Extract dockerfile to temporary directory
293 let dockerfile_dir = extract_dockerfile_to_temp("tsk-proxy")
294 .context("Failed to extract proxy Dockerfile")?;
295
296 // Create tar archive from the proxy dockerfile directory
297 let tar_archive = self
298 .create_tar_archive_from_directory(&dockerfile_dir)
299 .context("Failed to create tar archive for proxy build")?;
300
301 // Clean up the temporary directory
302 let _ = std::fs::remove_dir_all(&dockerfile_dir);
303
304 // Build options for proxy
305 let mut options_builder = bollard::query_parameters::BuildImageOptionsBuilder::default();
306 options_builder = options_builder.dockerfile("Dockerfile");
307 options_builder = options_builder.t(PROXY_IMAGE);
308 options_builder = options_builder.nocache(no_cache);
309 if self.container_engine == ContainerEngine::Podman {
310 options_builder = options_builder.networkmode("host");
311 }
312 let options = options_builder.build();
313
314 // Build the image using the DockerClient
315 let mut build_stream = self
316 .docker_client
317 .build_image(options, tar_archive)
318 .await
319 .map_err(|e| anyhow::anyhow!("Failed to build proxy image: {e}"))?;
320
321 // Capture build output (only displayed on failure to reduce noise)
322 use futures_util::StreamExt;
323 let mut build_output = String::new();
324 while let Some(result) = build_stream.next().await {
325 match result {
326 Ok(line) => {
327 build_output.push_str(&line);
328 }
329 Err(e) => {
330 logger.log(LogLine::tsk_message(&build_output));
331 return Err(anyhow::anyhow!("Failed to build proxy image: {e}"));
332 }
333 }

Callers 3

executeMethod · 0.80
ensure_proxyMethod · 0.80

Calls 6

logMethod · 0.80
config_dirMethod · 0.80
buildMethod · 0.45
build_imageMethod · 0.45