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: FileParser consider image prefix/suffixes as unique #3627

Merged
merged 3 commits into from
May 5, 2021

Conversation

thepwagner
Copy link
Contributor

@thepwagner thepwagner commented May 3, 2021

This modifies the Dependabot::Docker::FileParser to treat image variants like image:1.0.0 and image:1.0.0-alpine as unique dependencies, even within a single multistage Dockerfile.

Consider a multistage Dockerfile like:

FROM nginx:1.19.9 AS debian
FROM nginx:1.19.9-alpine AS alpine

Previously, Dependabot would parse this as multiple requirements for an image called nginx, and update all FROM statements to a single image if available.

#<Dependabot::Dependency:0x000055591e6cac10 @name="nginx", @version="1.19.9", @requirements=[{:requirement=>nil, :groups=>[], :file=>"Dockerfile", :source=>{:tag=>"1.19.9"}}, {:requirement=>nil, :groups=>[], :file=>"Dockerfile", :source=>{:tag=>"1.19.9-alpine"}}], @previous_version=nil, @previous_requirements=nil, @package_manager="docker">

By switching the parsing to allow multiple versions, the existing suffix handling code "just works" 🎉 .

Pre

[dependabot-core-dev] ~/dependabot-core $ bin/dry-run.rb docker nginxinc/kubernetes-ingress --commit=54e0b07503414ab0c28472646a681b0674d1f3b9 --dir="/build" --dep="nginx"
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.7-compliant syntax, but you are running 2.6.6.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
=&gt; fetching dependency files
=&gt; dumping fetched dependency files: ./dry-run/nginxinc/kubernetes-ingress/build
=&gt; parsing dependency files
=&gt; updating 1 dependencies: nginx

=== nginx (1.19.9)
 =&gt; checking for updates 1/1
 =&gt; latest available version is 1.19.10
 =&gt; latest allowed version is 1.19.10
 =&gt; requirements to unlock: own
 =&gt; requirements update strategy:
 =&gt; updating nginx from 1.19.9 to 1.19.10

    ± Dockerfile
    ~~~
    5c5
    &lt; FROM nginx:1.19.9 AS debian
    ---
    &gt; FROM nginx:1.19.10 AS debian
    17c17
    &lt; FROM nginx:1.19.9-alpine AS alpine
    ---
    &gt; FROM nginx:1.19.10 AS alpine
    ~~~

Post

[dependabot-core-dev] ~/dependabot-core $ bin/dry-run.rb docker nginxinc/kubernetes-ingress --commit=54e0b07503414ab0c28472646a681b0674d1f3b9 --dir="/build" --dep="nginx"
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.7-compliant syntax, but you are running 2.6.6.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
=&gt; fetching dependency files
=&gt; dumping fetched dependency files: ./dry-run/nginxinc/kubernetes-ingress/build
=&gt; parsing dependency files
=&gt; updating 2 dependencies: nginx, nginx

=== nginx (1.19.9)
 =&gt; checking for updates 1/2
 =&gt; latest available version is 1.19.10
 =&gt; latest allowed version is 1.19.10
 =&gt; requirements to unlock: own
 =&gt; requirements update strategy:
 =&gt; updating nginx from 1.19.9 to 1.19.10

    ± Dockerfile
    ~~~
    5c5
    &lt; FROM nginx:1.19.9 AS debian
    ---
    &gt; FROM nginx:1.19.10 AS debian
    ~~~

=== nginx (1.19.9-alpine)
 =&gt; checking for updates 2/2
 =&gt; latest available version is 1.19.10-alpine
 =&gt; latest allowed version is 1.19.10-alpine
 =&gt; requirements to unlock: own
 =&gt; requirements update strategy:
 =&gt; updating nginx from 1.19.9-alpine to 1.19.10-alpine

    ± Dockerfile
    ~~~
    17c17
    &lt; FROM nginx:1.19.9-alpine AS alpine
    ---
    &gt; FROM nginx:1.19.10-alpine AS alpine
    ~~~

Related

@thepwagner thepwagner self-assigned this May 3, 2021
@thepwagner
Copy link
Contributor Author

@dependabot/reviewers I'd dig an early peek at this thinking: it seems promising (e.g. dry-runs in the OP) but I may be missing something.

I intend to follow up with tests before RFR.

@mctofu
Copy link
Contributor

mctofu commented May 4, 2021

I had a prior look at this as a day of learning exercise when looking into #3173.

I started with a similar approach and there were some concerns about increasing the # of PRs we'd open: #3251

That led to #3277 which was able to make all the changes in the same PR but didn't yet support this multi stage docker case.

That said, I think it's worth revisiting if this is the better change. It's simpler and avoids some awkwardness when the PR says it's updating php 8.0.1-apache but is also updating php 8.0.1-cli. I could also see the multiple PR concern being more of an issue when they both target the same file though.

@thepwagner
Copy link
Contributor Author

thepwagner commented May 4, 2021

@mctofu noice, that's exactly the context I was looking for! I pinged the reporters in #3261 for their expectations about single/multiple PRs.

I'm pondering a middle ground where instead of using (name, version) as the key for unique dependences in the FileParser (which is where we both started, neato!), we use (name, prefix, suffix, format) - like you were in comparable_tags?.
The goal would be to keep php:8.0.1 and php:8.0.3 as grouped dependencies, but treat php:8.0.1 as a distinct from php:8.0.1-apache and php:8.0.1-cli.

@thepwagner thepwagner changed the title multistage docker: FileParser unique versions docker: FileParser consider image prefix/suffixes as unique May 5, 2021
@thepwagner thepwagner marked this pull request as ready for review May 5, 2021 16:35
@thepwagner thepwagner requested a review from a team as a code owner May 5, 2021 16:35
Copy link
Contributor

@feelepxyz feelepxyz left a comment

Choose a reason for hiding this comment

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

The goal would be to keep php:8.0.1 and php:8.0.3 as grouped dependencies, but treat php:8.0.1 as a distinct from php:8.0.1-apache and php:8.0.1-cli.

This sounds like a good approach and I like that the change is pretty minimal 👍

Thinking about it, there's probably not a huge number of projects with the same image with different prefixes/suffixes (assuming we'd hear a lot more noise if it was the case?) so probably won't start creating a lot more PRs and fixes currently broken PRs which is a big plus 💯

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.

Docker image tag suffix changes with multi stage Dockerfile
3 participants