From 48fbc99674356612e5ed9d5fc2ee41823a0ca79c Mon Sep 17 00:00:00 2001 From: Pete Cornish Date: Tue, 2 Jul 2024 11:02:18 +0100 Subject: [PATCH] feat: adds support for docker-distroless image. --- cmd/bundle.go | 6 +++++- cmd/common.go | 1 + cmd/engine_pull_test.go | 5 +++++ engine/builder.go | 15 ++++++++------- engine/docker/images.go | 3 +++ engine/docker/library.go | 2 ++ engine/docker/provider.go | 1 + 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cmd/bundle.go b/cmd/bundle.go index 6e6ca37..0b5b8fc 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -86,9 +86,13 @@ func getBundleDest(engineType engine.EngineType) string { if bundleFlags.output != "" { dest = bundleFlags.output } else { - if engineType == engine.EngineTypeDockerCore || engineType == engine.EngineTypeDockerAll { + if engineType == engine.EngineTypeDockerCore || + engineType == engine.EngineTypeDockerAll || + engineType == engine.EngineTypeDockerDistroless { + imageTag := time.Now().Format("20060102150405") dest = "imposter-bundle:" + imageTag + } else { temp, err := os.CreateTemp(os.TempDir(), "imposter-bundle-*.zip") if err != nil { diff --git a/cmd/common.go b/cmd/common.go index 026cc71..292478b 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -8,6 +8,7 @@ import ( var localTypes = []engine.EngineType{ engine.EngineTypeDockerCore, engine.EngineTypeDockerAll, + engine.EngineTypeDockerDistroless, engine.EngineTypeJvmSingleJar, } diff --git a/cmd/engine_pull_test.go b/cmd/engine_pull_test.go index f20024a..5058fd2 100644 --- a/cmd/engine_pull_test.go +++ b/cmd/engine_pull_test.go @@ -51,6 +51,11 @@ func Test_pull(t *testing.T) { engineType: engine.EngineTypeDockerAll, pullPolicy: engine.PullIfNotPresent, }}, + {name: "pull docker all distro if not present", args: args{ + version: "3.44.1", + engineType: engine.EngineTypeDockerDistroless, + pullPolicy: engine.PullIfNotPresent, + }}, {name: "pull latest jvm always", args: args{ version: "latest", engineType: engine.EngineTypeJvmSingleJar, diff --git a/engine/builder.go b/engine/builder.go index bd676e0..bf6caa1 100644 --- a/engine/builder.go +++ b/engine/builder.go @@ -28,12 +28,13 @@ import ( type EngineType string const ( - EngineTypeNone EngineType = "" - EngineTypeAwsLambda EngineType = "awslambda" - EngineTypeDockerCore EngineType = "docker" - EngineTypeDockerAll EngineType = "docker-all" - EngineTypeJvmSingleJar EngineType = "jvm" - EngineTypeJvmUnpacked EngineType = "unpacked" + EngineTypeNone EngineType = "" + EngineTypeAwsLambda EngineType = "awslambda" + EngineTypeDockerCore EngineType = "docker" + EngineTypeDockerAll EngineType = "docker-all" + EngineTypeDockerDistroless EngineType = "docker-distroless" + EngineTypeJvmSingleJar EngineType = "jvm" + EngineTypeJvmUnpacked EngineType = "unpacked" ) const defaultEngineType = EngineTypeDockerCore @@ -100,7 +101,7 @@ func build(engineType EngineType, configDir string, startOptions StartOptions) M func validateEngineType(engineType EngineType) error { switch engineType { - case EngineTypeAwsLambda, EngineTypeDockerCore, EngineTypeDockerAll, EngineTypeJvmSingleJar, EngineTypeJvmUnpacked: + case EngineTypeAwsLambda, EngineTypeDockerCore, EngineTypeDockerAll, EngineTypeDockerDistroless, EngineTypeJvmSingleJar, EngineTypeJvmUnpacked: return nil } return fmt.Errorf("unsupported engine type: %v", engineType) diff --git a/engine/docker/images.go b/engine/docker/images.go index ac414bf..2445795 100644 --- a/engine/docker/images.go +++ b/engine/docker/images.go @@ -127,6 +127,9 @@ func getImageRepo(engineType engine.EngineType) string { case engine.EngineTypeDockerAll: imageRepo = "outofcoffee/imposter-all" break + case engine.EngineTypeDockerDistroless: + imageRepo = "outofcoffee/imposter-distroless" + break default: panic("Unsupported engine type: " + engineType) } diff --git a/engine/docker/library.go b/engine/docker/library.go index afa8eb0..4bf1309 100644 --- a/engine/docker/library.go +++ b/engine/docker/library.go @@ -78,6 +78,8 @@ func (l DockerEngineLibrary) ShouldEnsurePlugins() bool { return true case engine.EngineTypeDockerAll: return false + case engine.EngineTypeDockerDistroless: + return true default: panic(fmt.Errorf("unsupported engine type: %s for Docker library", l.engineType)) } diff --git a/engine/docker/provider.go b/engine/docker/provider.go index ad759aa..2efb1c1 100644 --- a/engine/docker/provider.go +++ b/engine/docker/provider.go @@ -38,6 +38,7 @@ func EnableEngine() { initialised = true register(engine.EngineTypeDockerCore) register(engine.EngineTypeDockerAll) + register(engine.EngineTypeDockerDistroless) } }