From 5766e6a0fa6bc5400190805e6708d70ae3b3f10a Mon Sep 17 00:00:00 2001 From: Ilya Lesikov Date: Fri, 17 Jun 2022 16:13:37 +0300 Subject: [PATCH] feat(buildah): $WERF_CONTAINERIZED will override in container detection Signed-off-by: Ilya Lesikov --- pkg/util/env.go | 13 +++++++++++++ pkg/util/linux_container.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/pkg/util/env.go b/pkg/util/env.go index 7074492df8..065b350dec 100644 --- a/pkg/util/env.go +++ b/pkg/util/env.go @@ -8,6 +8,19 @@ import ( "strings" ) +func GetBoolEnvironment(environmentName string) *bool { + switch os.Getenv(environmentName) { + case "1", "true", "yes": + t := true + return &t + case "0", "false", "no": + f := false + return &f + } + + return nil +} + func GetBoolEnvironmentDefaultFalse(environmentName string) bool { switch os.Getenv(environmentName) { case "1", "true", "yes": diff --git a/pkg/util/linux_container.go b/pkg/util/linux_container.go index c77cf5966b..1e73b7fbe0 100644 --- a/pkg/util/linux_container.go +++ b/pkg/util/linux_container.go @@ -38,6 +38,11 @@ func ToLinuxContainerPath(path string) string { } func IsInContainer() bool { + werfContainerized := GetBoolEnvironment("WERF_CONTAINERIZED") + if werfContainerized != nil { + return *werfContainerized + } + // Docker-daemon if isInContainer, err := RegularFileExists("/.dockerenv"); err == nil && isInContainer { return true