Skip to content

Fix entrypoint parsing logic#5830

Merged
thaJeztah merged 1 commit intodocker:masterfrom
lalyos:fix-entrypoint-option-test
Feb 17, 2025
Merged

Fix entrypoint parsing logic#5830
thaJeztah merged 1 commit intodocker:masterfrom
lalyos:fix-entrypoint-option-test

Conversation

@lalyos
Copy link
Copy Markdown
Contributor

@lalyos lalyos commented Feb 17, 2025

Right now the test passes even if you change the expected value. It passes if the array has 1 element.

- What I did

I was trying to understand the docker run --entrypoint parsing process, and run the test:
go test -v ./cli/command/container -run Entry and even when I changed the expected value, it still passed?!

- How to verify it

change the expected value to foo and run: go test -v ./cli/command/container -run Entry

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Nice catch! These tests were added really long ago, and could use some cleaning up in general. I suspect the != 1 was added with the intent to prevent an out of bound if the slice was empty, but indeed flipped the boolean condition; had a quick peek and it looks like this was added when this code still lived in the moby/moby repository, and was part of a bigger refactor (moby/moby#14134) so definitely overlooked in review; moby/moby@d4aec5f#diff-b669db027d2079a55de7d0b67c632c4dc70ab0e577c4de03e8557dfd9f4898d5

Comment thread cli/command/container/opts_test.go Outdated
Comment on lines 1019 to 1024
if err != nil {
t.Fatal(err)
}
if len(config.Entrypoint) != 1 && config.Entrypoint[0] != "anything" {
if len(config.Entrypoint) != 1 || config.Entrypoint[0] != "anything" {
t.Fatalf("Expected entrypoint 'anything', got %v", config.Entrypoint)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that we already have the gotest.tools assert imported in this package (and use it for other tests in this file), we could use that for this test;

func TestParseEntryPoint(t *testing.T) {
	config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"})
	assert.NilError(t, err)
	assert.Check(t, is.DeepEqual(config.Entrypoint, []string{"anything"}))
}

@thaJeztah
Copy link
Copy Markdown
Member

Thank you for contributing! It appears your commit message is missing a DCO sign-off,
causing the DCO check to fail.

We require all commit messages to have a Signed-off-by line with your name
and e-mail (see "Sign your work"
in the CONTRIBUTING.md in this repository), which looks something like:

Signed-off-by: YourFirsName YourLastName <yourname@example.org>

There is no need to open a new pull request, but to fix this (and make CI pass),
you need to amend the commit(s) in this pull request, and "force push" the amended
commit.

Unfortunately, it's not possible to do so through GitHub's web UI, so this needs
to be done through the git commandline.

You can find some instructions in the output of the DCO check (which can be found
in the "checks" tab on this pull request), as well as in the Moby contributing guide.

Steps to do so "roughly" come down to:

  1. Set your name and e-mail in git's configuration:

    git config --global user.name "YourFirstName YourLastName"
    git config --global user.email "yourname@example.org"

    (Make sure to use your real name (not your GitHub username/handle) and e-mail)

  2. Clone your fork locally

  3. Check out the branch associated with this pull request

  4. Sign-off and amend the existing commit(s)

    git commit --amend --no-edit --signoff

    If your pull request contains multiple commits, either squash the commits (if
    needed) or sign-off each individual commit.

  5. Force push your branch to GitHub (using the --force or --force-with-lease flags) to update the pull request.

Sorry for the hassle (I wish GitHub would make this a bit easier to do), and let me know if you need help or more detailed instructions!

@thaJeztah
Copy link
Copy Markdown
Member

Ah, sorry for the canned reply; I see there's a sign-off, but DCO-check saw the spelling of your name was different than the information in the git "author" field (Lajos vs Lalyos); it can be rather picky on that, so you may have to either change your "author" config in git, or amend the sign-off line;

Commit sha: 10a91f1, Author: Lajos Papp, Committer: Lajos Papp; Expected "Lajos Papp lalyos@yahoo.com", but got "Lalyos Papp lalyos@yahoo.com".

@lalyos lalyos force-pushed the fix-entrypoint-option-test branch 2 times, most recently from 8fde770 to efa2043 Compare February 17, 2025 10:52
@lalyos
Copy link
Copy Markdown
Contributor Author

lalyos commented Feb 17, 2025

DCO is fixed
I used your version with gotest.tools but had to change the asserted type from []string to []strslice.StrSlice

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.18%. Comparing base (f488a75) to head (e868f0f).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5830      +/-   ##
==========================================
+ Coverage   58.79%   59.18%   +0.38%     
==========================================
  Files         349      352       +3     
  Lines       29536    29547      +11     
==========================================
+ Hits        17367    17486     +119     
+ Misses      11186    11080     -106     
+ Partials      983      981       -2     

@thaJeztah
Copy link
Copy Markdown
Member

Ah! Good one; forgot it was defined using that type; yeah either way (casting to []string or vice-versa should be fine in this case; I recall I recently changed some tests elsewhere because the []strslice.StrSlice was only to help with JSON marshalling.

Comment thread cli/command/container/opts_test.go Outdated
Comment thread cli/command/container/opts_test.go Outdated
@thaJeztah thaJeztah removed the dco/no label Feb 17, 2025
Right now the test passes even if you change the expected value.
It passes if the array has 1 element.

Signed-off-by: Lajos Papp <lalyos@yahoo.com>
@lalyos lalyos force-pushed the fix-entrypoint-option-test branch from efa2043 to e868f0f Compare February 17, 2025 11:13
@thaJeztah thaJeztah added this to the 28.0.0 milestone Feb 17, 2025
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for contributing!

@thaJeztah thaJeztah merged commit c542ad7 into docker:master Feb 17, 2025
@lalyos
Copy link
Copy Markdown
Contributor Author

lalyos commented Feb 17, 2025

Btw as it turned out that entrypoint is an strslice, I got the the crazy itch to check if I could give an actual array to --entrypoint using the same syntax as in Dockerfile's ENTRYPOINT

It just took 3 lines: 284534f and then you could do:

$ docker run --entrypoint '["sh","-c","echo look ma entrypoint as an array"]' alpine

look ma entrypoint as an array

I myself question if its practical at all, but I saw a couple of issues mentioning this feature.
What's your opinion, should I open a PR (with a couple of new tests: de56693)?

@lalyos lalyos deleted the fix-entrypoint-option-test branch February 17, 2025 12:41
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.

3 participants