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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

command(bake): Specify local and remote bake files #1838

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

c-ameron
Copy link
Contributor

@c-ameron c-ameron commented May 24, 2023

As I mentioned on Slack. This adds the ability to source additional local build definition files when sourcing Bake files via a remote url.
Prefixing a file with cwd:// will source the bake file from the local machine, instead of the remote location.
Local files will be read/have precedence before remote files.

Usage:

docker buildx bake https://github.com/example/upstream.git --file cwd://docker-bake.override.hcl --print

This will source a default file from the example/upstream repository, and also source a build definition from the local machine.

I'm a Go novice so any suggestions are welcome 馃槃

Thanks!

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

The "local://" prefix is not ideal but don't have better ideas either.

Ideally, this could have an integration test under tests but let us know if you need help with that.

commands/bake.go Outdated Show resolved Hide resolved
commands/bake.go Outdated Show resolved Hide resolved
@jedevc
Copy link
Collaborator

jedevc commented May 25, 2023

Fun tangent: was looking into this PR, only to discover that BAKE_CMD_CONTEXT doesn't work correctly anymore: #1840.

The "local://" prefix is not ideal but don't have better ideas either.

This seems kinda similar to the BAKE_CMD_CONTEXT var actually. Internally, we have this work by doing cwd:// - we could re-use this instead of local:// which should also let us share some code?

Ideally, this could have an integration test under tests but let us know if you need help with that.

馃憤 yup! Our integration tests are quite new here, so any help you can give to help us build those out is very appreciated 鉂わ笍

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

^ PTAL comment from @jedevc

@c-ameron
Copy link
Contributor Author

Apologies for the late reply, I was away on holiday so will get back to this PR at the end of the week.

Our integration tests are quite new here, so any help you can give to help us build those out is very appreciated

Could you please point me in the right direction where to do this? I should do it like the TestReadLocalFilesDefault function right?

This seems kinda similar to the BAKE_CMD_CONTEXT var actually. Internally, we have this work by doing cwd:// - we could re-use this instead of local:// which should also let us share some code?

Ok thanks - so I should use the cwd:// prefix instead? I had a look through toBuildOpt but I don't see any reusable methods?

@jedevc
Copy link
Collaborator

jedevc commented Jun 27, 2023

Could you please point me in the right direction where to do this? I should do it like the TestReadLocalFilesDefault function right?

We have our integration tests in https://github.com/docker/buildx/blob/master/tests/bake.go, and our bake unit tests in https://github.com/docker/buildx/blob/master/bake/bake_test.go. Ideally - we'd be able to have both, though if the logic is only defined in the commands package, we can't have a unit test under our current structure really (which is absolutely fine).

Ok thanks - so I should use the cwd:// prefix instead? I had a look through toBuildOpt but I don't see any reusable methods?

Yeah, cwd:// would be preferable I think, just so we don't end up having multiple different prefixes for the same thing, referencing local directories.

It's fine if the code doesn't share nicely, this is for different purposes 馃帀 Maybe it would be good to try and define the cwd:// constant somewhere though, so at least when manipulating the strings we're using common code (having different code for manipulating URLs has gotten us before 馃槩).

commands/bake.go Outdated Show resolved Hide resolved
@jedevc
Copy link
Collaborator

jedevc commented Jul 26, 2023

Also, can you squash commits, and add a sign-off (see https://github.com/docker/buildx/blob/master/.github/CONTRIBUTING.md#sign-your-work)

@c-ameron c-ameron force-pushed the feat/local-remote-files branch 2 times, most recently from 9034439 to 5638919 Compare August 12, 2023 15:42
@c-ameron
Copy link
Contributor Author

Hi, apologies for the delay in getting this done. I've added an integration test as well. Let me know if you require anything else. Thanks for your time 馃槂

@c-ameron c-ameron requested a review from jedevc August 12, 2023 15:46
@jedevc jedevc dismissed tonistiigi鈥檚 stale review August 13, 2023 13:22

Comments were addressed

@jedevc
Copy link
Collaborator

jedevc commented Aug 13, 2023

@c-ameron I realized that 5638919#diff-3f9c21dce82a82fae6d5ca096e77e5ddcf0eccd7051f815b452ec26fbfeb314bR284 was incorrect, which was causing the e2e tests to fail.

I pushed a commit that should fix that up, and simplifies the splitting logic, so we don't need the isRemote argument - hopefully looks good to you.

@jedevc jedevc requested a review from tonistiigi August 13, 2023 15:37
@c-ameron
Copy link
Contributor Author

Cool! Thanks for your help @jedevc ! 馃槂

@c-ameron
Copy link
Contributor Author

c-ameron commented Sep 7, 2023

Is this ok to be approved/merged @tonistiigi ? Thanks in advance! 馃槂

@c-ameron c-ameron force-pushed the feat/local-remote-files branch 4 times, most recently from 78616f2 to 6d13818 Compare October 4, 2023 16:21
@c-ameron
Copy link
Contributor Author

c-ameron commented Oct 4, 2023

I've rebased the commit onto master as there was a conflict in commands/bake.go :)

Although I'm not sure why this test is now failing https://github.com/docker/buildx/actions/runs/6408757454/job/17398732309?pr=1838

@crazy-max
Copy link
Member

Although I'm not sure why this test is now failing https://github.com/docker/buildx/actions/runs/6408757454/job/17398732309?pr=1838

@c-ameron Sorry for the delay. I have rebased to fix this ci issue.

I pushed an extra commit to fix some error handling when reading local/remote files and consolidate the logic in a single func as well. Feel free to squash if that looks good to you.

@c-ameron c-ameron force-pushed the feat/local-remote-files branch 2 times, most recently from 9bd369d to 589a4c9 Compare October 23, 2023 13:52
@c-ameron
Copy link
Contributor Author

No worries, thanks @crazy-max . I've squashed and added you as a co-author too.

@crazy-max crazy-max force-pushed the feat/local-remote-files branch 3 times, most recently from 208b042 to 38b0bc0 Compare October 24, 2023 17:35
This adds the ability to source additional local build definition files when
sourcing Bake files via a remote url.
Prefixing a file with 'cwd://' will source a bake file on the local
machine, instead of the remote location.
Local files will be read/have precedence before remote files.

Usage:
```
docker buildx bake https://github.com/example/upstream.git --file cwd://docker-bake.override.hcl --print
```
This will source a default file from the example/upstream repository,
and also source a build definition from the local machine.

Also moves remote and local files reading logic to a func

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Cameron Adams <pnzreba@gmail.com>
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
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.

None yet

4 participants