Skip to content

Commit

Permalink
Merge #2457
Browse files Browse the repository at this point in the history
2457: Set engine env from containers.conf r=rhatdan a=QiWang19

Set engine env from containrs.conf. Mirror podman PR containers/podman#6790.

Signed-off-by: Qi Wang <[email protected]>

<!--
Thanks for sending a pull request!

Please make sure you've read and understood our contributing guidelines
(https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring
that all your commits are signed with `git commit -s`.
-->

#### What type of PR is this?

<!--
Please label this pull request according to what type of issue you are
addressing, especially if this is a release targeted pull request.

Uncomment only one `/kind <>` line, hit enter to put that in a new line, and
remove leading whitespace from that line:
-->

> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test 
> /kind feature
> /kind flake
> /kind other

#### What this PR does / why we need it:

#### How to verify it

#### Which issue(s) this PR fixes:

<!--
Automatically closes linked issue when PR is merged.
Uncomment the following comment block and include the issue
number or None on one line.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`.
-->

<!--
Fixes #
or
None
-->

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write `None` in the release-note block below. If yes, a release note
is required: Enter your extended release note in the block below. If the PR
requires additional action from users switching to the new release, include the
string "action required".

For more information on release notes please follow the kubernetes model:
https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```



Co-authored-by: Qi Wang <[email protected]>
  • Loading branch information
bors[bot] and QiWang19 authored Jul 15, 2020
2 parents 5361d7a + b507c62 commit d4c696a
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 d4c696a

Please sign in to comment.