Set engine env from containers.conf

Set engine env from containers.conf. Mirror podman PR https://github.com/containers/podman/pull/6790.

Signed-off-by: Qi Wang <qiwan@redhat.com>
This commit is contained in:
Qi Wang 2020-07-10 14:46:43 -04:00
parent d2e0cd8988
commit b507c62769
2 changed files with 28 additions and 1 deletions

View File

@ -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
}

View File

@ -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 <tsweeney@redhat.com>