Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start_container: support setting environment variables #15

Merged
merged 7 commits into from
Mar 25, 2024

Conversation

vobst
Copy link

@vobst vobst commented Jan 26, 2024

Change the parsing of optional flag parameters after the three mandatory positional arguments to use a while loop. Makes it easier to add more arguments in the future.

Everything after -- will be passed to the docker command. Note: This change will break existing scripts that execute commands in the container.

As a first use-case: Add support for specifying environment variables for the container on the command line in a space-separated list. Note: It is not possible to set environment variables that contain spaces.

Why: I like to customize builds through environment variables and doing sh -c "FOO=BAR make" is ugly. :)

Examples:

$ export VAR=something
$ ./start_container.sh gcc-7 $(pwd) /tmp -e "FOO=BAR FOOBAR= VAR=$VAR" -- /usr/bin/env
Hey, we gonna use sudo for running docker
Starting "kernel-build-container:gcc-7"
Source code directory "/mnt/example/kernel-build-containers" is mounted at "~/src"
Build output directory "/tmp" is mounted at "~/out"
Container environment:  -e FOO=BAR -e FOOBAR= -e VAR=something
Run docker in interactive mode
Gonna run "/usr/bin/env"

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=e769fbdf9d72
FOO=BAR
FOOBAR=
VAR=something

Note: ./start_container.sh gcc-7 $(pwd) /tmp -e "FOO=BAR" -e "FOOBAR=" -e "VAR=$VAR" -- /usr/bin/env also works...

As further use case for the while-loop parsing: Add --help and --verbose flags.

@a13xp0p0v
Copy link
Owner

Hello @vobst,

Nice idea, thanks for the pull request!

I've found an infinite loop bug, I'll push the fix to the add-env-support branch on vobst/kernel-build-containers.

@a13xp0p0v
Copy link
Owner

a13xp0p0v commented Mar 25, 2024

I also:

  • forced using the -e argument of start_container.sh for each env variable, similar to -e in grep
  • fixed the start_container.sh calling in make_linux.py
  • improved the output of start_container.sh

@a13xp0p0v a13xp0p0v merged commit 28475b6 into a13xp0p0v:master Mar 25, 2024
@vobst
Copy link
Author

vobst commented Mar 25, 2024

Hi, thanks for picking this up and fixing those issues! Much appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants