-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.rs
More file actions
1657 lines (1487 loc) · 44.8 KB
/
build.rs
File metadata and controls
1657 lines (1487 loc) · 44.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Docker build command implementation.
//!
//! This module provides a comprehensive implementation of the `docker build` command
//! with support for all native options and an extensible architecture for any additional options.
use super::{CommandExecutor, DockerCommand};
use crate::error::Result;
use crate::stream::{OutputLine, StreamResult, StreamableCommand};
use async_trait::async_trait;
use std::collections::HashMap;
use std::path::PathBuf;
use tokio::process::Command as TokioCommand;
use tokio::sync::mpsc;
/// Docker build command builder with fluent API
#[derive(Debug, Clone)]
#[allow(clippy::struct_excessive_bools)]
pub struct BuildCommand {
/// Build context (path, URL, or stdin)
context: String,
/// Command executor for extensibility
pub executor: CommandExecutor,
/// Custom host-to-IP mappings
add_hosts: Vec<String>,
/// Build-time variables
build_args: HashMap<String, String>,
/// Images to consider as cache sources
cache_from: Vec<String>,
/// Parent cgroup for RUN instructions
cgroup_parent: Option<String>,
/// Compress the build context using gzip
compress: bool,
/// CPU limits
cpu_period: Option<i64>,
cpu_quota: Option<i64>,
cpu_shares: Option<i64>,
cpuset_cpus: Option<String>,
cpuset_mems: Option<String>,
/// Skip image verification
disable_content_trust: bool,
/// Name of the Dockerfile
file: Option<PathBuf>,
/// Always remove intermediate containers
force_rm: bool,
/// Write the image ID to file
iidfile: Option<PathBuf>,
/// Container isolation technology
isolation: Option<String>,
/// Set metadata for an image
labels: HashMap<String, String>,
/// Memory limit
memory: Option<String>,
/// Memory + swap limit
memory_swap: Option<String>,
/// Networking mode for RUN instructions
network: Option<String>,
/// Do not use cache when building
no_cache: bool,
/// Set platform for multi-platform builds
platform: Option<String>,
/// Always attempt to pull newer base images
pull: bool,
/// Suppress build output and print image ID on success
quiet: bool,
/// Remove intermediate containers after successful build
rm: bool,
/// Security options
security_opts: Vec<String>,
/// Size of /dev/shm
shm_size: Option<String>,
/// Name and tag for the image
tags: Vec<String>,
/// Target build stage
target: Option<String>,
/// Ulimit options
ulimits: Vec<String>,
/// Extra privileged entitlements
allow: Vec<String>,
/// Annotations to add to the image
annotations: Vec<String>,
/// Attestation parameters
attestations: Vec<String>,
/// Additional build contexts
build_contexts: Vec<String>,
/// Override the configured builder
builder: Option<String>,
/// Cache export destinations
cache_to: Vec<String>,
/// Method for evaluating build
call: Option<String>,
/// Shorthand for "--call=check"
check: bool,
/// Shorthand for "--output=type=docker"
load: bool,
/// Write build result metadata to file
metadata_file: Option<PathBuf>,
/// Do not cache specified stages
no_cache_filter: Vec<String>,
/// Type of progress output
progress: Option<String>,
/// Shorthand for "--attest=type=provenance"
provenance: Option<String>,
/// Shorthand for "--output=type=registry"
push: bool,
/// Shorthand for "--attest=type=sbom"
sbom: Option<String>,
/// Secrets to expose to the build
secrets: Vec<String>,
/// SSH agent socket or keys to expose
ssh: Vec<String>,
}
/// Output from docker build command
#[derive(Debug, Clone)]
pub struct BuildOutput {
/// The raw stdout from the command
pub stdout: String,
/// The raw stderr from the command
pub stderr: String,
/// Exit code from the command
pub exit_code: i32,
/// Built image ID (extracted from output)
pub image_id: Option<String>,
}
impl BuildOutput {
/// Check if the build executed successfully
#[must_use]
pub fn success(&self) -> bool {
self.exit_code == 0
}
/// Get combined output (stdout + stderr)
#[must_use]
pub fn combined_output(&self) -> String {
if self.stderr.is_empty() {
self.stdout.clone()
} else if self.stdout.is_empty() {
self.stderr.clone()
} else {
format!("{}\n{}", self.stdout, self.stderr)
}
}
/// Check if stdout is empty (ignoring whitespace)
#[must_use]
pub fn stdout_is_empty(&self) -> bool {
self.stdout.trim().is_empty()
}
/// Check if stderr is empty (ignoring whitespace)
#[must_use]
pub fn stderr_is_empty(&self) -> bool {
self.stderr.trim().is_empty()
}
/// Extract image ID from build output (best effort)
fn extract_image_id(output: &str) -> Option<String> {
// Look for patterns like "Successfully built abc123def456" or "sha256:..."
for line in output.lines() {
if line.contains("Successfully built ") {
if let Some(id) = line.split("Successfully built ").nth(1) {
return Some(id.trim().to_string());
}
}
if line.starts_with("sha256:") {
return Some(line.trim().to_string());
}
}
None
}
}
impl BuildCommand {
/// Create a new build command for the specified context
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".");
/// ```
pub fn new(context: impl Into<String>) -> Self {
Self {
context: context.into(),
executor: CommandExecutor::new(),
add_hosts: Vec::new(),
build_args: HashMap::new(),
cache_from: Vec::new(),
cgroup_parent: None,
compress: false,
cpu_period: None,
cpu_quota: None,
cpu_shares: None,
cpuset_cpus: None,
cpuset_mems: None,
disable_content_trust: false,
file: None,
force_rm: false,
iidfile: None,
isolation: None,
labels: HashMap::new(),
memory: None,
memory_swap: None,
network: None,
no_cache: false,
platform: None,
pull: false,
quiet: false,
rm: true, // Default is true
security_opts: Vec::new(),
shm_size: None,
tags: Vec::new(),
target: None,
ulimits: Vec::new(),
allow: Vec::new(),
annotations: Vec::new(),
attestations: Vec::new(),
build_contexts: Vec::new(),
builder: None,
cache_to: Vec::new(),
call: None,
check: false,
load: false,
metadata_file: None,
no_cache_filter: Vec::new(),
progress: None,
provenance: None,
push: false,
sbom: None,
secrets: Vec::new(),
ssh: Vec::new(),
}
}
/// Add a custom host-to-IP mapping
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .add_host("myhost:192.168.1.100");
/// ```
#[must_use]
pub fn add_host(mut self, host: impl Into<String>) -> Self {
self.add_hosts.push(host.into());
self
}
/// Set a build-time variable
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .build_arg("VERSION", "1.0.0")
/// .build_arg("DEBUG", "true");
/// ```
#[must_use]
pub fn build_arg(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.build_args.insert(key.into(), value.into());
self
}
/// Set multiple build-time variables
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
/// use std::collections::HashMap;
///
/// let mut args = HashMap::new();
/// args.insert("VERSION".to_string(), "1.0.0".to_string());
/// args.insert("DEBUG".to_string(), "true".to_string());
///
/// let build_cmd = BuildCommand::new(".").build_args_map(args);
/// ```
#[must_use]
pub fn build_args_map(mut self, args: HashMap<String, String>) -> Self {
self.build_args.extend(args);
self
}
/// Add an image to consider as cache source
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cache_from("myapp:cache");
/// ```
#[must_use]
pub fn cache_from(mut self, image: impl Into<String>) -> Self {
self.cache_from.push(image.into());
self
}
/// Set the parent cgroup for RUN instructions
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cgroup_parent("/docker");
/// ```
#[must_use]
pub fn cgroup_parent(mut self, parent: impl Into<String>) -> Self {
self.cgroup_parent = Some(parent.into());
self
}
/// Compress the build context using gzip
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".").compress();
/// ```
#[must_use]
pub fn compress(mut self) -> Self {
self.compress = true;
self
}
/// Set CPU period limit
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cpu_period(100000);
/// ```
#[must_use]
pub fn cpu_period(mut self, period: i64) -> Self {
self.cpu_period = Some(period);
self
}
/// Set CPU quota limit
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cpu_quota(50000);
/// ```
#[must_use]
pub fn cpu_quota(mut self, quota: i64) -> Self {
self.cpu_quota = Some(quota);
self
}
/// Set CPU shares (relative weight)
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cpu_shares(512);
/// ```
#[must_use]
pub fn cpu_shares(mut self, shares: i64) -> Self {
self.cpu_shares = Some(shares);
self
}
/// Set CPUs in which to allow execution
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cpuset_cpus("0-3");
/// ```
#[must_use]
pub fn cpuset_cpus(mut self, cpus: impl Into<String>) -> Self {
self.cpuset_cpus = Some(cpus.into());
self
}
/// Set MEMs in which to allow execution
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cpuset_mems("0-1");
/// ```
#[must_use]
pub fn cpuset_mems(mut self, mems: impl Into<String>) -> Self {
self.cpuset_mems = Some(mems.into());
self
}
/// Skip image verification
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .disable_content_trust();
/// ```
#[must_use]
pub fn disable_content_trust(mut self) -> Self {
self.disable_content_trust = true;
self
}
/// Set the name/path of the Dockerfile
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .file("Dockerfile.prod");
/// ```
#[must_use]
pub fn file(mut self, dockerfile: impl Into<PathBuf>) -> Self {
self.file = Some(dockerfile.into());
self
}
/// Always remove intermediate containers
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .force_rm();
/// ```
#[must_use]
pub fn force_rm(mut self) -> Self {
self.force_rm = true;
self
}
/// Write the image ID to a file
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .iidfile("/tmp/image_id.txt");
/// ```
#[must_use]
pub fn iidfile(mut self, file: impl Into<PathBuf>) -> Self {
self.iidfile = Some(file.into());
self
}
/// Set container isolation technology
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .isolation("hyperv");
/// ```
#[must_use]
pub fn isolation(mut self, isolation: impl Into<String>) -> Self {
self.isolation = Some(isolation.into());
self
}
/// Set metadata label for the image
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .label("version", "1.0.0")
/// .label("maintainer", "[email protected]");
/// ```
#[must_use]
pub fn label(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.labels.insert(key.into(), value.into());
self
}
/// Set multiple metadata labels
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
/// use std::collections::HashMap;
///
/// let mut labels = HashMap::new();
/// labels.insert("version".to_string(), "1.0.0".to_string());
/// labels.insert("env".to_string(), "production".to_string());
///
/// let build_cmd = BuildCommand::new(".").labels(labels);
/// ```
#[must_use]
pub fn labels(mut self, labels: HashMap<String, String>) -> Self {
self.labels.extend(labels);
self
}
/// Set memory limit
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .memory("1g");
/// ```
#[must_use]
pub fn memory(mut self, limit: impl Into<String>) -> Self {
self.memory = Some(limit.into());
self
}
/// Set memory + swap limit
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .memory_swap("2g");
/// ```
#[must_use]
pub fn memory_swap(mut self, limit: impl Into<String>) -> Self {
self.memory_swap = Some(limit.into());
self
}
/// Set networking mode for RUN instructions
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .network("host");
/// ```
#[must_use]
pub fn network(mut self, mode: impl Into<String>) -> Self {
self.network = Some(mode.into());
self
}
/// Do not use cache when building
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .no_cache();
/// ```
#[must_use]
pub fn no_cache(mut self) -> Self {
self.no_cache = true;
self
}
/// Set platform for multi-platform builds
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .platform("linux/amd64");
/// ```
#[must_use]
pub fn platform(mut self, platform: impl Into<String>) -> Self {
self.platform = Some(platform.into());
self
}
/// Always attempt to pull newer base images
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .pull();
/// ```
#[must_use]
pub fn pull(mut self) -> Self {
self.pull = true;
self
}
/// Suppress build output and print image ID on success
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .quiet();
/// ```
#[must_use]
pub fn quiet(mut self) -> Self {
self.quiet = true;
self
}
/// Remove intermediate containers after successful build (default: true)
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .no_rm(); // Don't remove intermediate containers
/// ```
#[must_use]
pub fn no_rm(mut self) -> Self {
self.rm = false;
self
}
/// Add a security option
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .security_opt("seccomp=unconfined");
/// ```
#[must_use]
pub fn security_opt(mut self, opt: impl Into<String>) -> Self {
self.security_opts.push(opt.into());
self
}
/// Set size of /dev/shm
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .shm_size("128m");
/// ```
#[must_use]
pub fn shm_size(mut self, size: impl Into<String>) -> Self {
self.shm_size = Some(size.into());
self
}
/// Add a name and tag for the image
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .tag("myapp:latest")
/// .tag("myapp:1.0.0");
/// ```
#[must_use]
pub fn tag(mut self, tag: impl Into<String>) -> Self {
self.tags.push(tag.into());
self
}
/// Set multiple tags for the image
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let tags = vec!["myapp:latest".to_string(), "myapp:1.0.0".to_string()];
/// let build_cmd = BuildCommand::new(".").tags(tags);
/// ```
#[must_use]
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags.extend(tags);
self
}
/// Set the target build stage
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .target("production");
/// ```
#[must_use]
pub fn target(mut self, stage: impl Into<String>) -> Self {
self.target = Some(stage.into());
self
}
/// Add a ulimit option
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .ulimit("nofile=65536:65536");
/// ```
#[must_use]
pub fn ulimit(mut self, limit: impl Into<String>) -> Self {
self.ulimits.push(limit.into());
self
}
/// Add an extra privileged entitlement
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .allow("network.host");
/// ```
#[must_use]
pub fn allow(mut self, entitlement: impl Into<String>) -> Self {
self.allow.push(entitlement.into());
self
}
/// Add an annotation to the image
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .annotation("org.opencontainers.image.title=MyApp");
/// ```
#[must_use]
pub fn annotation(mut self, annotation: impl Into<String>) -> Self {
self.annotations.push(annotation.into());
self
}
/// Add attestation parameters
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .attest("type=provenance,mode=max");
/// ```
#[must_use]
pub fn attest(mut self, attestation: impl Into<String>) -> Self {
self.attestations.push(attestation.into());
self
}
/// Add additional build context
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .build_context("mycontext=../path");
/// ```
#[must_use]
pub fn build_context(mut self, context: impl Into<String>) -> Self {
self.build_contexts.push(context.into());
self
}
/// Override the configured builder
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .builder("mybuilder");
/// ```
#[must_use]
pub fn builder(mut self, builder: impl Into<String>) -> Self {
self.builder = Some(builder.into());
self
}
/// Add cache export destination
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .cache_to("type=registry,ref=myregistry/cache");
/// ```
#[must_use]
pub fn cache_to(mut self, destination: impl Into<String>) -> Self {
self.cache_to.push(destination.into());
self
}
/// Set method for evaluating build
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .call("check");
/// ```
#[must_use]
pub fn call(mut self, method: impl Into<String>) -> Self {
self.call = Some(method.into());
self
}
/// Enable check mode (shorthand for "--call=check")
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .check();
/// ```
#[must_use]
pub fn check(mut self) -> Self {
self.check = true;
self
}
/// Enable load mode (shorthand for "--output=type=docker")
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .load();
/// ```
#[must_use]
pub fn load(mut self) -> Self {
self.load = true;
self
}
/// Write build result metadata to file
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .metadata_file("/tmp/metadata.json");
/// ```
#[must_use]
pub fn metadata_file(mut self, file: impl Into<PathBuf>) -> Self {
self.metadata_file = Some(file.into());
self
}
/// Do not cache specified stage
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .no_cache_filter("build-stage");
/// ```
#[must_use]
pub fn no_cache_filter(mut self, stage: impl Into<String>) -> Self {
self.no_cache_filter.push(stage.into());
self
}
/// Set type of progress output
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .progress("plain");
/// ```
#[must_use]
pub fn progress(mut self, progress_type: impl Into<String>) -> Self {
self.progress = Some(progress_type.into());
self
}
/// Set provenance attestation (shorthand for "--attest=type=provenance")
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .provenance("mode=max");
/// ```
#[must_use]
pub fn provenance(mut self, provenance: impl Into<String>) -> Self {
self.provenance = Some(provenance.into());
self
}
/// Enable push mode (shorthand for "--output=type=registry")
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .push();
/// ```
#[must_use]
pub fn push(mut self) -> Self {
self.push = true;
self
}
/// Set SBOM attestation (shorthand for "--attest=type=sbom")
///
/// # Examples
///
/// ```
/// use docker_wrapper::BuildCommand;
///
/// let build_cmd = BuildCommand::new(".")
/// .sbom("generator=image");
/// ```
#[must_use]
pub fn sbom(mut self, sbom: impl Into<String>) -> Self {
self.sbom = Some(sbom.into());
self
}
/// Add secret to expose to the build
///