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

[Setup] Config generation fails on Windows #50

Open
mattrrubino opened this issue Feb 15, 2023 · 4 comments
Open

[Setup] Config generation fails on Windows #50

mattrrubino opened this issue Feb 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@mattrrubino
Copy link

Subject of the issue


Running npm run generate-config produces the error message unknown shorthand flag: 'g' in -g on Windows

Expected 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

@mattrrubino mattrrubino added the bug Something isn't working label Feb 15, 2023
@mattrrubino
Copy link
Author

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.yml

This is sufficient to set up a Windows development environment. Ideally, this could be incorporated into the generate-config script in package.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.

@mattrrubino
Copy link
Author

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-config script, which is why it is currently failing. I've come up with two solutions below:

  1. Create a separate script generate-config-windows which only uses batch syntax. The README would also have to be updated to include instructions for Windows users.
  2. Add a .npmrc file 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 .npmrc file does not break anything on Unix based systems. Assuming this is the case, I think this is a good solution to the setup issue.

@mattrrubino
Copy link
Author

It turns out that changing the shell to bash does not work because npm install only 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.

@emilkovacev
Copy link
Member

emilkovacev commented Feb 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants