Create a tar archive of a directory for use as a Docker build context. Walks `context_dir` recursively, respects a `.dockerignore` file if present, and adds matching files with paths relative to the context root.
(context_dir: &Path)
| 267 | /// Walks `context_dir` recursively, respects a `.dockerignore` file if present, |
| 268 | /// and adds matching files with paths relative to the context root. |
| 269 | fn create_build_context_tar(context_dir: &Path) -> Result<Vec<u8>> { |
| 270 | let ignore_patterns = load_dockerignore(context_dir); |
| 271 | |
| 272 | let mut builder = tar::Builder::new(Vec::new()); |
| 273 | |
| 274 | // Walk the directory tree and add entries, skipping ignored paths. |
| 275 | walk_and_add(context_dir, context_dir, &ignore_patterns, &mut builder)?; |
| 276 | |
| 277 | builder |
| 278 | .into_inner() |
| 279 | .into_diagnostic() |
| 280 | .wrap_err("failed to finalize build context tar") |
| 281 | } |
| 282 | |
| 283 | /// Recursively walk a directory and add entries to a tar archive, |
| 284 | /// skipping paths that match `.dockerignore` patterns. |