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

Docker: Ignore ARGs without default values #4723

Merged
merged 1 commit into from
Feb 9, 2022

Conversation

jurre
Copy link
Member

@jurre jurre commented Feb 9, 2022

In #4598 we added
support for ARG FROM. However, this assumed that a default value is
always specified, when it isn't the code would crash.

This is not that common, however:

Due to how we parse Dockerfiles, this actually also happened for regular
ARGs in a Dockerfile, even if it didn't belong to the FROM, meaning
that any ARG without a default would cause our update to fail.

In #4598 we added
support for ARG FROM. However, this assumed that a default value is
always specified, when it isn't the code would crash.

This is not that common, however:

Due to how we parse Dockerfiles, this actually also happened for regular
`ARG`s in a Dockerfile, even if it didn't belong to the `FROM`, meaning
that any ARG without a default would cause our update to fail.
@jurre jurre requested a review from a team as a code owner February 9, 2022 16:16
Comment on lines -138 to +141
end

context "arg from" do
let(:dockerfile_fixture_name) { "arg_from_curls" }

describe "with curls" do
let(:dockerfile_fixture_name) { "arg_from_curls" }

Copy link
Member

Choose a reason for hiding this comment

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

nice fix

Comment on lines 45 to +47
key_value = line.delete_prefix("ARG ").split("=")
next if key_value.count != 2 # The ARG has no default value that we can set

Copy link
Member

@Nishnha Nishnha Feb 9, 2022

Choose a reason for hiding this comment

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

I'm not sure I fully understand how this piece works. Here we split on =, but the example in the fixture file doesn't have an = so HUB in ARG HUB does not qualify as a default argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

You would need to pass it in from the commandline:

docker build --build-arg=HUB=docker.io .

But since Dependabot can't know the value in this case, we don't perform an update

Copy link
Member

Choose a reason for hiding this comment

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

That makes a lot more sense in context 👍🏾

@jurre jurre merged commit bc66c81 into main Feb 9, 2022
@jurre jurre deleted the jurre/handle-docker-args-without-default-values branch February 9, 2022 17:26
@jurre jurre mentioned this pull request Feb 9, 2022
@hfhbd
Copy link
Contributor

hfhbd commented Feb 9, 2022

Sorry, this still fails, because I forgot to update the file-updater...
The outdated docker version is parsed correctly, and the new version is found, but the file_updater is not able to update the new format: eg FROM $HUB/docker:20.10.7-dind to FROM $HUB/docker:20.10.12-dind

https://github.com/dependabot/dependabot-core/blob/main/docker/lib/dependabot/docker/file_updater.rb

@jeffwidman
Copy link
Member

For anyone who stumbles across this later, ☝️ is tracked in #4725.

@mctofu mctofu mentioned this pull request Mar 12, 2022
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.

4 participants