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

Add spec load pass to check for undefined build args #281

Merged

Conversation

adamperlin
Copy link
Contributor

What this PR does / why we need it:
Currently, if a build arg is not specified in the args section of a Dalec spec file, its value is set to "" when the spec is loaded. This is confusing behavior, as a user could easily forget to declare a build-arg or mistype a build-arg reference, leading to an empty string substitution which could be hard to track down.

This PR adds an additional pass upon loading the spec which tokenizes all the build args first, and checks to ensure that each referenced arg does appear in the args section of the spec, raising an error if not.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #274

Special notes for your reviewer:

@adamperlin adamperlin marked this pull request as ready for review June 5, 2024 17:42
@adamperlin adamperlin requested a review from a team as a code owner June 5, 2024 17:42
@adamperlin adamperlin requested a review from cpuguy83 June 10, 2024 16:18
@cpuguy83
Copy link
Member

Did you happen to look into using https://pkg.go.dev/github.com/moby/buildkit/frontend/dockerfile/shell?utm_source=godoc#Lex.ProcessWordWithMatches instead?
I believe that should give us the list of vars which weren't in our env list.

@adamperlin
Copy link
Contributor Author

Ah no, I was not aware that function existed. I will see if I can reimplement using that instead

@adamperlin
Copy link
Contributor Author

It looks like the version of this function you referenced exists in a newer version of buildkit (0.14.0) than the one we import in dalec (0.13.1). Are we ok to bump the buildkit dependency?

@cpuguy83
Copy link
Member

Oh nice, yes we can/should bump it.

@adamperlin adamperlin force-pushed the adamperlin/fix-undefined-build-arg-subst branch from 4ea9b75 to 6a320db Compare June 27, 2024 22:18
load_test.go Outdated Show resolved Hide resolved
load.go Outdated Show resolved Hide resolved
load.go Outdated Show resolved Hide resolved
Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

MInor readability nit, but otherwise LGTM

load.go Show resolved Hide resolved
@cpuguy83 cpuguy83 merged commit 37aa490 into Azure:main Aug 22, 2024
9 checks passed
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.

[BUG] Argument substitution should handle undefined args used for substitution
2 participants