Skip to content

Commit 3d495ed

Browse files
committed
Allow compressing lima-guestagent with gzip
Signed-off-by: Anders F Björklund <[email protected]>
1 parent ce3c041 commit 3d495ed

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ config GUESTAGENT_ARCH_RISCV64
3030
help
3131
Build lima-guestagent for "riscv64" Arch
3232
default y
33+
34+
config GUESTAGENT_COMPRESS
35+
bool "guestagent compress"
36+
help
37+
Compress lima-guestagent
38+
default n

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,26 @@ HELPERS = \
8686
_output/bin/podman.lima \
8787
_output/bin/kubectl.lima
8888

89+
ifeq ($(CONFIG_GUESTAGENT_COMPRESS),y)
90+
gz = .gz
91+
endif
92+
8993
ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
9094
ifeq ($(CONFIG_GUESTAGENT_ARCH_X8664),y)
9195
GUESTAGENT += \
92-
_output/share/lima/lima-guestagent.Linux-x86_64
96+
_output/share/lima/lima-guestagent.Linux-x86_64$(gz)
9397
endif
9498
ifeq ($(CONFIG_GUESTAGENT_ARCH_AARCH64),y)
9599
GUESTAGENT += \
96-
_output/share/lima/lima-guestagent.Linux-aarch64
100+
_output/share/lima/lima-guestagent.Linux-aarch64$(gz)
97101
endif
98102
ifeq ($(CONFIG_GUESTAGENT_ARCH_ARMV7L),y)
99103
GUESTAGENT += \
100-
_output/share/lima/lima-guestagent.Linux-armv7l
104+
_output/share/lima/lima-guestagent.Linux-armv7l$(gz)
101105
endif
102106
ifeq ($(CONFIG_GUESTAGENT_ARCH_RISCV64),y)
103107
GUESTAGENT += \
104-
_output/share/lima/lima-guestagent.Linux-riscv64
108+
_output/share/lima/lima-guestagent.Linux-riscv64$(gz)
105109
endif
106110
endif
107111

@@ -188,6 +192,9 @@ _output/share/lima/lima-guestagent.Linux-riscv64:
188192
GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
189193
chmod 644 $@
190194

195+
_output/share/lima/lima-guestagent.%.gz: _output/share/lima/lima-guestagent.%
196+
gzip $<
197+
191198
.PHONY: manpages
192199
manpages: _output/bin/limactl$(exe)
193200
@mkdir -p _output/share/man/man1

config.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_GUESTAGENT_ARCH_X8664=y
33
CONFIG_GUESTAGENT_ARCH_AARCH64=y
44
CONFIG_GUESTAGENT_ARCH_ARMV7L=y
55
CONFIG_GUESTAGENT_ARCH_RISCV64=y
6+
CONFIG_GUESTAGENT_COMPRESS=n

pkg/cidata/cidata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
345345
if err != nil {
346346
return err
347347
}
348-
guestAgent, err := os.Open(guestAgentBinary)
348+
guestAgent, err := usrlocalsharelima.Open(guestAgentBinary)
349349
if err != nil {
350350
return err
351351
}

pkg/usrlocalsharelima/usrlocalsharelima.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package usrlocalsharelima
22

33
import (
4+
"compress/gzip"
45
"errors"
56
"fmt"
7+
"io"
68
"io/fs"
79
"os"
810
"path/filepath"
911
"runtime"
1012

1113
"github.com/lima-vm/lima/pkg/limayaml"
14+
"github.com/sirupsen/logrus"
1215
)
1316

1417
func Dir() (string, error) {
@@ -55,6 +58,11 @@ func Dir() (string, error) {
5558
} else if !errors.Is(err, os.ErrNotExist) {
5659
return "", err
5760
}
61+
if _, err := os.Stat(gaCandidate + ".gz"); err == nil {
62+
return filepath.Dir(gaCandidate), nil
63+
} else if !errors.Is(err, os.ErrNotExist) {
64+
return "", err
65+
}
5866
}
5967

6068
return "", fmt.Errorf("failed to find \"lima-guestagent.%s-%s\" binary for %q, attempted %v",
@@ -74,3 +82,19 @@ func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (string, error) {
7482
}
7583
return filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch), nil
7684
}
85+
86+
func Open(path string) (io.ReadCloser, error) {
87+
reader, err := os.Open(path)
88+
if errors.Is(err, os.ErrNotExist) {
89+
reader, err := os.Open(path + ".gz")
90+
if err != nil {
91+
return nil, err
92+
}
93+
logrus.Debugf("Decompressing %s.gz", path)
94+
return gzip.NewReader(reader)
95+
}
96+
if err != nil {
97+
return nil, err
98+
}
99+
return reader, nil
100+
}

0 commit comments

Comments
 (0)