From ced68f2e9e028220034e2f59631e18a58e17e7a5 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Fri, 9 Jan 2026 12:20:06 +0100 Subject: [PATCH] feat: Add conditional unpacking support - Introduced build tags to enable or disable the unpack image functionality - Added a new file `unpack_image_disabled.go` to handle cases when unpacking is disabled - Updated existing files to accommodate the new build tag structure This allows yip consumers to not build the unpack plugin if desired which saves 1243kB of deps from the following deps: - github.com/google/go-containerregistry -> 512 kB - github.com/docker/docker -> 391 kB - go.opentelemetry.io/otel -> 340 kB Signed-off-by: Itxaka --- pkg/plugins/unpack_image.go | 11 +++++++---- pkg/plugins/unpack_image_disabled.go | 17 +++++++++++++++++ pkg/plugins/unpack_image_test.go | 5 ++++- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 pkg/plugins/unpack_image_disabled.go diff --git a/pkg/plugins/unpack_image.go b/pkg/plugins/unpack_image.go index d7a5f1bb..a35233c2 100644 --- a/pkg/plugins/unpack_image.go +++ b/pkg/plugins/unpack_image.go @@ -1,8 +1,15 @@ +//go:build !nounpack + package plugins import ( "context" "fmt" + "net/http" + "os" + "runtime" + "syscall" + "github.com/containerd/containerd/archive" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" @@ -15,10 +22,6 @@ import ( "github.com/mudler/yip/pkg/logger" "github.com/mudler/yip/pkg/schema" "github.com/twpayne/go-vfs/v4" - "net/http" - "os" - "runtime" - "syscall" ) func UnpackImage(l logger.Interface, s schema.Stage, fs vfs.FS, console Console) error { diff --git a/pkg/plugins/unpack_image_disabled.go b/pkg/plugins/unpack_image_disabled.go new file mode 100644 index 00000000..0d2521bf --- /dev/null +++ b/pkg/plugins/unpack_image_disabled.go @@ -0,0 +1,17 @@ +//go:build nounpack + +package plugins + +import ( + "github.com/mudler/yip/pkg/logger" + "github.com/mudler/yip/pkg/schema" + "github.com/twpayne/go-vfs/v4" +) + +func UnpackImage(l logger.Interface, s schema.Stage, _ vfs.FS, _ Console) error { + if len(s.UnpackImages) == 0 { + return nil + } + l.Warn("Unpack image plugin is disabled at build time") + return nil +} diff --git a/pkg/plugins/unpack_image_test.go b/pkg/plugins/unpack_image_test.go index beba4a91..3b776d21 100644 --- a/pkg/plugins/unpack_image_test.go +++ b/pkg/plugins/unpack_image_test.go @@ -1,7 +1,11 @@ +//go:build !nounpack + package plugins_test import ( "debug/elf" + "os" + . "github.com/mudler/yip/pkg/plugins" "github.com/mudler/yip/pkg/schema" consoletests "github.com/mudler/yip/tests/console" @@ -9,7 +13,6 @@ import ( . "github.com/onsi/gomega" "github.com/sirupsen/logrus" "github.com/twpayne/go-vfs/v4" - "os" ) var _ = Describe("UnpackImage", Label("unpack_image"), func() {