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

Support docker build --build-context parameter #3273

Merged

Conversation

jonnyry
Copy link
Contributor

@jonnyry jonnyry commented Dec 3, 2024

What does this change

Add new --build-context parameter to porter, and pass through the value to docker build.

https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#build-context

What issue does it fix

Closes #3271

Checklist

  • Did you write tests?
  • Did you write documentation?

Copy link
Member

@schristoff schristoff left a comment

Choose a reason for hiding this comment

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

Some small comment but otherwise great work, thank you

inputArgs []string
wantArgs map[string]buildx.NamedContext
}{
{name: "valid args", inputArgs: []string{"A=1", "B=2=2", "C="},
Copy link
Member

Choose a reason for hiding this comment

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

Just checking, are these all valid from Dockers side? I figure if you pass in "C=" and Docker tries to run it it's gonna error, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes good point, "C=" is not.

I've taken another look and found docker buildkit has its own ParseContextNames function with error handling (similar to the --ssh param parsing), so I've replaced my hand rolled parseBuildContexts with it, so we get dockers own error handling on the parameter.

This yields the following outputs from porter:

$ ./porter build --build-context
flag needs an argument: --build-context

$ ./porter build --build-context context1
Copying porter runtime ===> 
Copying mixins ===> 
Copying mixin exec ===> 
Copying mixin terraform ===> 
Copying mixin az ===> 
Building bundle image
error parsing the --build-context flags: invalid context value: context1, expected key=value
unable to build bundle image: error parsing the --build-context flags: invalid context value: context1, expected key=value
unable to build bundle image: error parsing the --build-context flags: invalid context value: context1, expected key=value


$ ./porter build --build-context context1=
Copying porter runtime ===> 
Copying mixins ===> 
Copying mixin exec ===> 
Copying mixin terraform ===> 
Copying mixin az ===> 
Building bundle image
[+] Building 0.0s (0/0)                                                                                                                                                                                                                     
error building docker image: failed to get build context context1: stat : no such file or directory
unable to build bundle image: error building docker image: failed to get build context context1: stat : no such file or directory
unable to build bundle image: error building docker image: failed to get build context context1: stat : no such file or directory


./porter build --build-context context1=..
(command successful)

@jonnyry jonnyry force-pushed the feature/support-docker-build-context-flag branch from 1d3f82d to 09c0c2e Compare December 6, 2024 16:19
…or handling (instead of own function) 2) Add toNamedContexts function and tests 3) Improve help output to make format clearer.

Signed-off-by: jonnyry <[email protected]>
@schristoff
Copy link
Member

Good catch, thanks for that update :)

@schristoff schristoff merged commit 38dcc21 into getporter:main Dec 9, 2024
40 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.

Allow the passing of --build-context args to docker build
2 participants