Skip to content

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

Merged
crazy-max merged 1 commit into
docker:masterfrom
c-ameron:feat/local-remote-files
Nov 2, 2023
Merged

command(bake): Specify local and remote bake files#1838
crazy-max merged 1 commit into
docker:masterfrom
c-ameron:feat/local-remote-files

Conversation

@c-ameron

@c-ameronc-ameron commented May 24, 2023

Copy link
Copy Markdown
Contributor

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!

@tonistiigitonistiigi left a comment

Copy link
Copy Markdown
Member

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.

Comment threadcommands/bake.go Outdated
Comment threadcommands/bake.go Outdated
@jedevc

jedevc commented May 25, 2023

Copy link
Copy Markdown
Collaborator

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 ❤️

tonistiigi
tonistiigi previously requested changes Jun 20, 2023

@tonistiigitonistiigi left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Collaborator

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 😢).

@c-ameron
c-ameronforce-pushed the feat/local-remote-files branch from 99761bf to c84b21dCompareJuly 7, 2023 21:43
Comment threadcommands/bake.go Outdated
@jedevc

Copy link
Copy Markdown
Collaborator

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-ameronforce-pushed the feat/local-remote-files branch 2 times, most recently from 9034439 to 5638919CompareAugust 12, 2023 15:42
@c-ameron

Copy link
Copy Markdown
ContributorAuthor

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 jedevcAugust 12, 2023 15:46
@jedevc
jedevc dismissed tonistiigi’s stale reviewAugust 13, 2023 13:22

Comments were addressed

@jedevc

Copy link
Copy Markdown
Collaborator

@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 tonistiigiAugust 13, 2023 15:37
@c-ameron

Copy link
Copy Markdown
ContributorAuthor

Cool! Thanks for your help @jedevc ! 😃

@c-ameron

Copy link
Copy Markdown
ContributorAuthor

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

@c-ameron
c-ameronforce-pushed the feat/local-remote-files branch 4 times, most recently from 78616f2 to 6d13818CompareOctober 4, 2023 16:21
@c-ameron

c-ameron commented Oct 4, 2023

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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-ameronforce-pushed the feat/local-remote-files branch 2 times, most recently from 9bd369d to 589a4c9CompareOctober 23, 2023 13:52
@c-ameron

Copy link
Copy Markdown
ContributorAuthor

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

@crazy-max
crazy-maxforce-pushed the feat/local-remote-files branch 3 times, most recently from 208b042 to 38b0bc0CompareOctober 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@c-ameron@jedevc@crazy-max@tonistiigi