Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(agent/agentcontainers): add ContainerEnvInfoer#16623

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 9 commits intomainfromcj/agent-docker-envinfo
Feb 24, 2025

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedFeb 19, 2025
edited
Loading

This PR adds an alternative implementation of EnvInfo (#16603) that reads information from a running container.

NOTE: the new tests aren't run in CI by default; you'll have to just "trust" me that they work or run them yourself.

@johnstcnjohnstcn self-assigned thisFeb 19, 2025
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Only real issue I spotted is the env parsing. Both the premise (which I question) and also multiline handling. Otherwise looks solid.

}

// EnvInfo returns information about the environment of a container.
func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerUser string) (*ContainerEnvInfoer, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where will this be called? Right now it's only used in tests.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

See here:#16638


func (cei *ContainerEnvInfoer) CurrentUser() (*user.User, error) {
// Clone the user so that the caller can't modify it
u := *cei.user
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is technically just a shallow clone, but it's OK becauseuser.User does not have any reference type fields:https://pkg.go.dev/os/user#User

@@ -93,12 +105,93 @@ func TestDockerCLIContainerLister(t *testing.T) {
if assert.Len(t, foundContainer.Volumes, 1) {
assert.Equal(t, testTempDir, foundContainer.Volumes[testTempDir])
}
// Test that EnvInfo is able to correctly modify a command to be
Copy link
Contributor

Choose a reason for hiding this comment

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

Tasty 👍

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Noticed one potential issue? Otherwise LGTM once those are fixed 👍🏻

Comment on lines +131 to +142
func (*DockerEnvInfoer) Environ() []string {
// Return a clone of the environment so that the caller can't modify it
return os.Environ()
}

func (*DockerEnvInfoer) UserHomeDir() (string, error) {
// We default the working directory of the command to the user's home
// directory. Since this came from inside the container, we cannot guarantee
// that this exists on the host. Return the "real" home directory of the user
// instead.
return os.UserHomeDir()
}
Copy link
Member

Choose a reason for hiding this comment

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

Are we intentionally usingos here now? IIRC these were accessingdei.user before. I'm guessing the env and home dir may be different between host and container.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah I found that we still need to useos here otherwise you won't have e.g.$PATH set correctly, which will cause all kinds of issues. Given that both the implementations are doing the same thing now I could take it out of the equation, but it's also nice to have this abstraction in place IMO.

Copy link
Member

@mafredrimafredriFeb 24, 2025
edited
Loading

Choose a reason for hiding this comment

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

Hmm, if that's the case, I suppose I don't understand how this is supposed to be used.

Essentially setting cmd.Env is no-op fordocker exec commands. We need to serialize the container env asdocker exec -e ENV1=val1 ... where this is needed (or an env file or some such).

In general I like the abstraction, but as used it seems confusing to me?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I suppose a better implementation would be to haveDockerEnvInfoer embedsystemEnvInfoer and just override the required methods. That way you keep the abstraction but it's clear then that this implementation does nothing different.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is going to need a little refactoring so I'll merge as-is and address this in a follow-up.

@johnstcnjohnstcn merged commit304007b intomainFeb 24, 2025
30 checks passed
@johnstcnjohnstcn deleted the cj/agent-docker-envinfo branchFebruary 24, 2025 15:05
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 24, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

@dannykoppingdannykoppingdannykopping approved these changes

@SasSwartSasSwartAwaiting requested review from SasSwart

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@johnstcn@mafredri@dannykopping

[8]ページ先頭

©2009-2025 Movatter.jp