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

Dockerfile detector will only check files containing "Dockerfile" in the name #3499

Merged
merged 2 commits into from
Jan 15, 2020

Conversation

spectrox
Copy link
Contributor

@spectrox spectrox commented Jan 10, 2020

Fixes #3484.

Description

Initializer tries to find all available builders by checking each file in the tree for compatible with Dockerfile syntax.
This syntax is not unique and python file can be taken for Dockerfile:

from django.test import TestCase

This fix adds additional check to the file name which should contain "Dockerfile".

I am not sure if that is appropriate solution, because it can affect existing users.
But as far as I know, developers tend to keep Dockerfile in the name even when using multiple files in the same folder.

User facing changes

Before

When running skaffold init with python files like the one mentioned above you can see them in the list of available builders.

After

No python files should be listed in the survey.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Mentions any output changes.
  • Adds documentation as needed: user docs, YAML reference, CLI reference.
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit test added.
  • User facing changes look good.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@spectrox
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@codecov
Copy link

codecov bot commented Jan 10, 2020

Codecov Report

Merging #3499 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted Files Coverage Δ
pkg/skaffold/initializer/init.go 63.63% <100%> (+0.22%) ⬆️
pkg/skaffold/util/tar.go 52.87% <0%> (-4.6%) ⬇️
...affold/kubernetes/portforward/kubectl_forwarder.go 68.29% <0%> (+2.43%) ⬆️

results := []InitBuilder{docker.ArtifactConfig{File: path}}
return results, true
base := filepath.Base(path)
if strings.Contains(base, "Dockerfile") {
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I've also seen a lot of *.dockerfile out there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, it would be better to make it case insensitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it case insensitive and updated test to cover this case.

return results, true
base := filepath.Base(path)
if strings.Contains(base, "Dockerfile") {
if docker.Validate(path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also check in docker.Validate(path) if there is some python-ish code after from ... (like import <name>).

WDYT @dgageot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that Dockerfile validator should be aware of python-ish code constructs.
It's responsibility to validate Dockerfile and it does that by validating commands. Validating arguments would be too much overhead IMO.

@spectrox spectrox requested a review from dgageot January 13, 2020 18:23
@dgageot dgageot self-assigned this Jan 15, 2020
@dgageot dgageot added the kokoro:run runs the kokoro jobs on a PR label Jan 15, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jan 15, 2020
@dgageot dgageot merged commit 1ac3b2a into GoogleContainerTools:master Jan 15, 2020
@spectrox spectrox deleted the fix-3484 branch January 15, 2020 09:17
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.

skaffold init thinks some python files are Dockerfiles
5 participants