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

Copy host env to container for env/envfile option #1524

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

liubin
Copy link
Contributor

@liubin liubin commented Nov 19, 2022

Add a function to process env/envfile specified by users and set value for env with no value has been set.

Fixes: #1487

Signed-off-by: bin liu liubin0329@gmail.com

New behaiver with this patch:

For host envs:

root@master:~# export X=abc
root@master:~# docker run --rm --env X alpine printenv X
abc
root@master:~# docker run --rm --env X=23 alpine printenv X
23
root@master:~# docker run --rm --env X= alpine printenv X

root@master:~# nerdctl run --rm --net=none --env X alpine printenv X
abc
root@master:~# nerdctl run --rm --net=none --env X=23 alpine printenv X
23
root@master:~# nerdctl run --rm --net=none --env X= alpine printenv X

For envs not in host:

root@master:~# unset X
root@master:~# docker run --rm --env X alpine printenv X
root@master:~# docker run --rm --env X=23 alpine printenv X
23
root@master:~# docker run --rm --env X= alpine printenv X

root@master:~# nerdctl run --rm --net=none --env X alpine printenv X
root@master:~# nerdctl run --rm --net=none --env X=23 alpine printenv X
23
root@master:~# nerdctl run --rm --net=none --env X= alpine printenv X

@liubin liubin force-pushed the copy-env-from-host-to-container branch from 8a80118 to 1a61ccf Compare November 19, 2022 06:09
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda
Copy link
Member

CI failing

=== CONT  TestRunEnv
    run_test.go:193: assertion failed: error is not nil: got bad GARPLY: ALLUSERSPROFILE=C:\ProgramData
        APPDATA=C:\Users\ContainerAdministrator\AppData\Roaming
        BAR=bar1 bar2
        CommonProgramFiles=C:\Program Files\Common Files
        CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
        CommonProgramW6432=C:\Program Files\Common Files
        COMPUTERNAME=FC1E0F5CF954
        ComSpec=C:\Windows\system32\cmd.exe
        CORGE=corge-value-in-host
        DriverData=C:\Windows\System32\Drivers\DriverData
        FOO=foo1,foo2
        GRAULT=grault_key=grault_value
        LOCALAPPDATA=C:\Users\ContainerAdministrator\AppData\Local
        NUMBER_OF_PROCESSORS=2
        OS=Windows_NT
        Path=C:\dig\;C:\bin;C:\curl;C:\Windows\System32;C:\Windows;C:\Program Files\PowerShell;
        PATHEXT=.COM;.EXE;.BAT;.CMD
        PROCESSOR_ARCHITECTURE=AMD64
        PROCESSOR_IDENTIFIER=AMD64 Family 25 Model 1 Stepping 0, AuthenticAMD
        PROCESSOR_LEVEL=25
        PROCESSOR_REVISION=0100
        ProgramData=C:\ProgramData
        ProgramFiles=C:\Program Files
        ProgramFiles(x86)=C:\Program Files (x86)
        ProgramW6432=C:\Program Files
        PROMPT=$P$G
        PSCORE=C:\Program Files\PowerShell\pwsh.exe
        PSModuleAnalysisCachePath=C:\Users\ContainerAdministrator\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache
        PUBLIC=C:\Users\Public
        QUUX=quux2
        SystemDrive=C:
        SystemRoot=C:\Windows
        TEMP=C:\Windows\TEMP
        TMP=C:\Windows\TEMP
        USERDOMAIN=User Manager
        USERNAME=ContainerAdministrator
        USERPROFILE=C:\Users\ContainerAdministrator
        windir=C:\Windows
--- FAIL: TestRunEnv (1.03s)

https://cirrus-ci.com/task/6507949194477568

@liubin liubin force-pushed the copy-env-from-host-to-container branch from 1a61ccf to 0a5510e Compare November 21, 2022 03:18
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
@liubin liubin force-pushed the copy-env-from-host-to-container branch from 0a5510e to 38f4bcb Compare November 21, 2022 05:26
@liubin
Copy link
Contributor Author

liubin commented Nov 21, 2022

@AkihiroSuda I think I have fixed the issue in Windows.

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.

environment variables of current shell can't be passed to container via nerdctl run '-e' option
2 participants