Skip to content

Conversation

savil
Copy link
Collaborator

@savil savil commented Oct 6, 2022

Summary

This should fix a consequence of a change introduced in #200 to make the devbox.srcDir be an absolute path.
In the BuildPlanners, we need the paths to be relative so they are inside the "docker context" and
can be used in Dockerfiles.

New Fix:
I think the problem is actually scoped to just the NodeJSPlanner. Within NodeJSPlanner, the inputFiles were being set using filepath.Join(srcDir, <filename>) when instead it should be just <filename>, or more pedantically path/of/filename/from/devbox-json.

This is because the docker-context is the directory-of-devbox-json, and any files COPY --link'd should be specified with paths relative to this docker-context.

I inspected git grep InputFiles and it seems NodeJSPlanner is the only one with this issue.

I also went back in history to a commit from Monday, built the binary and found that the following would fail due to this reason:

> cd testdata/nodejs
> devbox build nodejs-18

It works now with this fix.

How was it tested?

in www.jetpack.io repo,

  1. did devbox build and docker run -p 3000:3000 --expose 3000 -ti devbox and could open the website in localhost:3000
  2. did cd root-of-www.jetpack.io and did devbox build www && docker run -p 3000:3000 --expose 3000 -ti devbox. Works!
  3. did mkdir -p root-of-www.jetpack.io/www/fake-dir && cd root-of-www.jetpack.io/www/fake-dir and then: devbox build ../ && docker run -p 3000:3000 --expose 3000 -ti devbox. Works! Also, works with just devbox build i.e. omitting ../ argument (due to [config] look for the devbox.json file in parent directories as well #200)

For NodeJS testdata in testdata/nodejs:

  1. cd testdata/nodejs and devbox build nodejs-18 && docker run devbox. Works!
  2. cd testdata/nodejs/nodejs-18 and devbox build && docker run devbox. Works!
  3. cd testdata/nodejs/nodejs-18/fake-dir and devbox build && docker run devbox. Works!

in devbox repo,
did devbox build and docker run devbox with:

  • testdata/rust/rust-stable
  • testdata/python/pip-example

Copy link
Collaborator Author

savil commented Oct 6, 2022

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil force-pushed the savil/relative-paths-in-build branch from aa4ff52 to 96769e4 Compare October 6, 2022 00:31
@savil savil requested review from LucilleH and loreto October 6, 2022 00:32
Copy link
Collaborator

@LucilleH LucilleH left a comment

Choose a reason for hiding this comment

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

👍
Just to confirm, this works with devbox build <absolute_path>, devbox build <relative_child_path>, devbox build <relative_parent_path>, and devbox build?

@savil
Copy link
Collaborator Author

savil commented Oct 6, 2022

👍
Just to confirm, this works with devbox build <absolute_path>, devbox build <relative_child_path>, devbox build <relative_parent_path>, and devbox build?

I'll test these to verify, but conceptually these should work because we normalize all of these by using the absolute-path in devbox.Open() when initializing devbox.srcDir.

EDIT: ugh, no this will still fail 😩

@savil savil marked this pull request as draft October 6, 2022 03:20
@savil
Copy link
Collaborator Author

savil commented Oct 6, 2022

This has a bug: using devbox build <path> can sometimes fail. Will re-submit for review after I fix it.

@savil savil changed the title [build] use relative paths in devbox-build [nodejs planner] InputFiles should take paths relative to devbox.json, and not combined with srcDir Oct 6, 2022
@savil savil force-pushed the savil/relative-paths-in-build branch from e93b4ca to d3137eb Compare October 6, 2022 04:46
@savil savil requested a review from LucilleH October 6, 2022 04:46
@savil savil marked this pull request as ready for review October 6, 2022 04:46
Copy link
Collaborator

@LucilleH LucilleH left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

@loreto
Copy link
Contributor

loreto commented Oct 6, 2022

For a follow up PR: What can we do to catch these automatically? (and avoid a regression)

@savil
Copy link
Collaborator Author

savil commented Oct 6, 2022

For a follow up PR: What can we do to catch these automatically? (and avoid a regression)

Good question. I was thinking about this as well. One idea is to have a validatePlan function in planner, which can have validation rules. One validationRule can check that the inputFiles are not absolute paths.

We could run this validatePlan in devbox_test or even every time planner.BuildPlan() and planner.ShellPlan() is called. My preference is for doing it in devbox_test and ensuring we have good test coverage of various scenarios for the planners.

@savil savil merged commit 6d96c05 into main Oct 6, 2022
@savil savil deleted the savil/relative-paths-in-build branch October 6, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants