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

Relative file path option for nx-container is not relative to the project root #1129

Open
Nicklason opened this issue Sep 19, 2024 · 1 comment

Comments

@Nicklason
Copy link

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:

file: options.file || join(getProjectRoot(ctx), 'Dockerfile'),

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.

"file": {
"type": "string",
"description": "Path to the Dockerfile (default Dockerfile)"
},

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.

@gperdomor
Copy link
Owner

gperdomor commented Oct 1, 2024

@Nicklason Hi buddy... If you want to have a Dockerfile in the root of the workspace, you need to pass this:

"file": "{workspaceRoot}/Dockerfile",

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

No branches or pull requests

2 participants