@@ -43,22 +43,35 @@ func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
43
43
return "" , nil
44
44
}
45
45
46
- errs := make ([]error , len (y .Containerd .Archives ))
47
- for i := range y .Containerd .Archives {
48
- f := & y .Containerd .Archives [i ]
49
- if f .Arch != * y .Arch {
46
+ location , errs := downloadAndCacheArchiveForArch (y .Containerd .Archives , * y .Arch , "nerdctl" )
47
+ if location == "" {
48
+ return "" , fmt .Errorf ("failed to download the nerdctl archive, attempted %d candidates, errors=%v" ,
49
+ len (y .Containerd .Archives ), errs )
50
+ }
51
+
52
+ return location , nil
53
+ }
54
+
55
+ // downloadAndCacheArchiveForArch iterates through a slice of File and tries to download the provided
56
+ // file which matches the supplied arch.
57
+ // The downloader caches remote downloads to disk, and then returns a file path to the archive.
58
+ func downloadAndCacheArchiveForArch (files []limayaml.File , arch limayaml.Arch , archiveType string ) (string , []error ) {
59
+ errs := make ([]error , len (files ))
60
+ for i := range files {
61
+ f := & files [i ]
62
+ if f .Arch != arch {
50
63
errs [i ] = fmt .Errorf ("unsupported arch: %q" , f .Arch )
51
64
continue
52
65
}
53
- logrus .WithField ("digest" , f .Digest ).Infof ("Attempting to download the nerdctl archive from %q" , f .Location )
66
+ logrus .WithField ("digest" , f .Digest ).Infof ("Attempting to download the %s archive from %q" , archiveType , f .Location )
54
67
res , err := downloader .Download ("" , f .Location , downloader .WithCache (), downloader .WithExpectedDigest (f .Digest ))
55
68
if err != nil {
56
69
errs [i ] = fmt .Errorf ("failed to download %q: %w" , f .Location , err )
57
70
continue
58
71
}
59
72
switch res .Status {
60
73
case downloader .StatusDownloaded :
61
- logrus .Infof ("Downloaded the nerdctl archive from %q" , f .Location )
74
+ logrus .Infof ("Downloaded the %s archive from %q" , archiveType , f .Location )
62
75
case downloader .StatusUsedCache :
63
76
logrus .Infof ("Using cache %q" , res .CachePath )
64
77
default :
@@ -68,13 +81,11 @@ func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
68
81
if downloader .IsLocal (f .Location ) {
69
82
return f .Location , nil
70
83
}
71
- return "" , fmt .Errorf ("cache did not contain %q" , f .Location )
84
+ errs [ i ] = fmt .Errorf ("cache did not contain %q" , f .Location )
72
85
}
73
86
return res .CachePath , nil
74
87
}
75
-
76
- return "" , fmt .Errorf ("failed to download the nerdctl archive, attempted %d candidates, errors=%v" ,
77
- len (y .Containerd .Archives ), errs )
88
+ return "" , errs
78
89
}
79
90
80
91
func Start (ctx context.Context , inst * store.Instance ) error {
@@ -132,29 +143,13 @@ func Start(ctx context.Context, inst *store.Instance) error {
132
143
if nerdctlArchiveCache != "" {
133
144
args = append (args , "--nerdctl-archive" , nerdctlArchiveCache )
134
145
}
135
- if y .ExtraArchive != nil {
136
- if y .ExtraArchive .Digest .String () != "" {
137
- if ! y .ExtraArchive .Digest .Algorithm ().Available () {
138
- return fmt .Errorf ("expected digest algorithm %q is not available" , y .ExtraArchive .Digest .Algorithm ())
139
- }
140
- if err := y .ExtraArchive .Digest .Validate (); err != nil {
141
- return err
142
- }
143
- eaBuf , err := os .ReadFile (y .ExtraArchive .Location )
144
- if err != nil {
145
- return err
146
- }
147
- verifier := y .ExtraArchive .Digest .Verifier ()
148
- if _ , err := verifier .Write (eaBuf ); err != nil {
149
- return err
150
- }
151
- if ! verifier .Verified () {
152
- return errors .New ("digest mismatch between supplied digest and calculated digest for extra archive" )
153
- }
154
- }
155
-
156
- args = append (args , "--extra-archive" , y .ExtraArchive .Location )
146
+ location , errs := downloadAndCacheArchiveForArch (y .ExtraArchives , * y .Arch , "extrArchive" )
147
+ if location == "" {
148
+ return fmt .Errorf ("failed to download the extraArchive archive, attempted %d candidates, errors=%v" ,
149
+ len (y .ExtraArchives ), errs )
157
150
}
151
+ args = append (args , "--extra-archive" , location )
152
+
158
153
args = append (args , inst .Name )
159
154
haCmd := exec .CommandContext (ctx , self , args ... )
160
155
0 commit comments