Skip to content

Commit

Permalink
Set engine env from containers.conf
Browse files Browse the repository at this point in the history
Set engine env from containers.conf. Mirror podman PR containers/podman#6790.

Signed-off-by: Qi Wang <[email protected]>
  • Loading branch information
QiWang19 committed Jul 14, 2020
1 parent d2e0cd8 commit b507c62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions cmd/buildah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion docs/buildah.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 <[email protected]>

0 comments on commit b507c62

Please sign in to comment.