diff --git a/cmd/buildah/main.go b/cmd/buildah/main.go index df93829b663..2124a4804f4 100644 --- a/cmd/buildah/main.go +++ b/cmd/buildah/main.go @@ -6,11 +6,13 @@ import ( "os/exec" "runtime" "runtime/pprof" + "strings" "syscall" "github.com/containers/buildah" "github.com/containers/buildah/pkg/cli" "github.com/containers/buildah/pkg/parse" + "github.com/containers/common/pkg/config" "github.com/containers/storage" "github.com/containers/storage/pkg/unshare" ispecs "github.com/opencontainers/image-spec/specs-go" @@ -142,6 +144,27 @@ func before(cmd *cobra.Command) error { logrus.Fatalf("error starting CPU profiling: %v", err) } } + + defaultContainerConfig, err := config.Default() + if err != nil { + return err + } + + for _, env := range defaultContainerConfig.Engine.Env { + splitEnv := strings.SplitN(env, "=", 2) + if len(splitEnv) != 2 { + return fmt.Errorf("invalid environment variable %q from containers.conf, valid configuration is KEY=value pair", env) + } + // skip if the env is already defined + if _, ok := os.LookupEnv(splitEnv[0]); ok { + logrus.Debugf("environment variable %q is already defined, skip the settings from containers.conf", splitEnv[0]) + continue + } + if err := os.Setenv(splitEnv[0], splitEnv[1]); err != nil { + return err + } + } + return nil } diff --git a/docs/buildah.md b/docs/buildah.md index b119847d172..cef4173de4c 100644 --- a/docs/buildah.md +++ b/docs/buildah.md @@ -91,6 +91,10 @@ This option overrides the *remap-gids* setting in the *options* section of Print the version +## Environment Variables + +Buildah can set up environment variables from the env entry in the [engine] table in the containers.conf(5). These variables can be overridden by passing environment variables before the `buildah` commands. + ## COMMANDS | Command | Description | @@ -147,7 +151,7 @@ registries.conf is the configuration file which specifies which container regist Directory which contains configuration snippets which specify registries which should be consulted when completing image names which do not include a registry or domain portion. ## SEE ALSO -podman(1), containers-mounts.conf(5), newuidmap(1), newgidmap(1), containers-registries.conf(5), containers-storage.conf(5) +podman(1), containers.conf(5), containers-mounts.conf(5), newuidmap(1), newgidmap(1), containers-registries.conf(5), containers-storage.conf(5) ## HISTORY December 2017, Originally compiled by Tom Sweeney