Repository navigation
[Setup] Config generation fails on Windows #50
Description
Activity
Adding quotes and running through PowerShell resolves the issue:
docker run --pull always -v "$(pwd)/config:/config" --user "$(id -u):$(id -g)" --rm ubautograding/devtools /generateConfig.sh config/default.ymlThis is sufficient to set up a Windows development environment. Ideally, this could be incorporated into the
generate-configscript inpackage.json. This would look like the following:"generate-config": "docker run --pull always -v \"$(pwd)/config:/config\" --user \"$(id -u):$(id -g)\" --rm ubautograding/devtools /generateConfig.sh config/default.yml"Unfortunately, when this command is run indirectly through npm (as opposed to directly through PowerShell), a new error occurs. It says:
docker: Error response from daemon: create $(pwd)/config: "$(pwd)/config" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.It seems that subcommands are not evaluated properly when running through npm. I'm going to continue to look into this, but at least there is now an option for developing on Windows.
I figured out the problem. It turns out that npm creates a new shell for every run, and the default shell for windows happens to be cmd.exe (command prompt). This shell does not support the subexpression syntax used in the
generate-configscript, which is why it is currently failing. I've come up with two solutions below:- Create a separate script
generate-config-windowswhich only uses batch syntax. The README would also have to be updated to include instructions for Windows users. - Add a
.npmrcfile to the project to tell npm to use bash instead of the default shell.
Solution 1 is good because it will work on any Windows machine without additional configuration. However, it means that setup instructions will be different depending on the platform, which could complicate things unnecessarily. Solution 2 seems more elegant because, from the user's perspective, the setup process has not changed at all (except for the fact that it works). The only negative to solution 2 is that it assumes that the user has bash installed somewhere on their path. However, I think this is a reasonable assumption since it ships with Git for WIndows, and Git is a prerequisite for acquiring the repository.
I am going to open a PR with solution 2 for now. I still need to verify that the addition of the
.npmrcfile does not break anything on Unix based systems. Assuming this is the case, I think this is a good solution to the setup issue.Reacted by Emil Kovacev- Create a separate script
It turns out that changing the shell to bash does not work because
npm installonly adds scripts for batch, PowerShell, and sh. Git for Windows also comes with sh, so I think that this could still work. However, changing the shell to sh creates a new error on Windows.It says:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "C:/Program Files/Git/generateConfig.sh": stat C:/Program Files/Git/generateConfig.sh: no such file or directory: unknown.I am not sure how to resolve this at the moment, but I will look into it later.
The one thing I was looking at is doing the "docker pull" command from within a docker container (henceforth dockerizing the application). That should ideally prevent any of the cross-platform crashes, but getting it to work has been troublesome to say the least.
Subject of the issue
Running
npm run generate-configproduces the error messageunknown shorthand flag: 'g' in -gon WindowsExpected behaviour
The file config/default.yml is generated
Actual behaviour
An error occurs
Steps to reproduce
Clone the repository and run the setup instructions on a windows machine
Any relevant logs, error output, etc?
unknown shorthand flag: 'g' in -g