@@ -36,22 +36,35 @@ func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
36
36
return "" , nil
37
37
}
38
38
39
- errs := make ([]error , len (y .Containerd .Archives ))
40
- for i := range y .Containerd .Archives {
41
- f := & y .Containerd .Archives [i ]
42
- if f .Arch != * y .Arch {
39
+ location , errs := downloadAndCacheArchiveForArch (y .Containerd .Archives , * y .Arch , "nerdctl" )
40
+ if location == "" {
41
+ return "" , fmt .Errorf ("failed to download the nerdctl archive, attempted %d candidates, errors=%v" ,
42
+ len (y .Containerd .Archives ), errs )
43
+ }
44
+
45
+ return location , nil
46
+ }
47
+
48
+ // downloadAndCacheArchiveForArch iterates through a slice of File and tries to download the provided
49
+ // file which matches the supplied arch.
50
+ // The downloader caches remote downloads to disk, and then returns a file path to the archive.
51
+ func downloadAndCacheArchiveForArch (files []limayaml.File , arch limayaml.Arch , archiveType string ) (string , []error ) {
52
+ errs := make ([]error , len (files ))
53
+ for i := range files {
54
+ f := & files [i ]
55
+ if f .Arch != arch {
43
56
errs [i ] = fmt .Errorf ("unsupported arch: %q" , f .Arch )
44
57
continue
45
58
}
46
- logrus .WithField ("digest" , f .Digest ).Infof ("Attempting to download the nerdctl archive from %q" , f .Location )
59
+ logrus .WithField ("digest" , f .Digest ).Infof ("Attempting to download the %s archive from %q" , archiveType , f .Location )
47
60
res , err := downloader .Download ("" , f .Location , downloader .WithCache (), downloader .WithExpectedDigest (f .Digest ))
48
61
if err != nil {
49
62
errs [i ] = fmt .Errorf ("failed to download %q: %w" , f .Location , err )
50
63
continue
51
64
}
52
65
switch res .Status {
53
66
case downloader .StatusDownloaded :
54
- logrus .Infof ("Downloaded the nerdctl archive from %q" , f .Location )
67
+ logrus .Infof ("Downloaded the %s archive from %q" , archiveType , f .Location )
55
68
case downloader .StatusUsedCache :
56
69
logrus .Infof ("Using cache %q" , res .CachePath )
57
70
default :
@@ -61,13 +74,11 @@ func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
61
74
if downloader .IsLocal (f .Location ) {
62
75
return f .Location , nil
63
76
}
64
- return "" , fmt .Errorf ("cache did not contain %q" , f .Location )
77
+ errs [ i ] = fmt .Errorf ("cache did not contain %q" , f .Location )
65
78
}
66
79
return res .CachePath , nil
67
80
}
68
-
69
- return "" , fmt .Errorf ("failed to download the nerdctl archive, attempted %d candidates, errors=%v" ,
70
- len (y .Containerd .Archives ), errs )
81
+ return "" , errs
71
82
}
72
83
73
84
func Start (ctx context.Context , inst * store.Instance ) error {
@@ -134,6 +145,15 @@ func Start(ctx context.Context, inst *store.Instance) error {
134
145
if nerdctlArchiveCache != "" {
135
146
args = append (args , "--nerdctl-archive" , nerdctlArchiveCache )
136
147
}
148
+ if len (y .AdditionalArchives ) > 0 {
149
+ location , errs := downloadAndCacheArchiveForArch (y .AdditionalArchives , * y .Arch , "additionalArchive" )
150
+ if location == "" {
151
+ return fmt .Errorf ("failed to download the additionalArchive archive, attempted %d candidates, errors=%v" ,
152
+ len (y .AdditionalArchives ), errs )
153
+ }
154
+ args = append (args , "--additional-archive" , location )
155
+ }
156
+
137
157
args = append (args , inst .Name )
138
158
haCmd := exec .CommandContext (ctx , self , args ... )
139
159
0 commit comments