nx-tools
nx-tools copied to clipboard
Relative `file` path option for nx-container is not relative to the project root
The Dockerfile for all the apps in my nx project are identical. Because of this I want to reuse a single Dockerfile for all the apps. The default behavior is that the nx-container executor uses the Dockerfile inside the app's directory. Because of this, I passed ../../Dockerfile, expecting that it would use the Dockerfile in the root of my nx project. What actually happens is that it just passes ../../Dockerfile as the file option to the build command which is not what I expected.
This behavior comes from this line of code:
https://github.com/gperdomor/nx-tools/blob/df601249cd340686169cf7488e1f7adf030692f9/plugins/nx-container/src/executors/build/executor.ts#L21
I expected it to work more like this:
path.isAbsolute(options.file) ? options.file : path.join(getProjectRoot(ctx), options.file ?? 'Dockerfile')
If I give a full path I would expect it to use the full path. And if I give it a relative path I would expect it to be relative to the default path. It even says that Dockerfile is the default in the documentation, but if I manually pass Dockerfile then that results in a different behavior.
https://github.com/gperdomor/nx-tools/blob/df601249cd340686169cf7488e1f7adf030692f9/plugins/nx-container/src/executors/build/schema.json#L87-L90
A "workaround" is to just pass ./Dockerfile as the file option and run the command in the root of the nx project. The problem with this, is that it now depends on the directory I run the command in. It is not that big of a problem to me because I only use the nx-container executor in a CI environment.
@Nicklason Hi buddy... If you want to have a Dockerfile in the root of the workspace, you need to pass this:
"file": "{workspaceRoot}/Dockerfile",