@@ -2,20 +2,26 @@ package cidata
2
2
3
3
import (
4
4
"bytes"
5
+ "fmt"
5
6
"io"
6
7
"io/fs"
8
+ "io/ioutil"
7
9
"os"
8
10
"os/user"
9
11
"path/filepath"
10
12
"strconv"
11
13
14
+ "github.com/AkihiroSuda/lima/pkg/downloader"
12
15
"github.com/AkihiroSuda/lima/pkg/iso9660util"
13
16
"github.com/AkihiroSuda/lima/pkg/limayaml"
14
17
"github.com/AkihiroSuda/lima/pkg/localpathutil"
15
18
"github.com/AkihiroSuda/lima/pkg/sshutil"
16
19
"github.com/pkg/errors"
20
+ "github.com/sirupsen/logrus"
17
21
)
18
22
23
+ const NerdctlVersion = "0.8.3"
24
+
19
25
func GenerateISO9660 (isoPath , name string , y * limayaml.LimaYAML ) error {
20
26
if err := limayaml .ValidateRaw (* y ); err != nil {
21
27
return err
@@ -81,6 +87,50 @@ func GenerateISO9660(isoPath, name string, y *limayaml.LimaYAML) error {
81
87
})
82
88
}
83
89
90
+ if args .Containerd .System || args .Containerd .User {
91
+ var nftgzBase string
92
+ switch y .Arch {
93
+ case limayaml .X8664 :
94
+ nftgzBase = fmt .Sprintf ("nerdctl-full-%s-linux-amd64.tar.gz" , NerdctlVersion )
95
+ case limayaml .AARCH64 :
96
+ nftgzBase = fmt .Sprintf ("nerdctl-full-%s-linux-arm64.tar.gz" , NerdctlVersion )
97
+ default :
98
+ return errors .Errorf ("unexpected arch %q" , y .Arch )
99
+ }
100
+ td , err := ioutil .TempDir ("" , "lima-download-nerdctl" )
101
+ if err != nil {
102
+ return err
103
+ }
104
+ defer os .RemoveAll (td )
105
+ nftgzLocal := filepath .Join (td , nftgzBase )
106
+ nftgzURL := fmt .Sprintf ("https://github.com/containerd/nerdctl/releases/download/v%s/%s" ,
107
+ NerdctlVersion , nftgzBase )
108
+ logrus .Infof ("Downloading %q" , nftgzURL )
109
+ res , err := downloader .Download (nftgzLocal , nftgzURL , downloader .WithCache ())
110
+ if err != nil {
111
+ return errors .Wrapf (err , "failed to download %q" , nftgzURL )
112
+ }
113
+ switch res .Status {
114
+ case downloader .StatusDownloaded :
115
+ logrus .Infof ("Downloaded %q" , nftgzBase )
116
+ case downloader .StatusUsedCache :
117
+ logrus .Infof ("Using cache %q" , res .CachePath )
118
+ default :
119
+ logrus .Warnf ("Unexpected result from downloader.Download(): %+v" , res )
120
+ }
121
+ // TODO: verify sha256
122
+ nftgzR , err := os .Open (nftgzLocal )
123
+ if err != nil {
124
+ return err
125
+ }
126
+ defer nftgzR .Close ()
127
+ layout = append (layout , iso9660util.Entry {
128
+ // ISO9660 requires len(Path) <= 30
129
+ Path : "nerdctl-full.tgz" ,
130
+ Reader : nftgzR ,
131
+ })
132
+ }
133
+
84
134
return iso9660util .Write (isoPath , "cidata" , layout )
85
135
}
86
136
0 commit comments