Skip to content

Commit b8a0ed8

Browse files
committed
bugfix:fix limactl panic because of invalid digest
Signed-off-by: ningmingxiao <[email protected]>
1 parent c1b8496 commit b8a0ed8

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ endif
4040

4141
PACKAGE := github.com/lima-vm/lima/v2
4242

43-
VERSION := $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
43+
VERSION := v1.2.1
4444
VERSION_TRIMMED := $(VERSION:v%=%)
4545

4646
KEEP_SYMBOLS ?=
@@ -547,7 +547,7 @@ ifeq ($(GOOS),darwin)
547547
to_uname_m = $(foreach arch,$(1),$(shell echo $(arch) | sed 's/amd64/x86_64/'))
548548
else ifeq ($(GOOS),linux)
549549
# CC is required for cross-compiling on Linux.
550-
CC = $(call to_uname_m,$(GOARCH))-linux-gnu-gcc
550+
CC = gcc
551551
else ifeq ($(GOOS),windows)
552552
# artifact in zip format also provided for Windows.
553553
ARTIFACT_FILE_EXTENSIONS += .zip

pkg/cidata/cidata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ func GenerateCloudConfig(instDir, name string, instConfig *limayaml.LimaYAML) er
337337
if err != nil {
338338
return err
339339
}
340+
340341
// mounts are not included here
341342
args.Mounts = nil
342343
// resolv_conf is not included here

pkg/limayaml/validate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,12 @@ func validateFileObject(f File, fieldName string) error {
425425
errs = errors.Join(errs, fmt.Errorf("field `arch` must be one of %v; got %q", ArchTypes, f.Arch))
426426
}
427427
if f.Digest != "" {
428-
if !f.Digest.Algorithm().Available() {
429-
errs = errors.Join(errs, fmt.Errorf("field `%s.digest` refers to an unavailable digest algorithm", fieldName))
430-
}
431428
if err := f.Digest.Validate(); err != nil {
432429
errs = errors.Join(errs, fmt.Errorf("field `%s.digest` is invalid: %s: %w", fieldName, f.Digest.String(), err))
430+
return errs
431+
}
432+
if !f.Digest.Algorithm().Available() {
433+
errs = errors.Join(errs, fmt.Errorf("field `%s.digest` refers to an unavailable digest algorithm", fieldName))
433434
}
434435
}
435436
return errs

pkg/limayaml/validate_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ func TestValidateMinimumLimaVersion(t *testing.T) {
7373
}
7474
}
7575

76+
func TestValidateDigest(t *testing.T) {
77+
images := `images: [{"location": "/",digest: "69f31d3208895e5f646e345fbc95190e5e311ecd1359a4d6ee2c0b6483ceca03"}]`
78+
validProbe := `probes: [{"script": "#!foo"}]`
79+
y, err := Load([]byte(validProbe+"\n"+images), "lima.yaml")
80+
assert.NilError(t, err)
81+
err = Validate(y, false)
82+
assert.Error(t, err, "field `images[0].digest` is invalid: 69f31d3208895e5f646e345fbc95190e5e311ecd1359a4d6ee2c0b6483ceca03: invalid checksum digest format")
83+
}
84+
7685
func TestValidateProbes(t *testing.T) {
7786
images := `images: [{"location": "/"}]`
7887
validProbe := `probes: [{"script": "#!foo"}]`

templates/default.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,12 @@ containerd:
196196
# The "digest" property is currently unused.
197197
# Relative script files will be resolved relative to the location of the template file.
198198
# 🟢 Builtin default: []
199-
# provision:
200-
# # `system` is executed with root privileges
201-
# - mode: system
202-
# script: |
203-
# #!/bin/bash
204-
# set -eux -o pipefail
205-
# export DEBIAN_FRONTEND=noninteractive
206-
# apt-get install -y vim
199+
provision:
200+
- mode: system
201+
script: |
202+
#!/bin/bash
203+
chmod 777 /etc/ssh/sshd_config
204+
207205
# # `user` is executed without root privileges
208206
# - mode: user
209207
# file:

0 commit comments

Comments
 (0)