-
Notifications
You must be signed in to change notification settings - Fork 949
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
feature: cli supports --env-file #2870
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2870 +/- ##
==========================================
- Coverage 68.87% 68.85% -0.02%
==========================================
Files 291 291
Lines 18249 18249
==========================================
- Hits 12569 12566 -3
- Misses 4223 4227 +4
+ Partials 1457 1456 -1
|
We found this is your first time to contribute to pouch, @lang710 |
@lang710 Would you please squash the commits into a single one and set a readable commit message . |
Test cases are high priority, would you please add unit test and integration test? |
I have written the test, but not sure if it's right. |
cli/envfile.go
Outdated
return lines, scanner.Err() | ||
} | ||
|
||
var whiteSpaces = " \t" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to make this variable a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so and thank you for you advise!
7644b4c
to
dabfce5
Compare
@lang710 CI failed, please take a look at build log.
|
e6b4612
to
3d160f9
Compare
22e5ccb
to
a387cd1
Compare
cli/envfile.go
Outdated
} | ||
|
||
if len(data) > 1 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate empty line
cli/envfile.go
Outdated
data := strings.SplitN(line, "=", 2) | ||
|
||
// trim the front of a variable, but nothing else | ||
variable := strings.TrimLeft(data[0], whiteSpaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we actually need this line? I think the strings.TrimLeft(scanner.Text(), whiteSpaces)
is good enough.
cli/envfile.go
Outdated
scanner := bufio.NewScanner(fh) | ||
for scanner.Scan() { | ||
// trim the line from all leading whitespace first | ||
line := strings.TrimLeft(scanner.Text(), whiteSpaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about unicode.IsSpace
?
|
||
// Test ParseEnvFile for a file with a few well formatted lines | ||
func TestParseEnvFileGoodFile(t *testing.T) { | ||
content := `foo=bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that the behaviour in Chinese 😂
could you please add some test for this?
test/cli_run_test.go
Outdated
c.Assert(strings.TrimSpace(ret.Stdout()), check.Equals, "value1-") | ||
|
||
// Test three | ||
validfile = "fixtures/valid.env" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use tmp file to contain the content. How do you think?
0491081
to
764b8b6
Compare
66f0861
to
8b3d26b
Compare
with.dots=working | ||
and_underscore=working too | ||
地址=杭州 | ||
ADDRESS=杭州 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ADDRESS=杭州
is valid env.
root@ubuntu-xenial /h/vagrant# cat /tmp/1 1
地址=杭州
ADDRESS=杭州
root@ubuntu-xenial /h/vagrant# docker run -d --env-file /tmp/1 busybox:1.25 top
edd1c870b3be3727d87ffe320c1af218f67a2f148f4989a4039f81ea397fc3d8
root@ubuntu-xenial /h/vagrant# docker exec edd1c870b3be3727d87ffe320c1af218f67a2f148f4989a4039f81ea397fc3d8 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=edd1c870b3be
地址=杭州
ADDRESS=杭州
HOME=/root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is no problem with testing Chinese characters.
res = command.PouchRun("start", name) | ||
res.Assert(c, icmd.Success) | ||
|
||
ret := command.PouchRun("exec", name, "env") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing ret.Assert(c, icmd.Success)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's no need to add this instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. But it can help us to know the command status. If there is output wrong, we need to know the command is correct or not. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree!
apis/server/container_bridge.go
Outdated
@@ -4,6 +4,7 @@ import ( | |||
"context" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/docker/docker/pkg/stdcopy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put this package into next third group
7d98da9
to
a825538
Compare
Signed-off-by: Lang Chi <21860405@zju.edu.cn>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Lang Chi 21860405@zju.edu.cn
Ⅰ. Describe what this PR did
pouch command supports --env-file
Ⅱ. Does this pull request fix one issue?
fixes #2857
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
added
Ⅳ. Describe how to verify it
cat /home/abc
env_var_name=another_value
pouch run --env-file=/home/abc -d busybox top
b2f0df7176e9459441276c7470ad95ae701329b49ff2709344706316597ce639
pouch exec b2f0df7176e9459441276c7470ad95ae701329b49ff2709344706316597ce639 env | grep env_var_name
env_var_name=another_value
Ⅴ. Special notes for reviews