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

Allow build args in target image config #491

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pmengelbert
Copy link
Contributor

@pmengelbert pmengelbert commented Jan 6, 2025

What this PR does / why we need it:

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 #490
Fixes #487

Special notes for your reviewer:

@pmengelbert pmengelbert requested a review from a team as a code owner January 6, 2025 17:45
load.go Outdated
img.Labels[k] = updated
}

if img.Post != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see why this would be necessary and would prefer to not support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understandable. Not strictly necessary, just a little more convenient for certain things. If you don't agree with the rationale feel free to close

load.go Outdated
*p = updated
}

for i, s := range img.Env {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little hesitant support this here but not against it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

load.go Outdated

func (img *ImageConfig) processBuildArgs(lex *shell.Lex, args map[string]string, allowArg func(string) bool) error {
var errs error
for _, p := range []*string{&img.Base, &img.Cmd, &img.User, &img.Entrypoint, &img.StopSignal, &img.WorkingDir} {
Copy link
Member

Choose a reason for hiding this comment

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

Likewise, I don't see why image base would need build args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the very least I think it would be useful for the tag. Some repos do not have a latest tag, and not allowing a build arg here forces a hard-coded tag. I'm not married to the idea of introducing this, but it does seem useful.

Other uses could be not hard-coding a registry.

Copy link
Member

Choose a reason for hiding this comment

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

Not hard-coding a registry could be taken care of by source policies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about tags?

Copy link
Member

Choose a reason for hiding this comment

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

I think I'd opt for explicitness in the spec in this case until someone actually asks for this.

Copy link
Member

Choose a reason for hiding this comment

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

Also base image is now deprecated in favor of the new bases.

@cpuguy83 cpuguy83 requested a review from MorrisLaw January 6, 2025 19:02
@@ -447,3 +453,57 @@ func (b *ArtifactBuild) processBuildArgs(lex *shell.Lex, args map[string]string,

return goerrors.Join(errs...)
}

func (img *ImageConfig) processBuildArgs(lex *shell.Lex, args map[string]string, allowArg func(string) bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Labels seems like a good candidate for build args. But why the other fields? Why not just limit support to Labels for now until there's a compelling use case/need for additional build arg support?

Note: I could be missing context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above, I think it could be useful for setting base image tags or registry host, particularly when the base image provider doesn't have a latest tag.

@cpuguy83
Copy link
Member

@pmengelbert any update here?

@pmengelbert
Copy link
Contributor Author

pmengelbert commented Jan 29, 2025

@pmengelbert any update here?

I'm going to update the PR to just allow the args in the labels.

@cpuguy83 cpuguy83 added this to the v0.12.0 milestone Jan 29, 2025
Also fix implementation

Signed-off-by: Peter Engelbert <[email protected]>
Earlier commits allowed substitution in various places in the Image
Config. This commit reverts most of those changes and allows arg
substitution only in the `Labels` field of the image config.

Signed-off-by: Peter Engelbert <[email protected]>
@pmengelbert pmengelbert force-pushed the pmengelbert/args_in_image_config/2 branch from 676cf38 to b0ade70 Compare February 5, 2025 15:43
@pmengelbert
Copy link
Contributor Author

@cpuguy83 @MorrisLaw Now the args are only substituted in the Labels field of the image config. Should be ready to go

@pmengelbert
Copy link
Contributor Author

I still need to update the tests

@cpuguy83
Copy link
Member

cpuguy83 commented Feb 6, 2025

Unit test is failing.

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] Build args are not substituted into image.base [REQ] image.labels should support arg substitution
3 participants