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

feature: cli supports --env-file #2870

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

lang710
Copy link
Contributor

@lang710 lang710 commented May 27, 2019

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

@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #2870 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#criv1alpha2_test 38.36% <ø> (+0.02%) ⬆️
#integration_test_0 36.2% <ø> (+0.1%) ⬆️
#integration_test_1 35.69% <ø> (+0.02%) ⬆️
#integration_test_2 36.42% <ø> (+0.38%) ⬆️
#integration_test_3 35.51% <ø> (-0.15%) ⬇️
#node_e2e_test 34.16% <ø> (-0.05%) ⬇️
#unittest 28.03% <ø> (ø) ⬆️
Impacted Files Coverage Δ
apis/server/utils.go 71.15% <0%> (-3.85%) ⬇️
cri/ocicni/netns.go 58.1% <0%> (-2.71%) ⬇️
ctrd/supervisord/daemon.go 49.32% <0%> (-1.36%) ⬇️
ctrd/container.go 54.3% <0%> (ø) ⬆️
ctrd/watch.go 78.37% <0%> (+5.4%) ⬆️

@pouchrobot
Copy link
Collaborator

We found this is your first time to contribute to pouch, @lang710
👏 We really appreciate it.
Just remind that you have read the contribution guide: https://github.com/alibaba/pouch/blob/master/CONTRIBUTING.md
If you didn't, you should do that first. If done, welcome again and please enjoy hacking! 🍻

@CodeJuan
Copy link
Contributor

CodeJuan commented May 27, 2019

@lang710 Would you please squash the commits into a single one and set a readable commit message .

@CodeJuan
Copy link
Contributor

Test cases are high priority, would you please add unit test and integration test?

@lang710
Copy link
Contributor Author

lang710 commented May 27, 2019

@lang710 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 Show resolved Hide resolved
cli/envfile.go Outdated
return lines, scanner.Err()
}

var whiteSpaces = " \t"
Copy link
Contributor

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?

Copy link
Contributor Author

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!

@CodeJuan
Copy link
Contributor

@lang710 CI failed, please take a look at build log.

FAIL: cli_create_test.go:364: PouchCreateSuite.TestCreateWithEnvfile
cli_create_test.go:385:
    c.Fatalf("container env in inspect result should have %s in %s while no\n", env1, envs)
... Error: container env in inspect result should have TEST1=value1 in [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin TEST2=value2] while no

@lang710 lang710 force-pushed the fixenv branch 3 times, most recently from e6b4612 to 3d160f9 Compare May 28, 2019 12:47
@lang710 lang710 force-pushed the fixenv branch 3 times, most recently from 22e5ccb to a387cd1 Compare May 29, 2019 01:40
cli/envfile.go Outdated
}

if len(data) > 1 {

Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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?

c.Assert(strings.TrimSpace(ret.Stdout()), check.Equals, "value1-")

// Test three
validfile = "fixtures/valid.env"
Copy link
Contributor

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?

@lang710 lang710 force-pushed the fixenv branch 5 times, most recently from 0491081 to 764b8b6 Compare May 29, 2019 11:47
test/util/util.go Outdated Show resolved Hide resolved
with.dots=working
and_underscore=working too
地址=杭州
ADDRESS=杭州
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree!

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/docker/docker/pkg/stdcopy"
Copy link
Contributor

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

@lang710 lang710 force-pushed the fixenv branch 4 times, most recently from 7d98da9 to a825538 Compare June 4, 2019 08:07
Signed-off-by: Lang Chi <21860405@zju.edu.cn>
Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

pouch run support --env-file
5 participants