Skip to content

Conversation

@loispostula
Copy link
Contributor

@loispostula loispostula commented Oct 23, 2025

Fix #5954

Switch from HasPrefix to == for Dockerfile FROM matching

Test

To test this pull request, you can run the following commands:

cd pkg/plugins/resources/dockerfile
go test

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

Tradeoff

This is a behavioral breaking change

Potential improvement

@loispostula loispostula requested a review from dduportal October 23, 2025 16:09
@olblak
Copy link
Member

olblak commented Oct 24, 2025

If I understand correctly, this will be a breaking change with the declarative pipeline but a bug fix for the autodiscovery plugin.
I am not sure anymore, but I think we were using the hasPRefix because at that time, Updatecli couldn't handle stage information such as.

FROM golang as build

Which we do now.

TBH, I don't understand how this change would introduce a breaking change for the autodiscovery plugin, normally it should handle every image independently. In fact, using string comparison over checking prefix is even a bug fix for the autodiscovery because a multi-stage Dockerfile containing both python and python_runtime wouldn't be idempotent as Updatecli could use the python tag to update the python_runtime depending on the order of the generated manifests.

To play extra safe, we could use regex over string comparison, but then we would always need to specify $xxx^ which imho bring a bad UI

So my take on this would be to consider this as a bug and use string comparison

To me

@loispostula
Copy link
Contributor Author

Then we need to revisit the autodiscovery, at the moment to get all image in a dockerfile we check for all FROM instruction matching "" as the matching is with Prefix, it gives us all the docker images in the dockerfile.

The way I expect this to work is:

  • FROM matching should be exact match
  • autodiscovery should find all docker images in a dockerfile that are not a stage name:
FROM golang AS golang_builder
FROM scracth
FROM golang_builder
FROM python

Should find ["golang", "scratch", "python"] to update and only update thoses

@olblak
Copy link
Member

olblak commented Oct 24, 2025

Sorry for the stupid question, but why do you want to ignore stage images? I don't understand
Right now, we detect all of them. I just did a quick check and the pipelines are executed in the order of appearance which is a good think there is still the problem to update the wrong docker image tag

@loispostula
Copy link
Contributor Author

The behaviour I see is

FROM python:3.14 AS python-runtime

RUN apk add git

FROM python-runtime AS builder
...
FROM python-runtime AS dev
...

So we have base runtime, that we call python-runtime, it's reused multiple time.

When i run autodiscovery, I expect to only update the first one, the others are not docker images per se

@olblak
Copy link
Member

olblak commented Oct 24, 2025

Haaa good point thanks for the clarification

@olblak olblak added bug Something isn't working resource-dockerfile Resource of kind Dockerfile autodiscovery All things related to the autodiscovery feature labels Oct 28, 2025
olblak
olblak previously approved these changes Oct 28, 2025
Copy link
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

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

Thanks for the fix

@olblak
Copy link
Member

olblak commented Oct 28, 2025

Re-triggering the unit tests, for some reason it's failing, but I don't seem to be able to reproduce locally :/

@olblak
Copy link
Member

olblak commented Oct 28, 2025

I could reproduce executing multiple time go test -count=1

@olblak
Copy link
Member

olblak commented Oct 28, 2025

And the dockerfile e2e tests are not passing for the autodiscovery

@olblak olblak enabled auto-merge (squash) October 29, 2025 07:53
@olblak
Copy link
Member

olblak commented Oct 30, 2025

The e2e tests are not passing because they rely on docker images hosted on DockerHub, but pull request don't have access to DockerHub credentials for obvious security reason. I'll try to find some time to make the tests passing

@olblak
Copy link
Member

olblak commented Oct 30, 2025

So for some reason, the changes introduce in this pull request would detect this Dockerfile with an image not available on DockerHub 🤷🏾

@olblak olblak merged commit 88ded3c into main Oct 30, 2025
5 of 6 checks passed
@olblak olblak deleted the lp/5954 branch October 30, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autodiscovery All things related to the autodiscovery feature bug Something isn't working resource-dockerfile Resource of kind Dockerfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updatecli docker autodiscovery is updating hash of FROM referencing previous stage

2 participants