Skip to content

Commit

Permalink
Allow compressing lima-guestagent with gzip
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jun 30, 2024
1 parent ce3c041 commit 3d495ed
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ config GUESTAGENT_ARCH_RISCV64
help
Build lima-guestagent for "riscv64" Arch
default y

config GUESTAGENT_COMPRESS
bool "guestagent compress"
help
Compress lima-guestagent
default n
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,26 @@ HELPERS = \
_output/bin/podman.lima \
_output/bin/kubectl.lima

ifeq ($(CONFIG_GUESTAGENT_COMPRESS),y)
gz = .gz
endif

ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
ifeq ($(CONFIG_GUESTAGENT_ARCH_X8664),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-x86_64
_output/share/lima/lima-guestagent.Linux-x86_64$(gz)
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_AARCH64),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-aarch64
_output/share/lima/lima-guestagent.Linux-aarch64$(gz)
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_ARMV7L),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-armv7l
_output/share/lima/lima-guestagent.Linux-armv7l$(gz)
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_RISCV64),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-riscv64
_output/share/lima/lima-guestagent.Linux-riscv64$(gz)
endif
endif

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

_output/share/lima/lima-guestagent.%.gz: _output/share/lima/lima-guestagent.%
gzip $<

.PHONY: manpages
manpages: _output/bin/limactl$(exe)
@mkdir -p _output/share/man/man1
Expand Down
1 change: 1 addition & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CONFIG_GUESTAGENT_ARCH_X8664=y
CONFIG_GUESTAGENT_ARCH_AARCH64=y
CONFIG_GUESTAGENT_ARCH_ARMV7L=y
CONFIG_GUESTAGENT_ARCH_RISCV64=y
CONFIG_GUESTAGENT_COMPRESS=n
2 changes: 1 addition & 1 deletion pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
if err != nil {
return err
}
guestAgent, err := os.Open(guestAgentBinary)
guestAgent, err := usrlocalsharelima.Open(guestAgentBinary)
if err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/usrlocalsharelima/usrlocalsharelima.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package usrlocalsharelima

import (
"compress/gzip"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime"

"github.com/lima-vm/lima/pkg/limayaml"
"github.com/sirupsen/logrus"
)

func Dir() (string, error) {
Expand Down Expand Up @@ -55,6 +58,11 @@ func Dir() (string, error) {
} else if !errors.Is(err, os.ErrNotExist) {
return "", err
}
if _, err := os.Stat(gaCandidate + ".gz"); err == nil {
return filepath.Dir(gaCandidate), nil
} else if !errors.Is(err, os.ErrNotExist) {
return "", err
}
}

return "", fmt.Errorf("failed to find \"lima-guestagent.%s-%s\" binary for %q, attempted %v",
Expand All @@ -74,3 +82,19 @@ func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (string, error) {
}
return filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch), nil
}

func Open(path string) (io.ReadCloser, error) {
reader, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) {
reader, err := os.Open(path + ".gz")
if err != nil {
return nil, err
}
logrus.Debugf("Decompressing %s.gz", path)
return gzip.NewReader(reader)
}
if err != nil {
return nil, err
}
return reader, nil
}

0 comments on commit 3d495ed

Please sign in to comment.