Skip to content

Commit 721f7d0

Browse files
committed
yaml: support overriding the location of nerdctl-full-X.Y.Z-linux-ARCH.tar.gz
e.g., ```yaml containerd: system: false user: true archives: - location: "~/Downloads/nerdctl-full-X.Y.Z-linux-amd64.tar.gz" arch: "x86_64" digest: "sha256:..." ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent e31f365 commit 721f7d0

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

pkg/cidata/cidata.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@ import (
1717
"github.com/lima-vm/lima/pkg/limayaml"
1818
"github.com/lima-vm/lima/pkg/localpathutil"
1919
"github.com/lima-vm/lima/pkg/osutil"
20-
"github.com/lima-vm/lima/pkg/qemu/const"
20+
qemu "github.com/lima-vm/lima/pkg/qemu/const"
2121
"github.com/lima-vm/lima/pkg/sshutil"
2222
"github.com/lima-vm/lima/pkg/store/filenames"
23-
"github.com/opencontainers/go-digest"
2423
"github.com/sirupsen/logrus"
2524
)
2625

27-
const (
28-
NerdctlVersion = "0.12.0"
29-
)
30-
31-
var (
32-
NerdctlFullDigests = map[limayaml.Arch]digest.Digest{
33-
limayaml.X8664: "sha256:7789800cfdd19fa9eccadb5e4a911e4ba759799ad9ec0b7929c983b9d149bc98",
34-
limayaml.AARCH64: "sha256:ebb05e22ac6a3c25ac88ca4f747feed89bfae8e447a626d0fedf3b4f40ac3303",
35-
}
36-
)
37-
3826
func setupEnv(y *limayaml.LimaYAML) (map[string]string, error) {
3927
// Start with the proxy variables from the system settings.
4028
env, err := osutil.ProxySettings()
@@ -177,33 +165,32 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML) error {
177165
}
178166

179167
if args.Containerd.System || args.Containerd.User {
180-
var nftgzBase string
181-
switch y.Arch {
182-
case limayaml.X8664:
183-
nftgzBase = fmt.Sprintf("nerdctl-full-%s-linux-amd64.tar.gz", NerdctlVersion)
184-
case limayaml.AARCH64:
185-
nftgzBase = fmt.Sprintf("nerdctl-full-%s-linux-arm64.tar.gz", NerdctlVersion)
186-
default:
187-
return fmt.Errorf("unexpected arch %q", y.Arch)
168+
var nftgz *limayaml.File
169+
for i := range y.Containerd.Archives {
170+
f := &y.Containerd.Archives[i]
171+
if f.Arch != y.Arch {
172+
continue
173+
}
174+
nftgz = f
175+
}
176+
if nftgz == nil {
177+
return fmt.Errorf("no containerd archive was provided for arch %q", y.Arch)
188178
}
189179
td, err := ioutil.TempDir("", "lima-download-nerdctl")
190180
if err != nil {
191181
return err
192182
}
193183
defer os.RemoveAll(td)
194-
nftgzLocal := filepath.Join(td, nftgzBase)
195-
nftgzURL := fmt.Sprintf("https://github.com/containerd/nerdctl/releases/download/v%s/%s",
196-
NerdctlVersion, nftgzBase)
197-
nftgzDigest := NerdctlFullDigests[y.Arch]
198-
logrus.Infof("Downloading %q (%s)", nftgzURL, nftgzDigest)
199-
res, err := downloader.Download(nftgzLocal, nftgzURL, downloader.WithCache(), downloader.WithExpectedDigest(nftgzDigest))
184+
nftgzLocal := filepath.Join(td, "nerdctl-full.tgz")
185+
logrus.Infof("Downloading %q (%s)", nftgz.Location, nftgz.Digest)
186+
res, err := downloader.Download(nftgzLocal, nftgz.Location, downloader.WithCache(), downloader.WithExpectedDigest(nftgz.Digest))
200187
if err != nil {
201-
return fmt.Errorf("failed to download %q: %w", nftgzURL, err)
188+
return fmt.Errorf("failed to download %q: %w", nftgz.Location, err)
202189
}
203190
logrus.Debugf("res.ValidatedDigest=%v", res.ValidatedDigest)
204191
switch res.Status {
205192
case downloader.StatusDownloaded:
206-
logrus.Infof("Downloaded %q", nftgzBase)
193+
logrus.Infof("Downloaded %q", nftgz.Location)
207194
case downloader.StatusUsedCache:
208195
logrus.Infof("Using cache %q", res.CachePath)
209196
default:

pkg/limayaml/default.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ containerd:
7070
# Enable user-scoped (aka rootless) containerd and its dependencies
7171
# Default: true
7272
user: true
73+
# # Override containerd archive
74+
# # Default: hard-coded URL with hard-coded digest
75+
# archives:
76+
# - location: "~/Downloads/nerdctl-full-X.Y.Z-linux-amd64.tar.gz"
77+
# arch: "x86_64"
78+
# digest: "sha256:..."
7379

7480
# Provisioning scripts need to be idempotent because they might be called
7581
# multiple times, e.g. when the host VM is being restarted.

pkg/limayaml/defaults.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ import (
1111
"github.com/lima-vm/lima/pkg/osutil"
1212
)
1313

14+
func defaultContainerdArchives() []File {
15+
const nerdctlVersion = "0.12.0"
16+
location := func(goarch string) string {
17+
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-linux-" + goarch + ".tar.gz"
18+
}
19+
return []File{
20+
{
21+
Location: location("amd64"),
22+
Arch: X8664,
23+
Digest: "sha256:7789800cfdd19fa9eccadb5e4a911e4ba759799ad9ec0b7929c983b9d149bc98",
24+
},
25+
{
26+
Location: location("arm64"),
27+
Arch: AARCH64,
28+
Digest: "sha256:ebb05e22ac6a3c25ac88ca4f747feed89bfae8e447a626d0fedf3b4f40ac3303",
29+
},
30+
}
31+
}
32+
1433
func MACAddress(uniqueID string) string {
1534
sha := sha256.Sum256([]byte(osutil.MachineID() + uniqueID))
1635
// "5" is the magic number in the Lima ecosystem.
@@ -59,6 +78,15 @@ func FillDefault(y *LimaYAML, filePath string) {
5978
if y.Containerd.User == nil {
6079
y.Containerd.User = &[]bool{true}[0]
6180
}
81+
if len(y.Containerd.Archives) == 0 {
82+
y.Containerd.Archives = defaultContainerdArchives()
83+
}
84+
for i := range y.Containerd.Archives {
85+
f := &y.Containerd.Archives[i]
86+
if f.Arch == "" {
87+
f.Arch = y.Arch
88+
}
89+
}
6290
for i := range y.Probes {
6391
probe := &y.Probes[i]
6492
if probe.Mode == "" {
@@ -79,10 +107,10 @@ func FillDefault(y *LimaYAML, filePath string) {
79107
if len(y.Network.VDEDeprecated) > 0 && len(y.Networks) == 0 {
80108
for _, vde := range y.Network.VDEDeprecated {
81109
network := Network{
82-
Interface: vde.Name,
110+
Interface: vde.Name,
83111
MACAddress: vde.MACAddress,
84112
SwitchPort: vde.SwitchPort,
85-
VNL: vde.VNL,
113+
VNL: vde.VNL,
86114
}
87115
y.Networks = append(y.Networks, network)
88116
}

pkg/limayaml/limayaml.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ type Provision struct {
7777
}
7878

7979
type Containerd struct {
80-
System *bool `yaml:"system,omitempty"` // default: false
81-
User *bool `yaml:"user,omitempty"` // default: true
80+
System *bool `yaml:"system,omitempty"` // default: false
81+
User *bool `yaml:"user,omitempty"` // default: true
82+
Archives []File `yaml:"archives,omitempty"` // default: see defaultContainerdArchives
8283
}
8384

8485
type ProbeMode = string

pkg/limayaml/validate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/lima-vm/lima/pkg/localpathutil"
1515
"github.com/lima-vm/lima/pkg/networks"
1616
"github.com/lima-vm/lima/pkg/osutil"
17-
"github.com/lima-vm/lima/pkg/qemu/const"
17+
qemu "github.com/lima-vm/lima/pkg/qemu/const"
1818
"github.com/sirupsen/logrus"
1919
)
2020

@@ -109,6 +109,10 @@ func Validate(y LimaYAML, warn bool) error {
109109
i, ProvisionModeSystem, ProvisionModeUser)
110110
}
111111
}
112+
needsContainerdArchives := (y.Containerd.User != nil && *y.Containerd.User) || (y.Containerd.System != nil && *y.Containerd.System)
113+
if needsContainerdArchives && len(y.Containerd.Archives) == 0 {
114+
return fmt.Errorf("field `containerd.archives` must be provided")
115+
}
112116
for i, p := range y.Probes {
113117
switch p.Mode {
114118
case ProbeModeReadiness:

0 commit comments

Comments
 (0)