0

I'm trying to copy ~/.aws into my docker container. But I'm on a Windows machine running git-bash and that seems to be causing some issues.

Two things I've tried so far:

"d-aws-copy": "docker cp ~/.aws constraint-listener:/usr/src/app"

Result: GetFileAttributesEx C:\work\project-name\~: The system cannot find the file specified.

"d-aws-copy": "docker cp /c/Users/user-name-here/.aws constraint-listener:/usr/src/app",

Result: GetFileAttributesEx C:\c: The system cannot find the file specified.

All the solutions I've seen involving tilde expansion are for node code, not for command line npm scripts.

If I run docker cp ~/.aws constraint-listener:/usr/src/app from bash it works fine. But inside of an npm script it crashes as seen above.

How can I get ~ to work in an npm script on a Windows machine?

jcollum
  • 43,623
  • 55
  • 191
  • 321

2 Answers2

0

Solution is to call bash directly:

"d-copy-aws": "bash -c \"docker cp ~/.aws constraint-listener:/root\" && echo aws credentials copied",
jcollum
  • 43,623
  • 55
  • 191
  • 321
0

When calling out from Node you are using the standard shell, probably CMD on Windows. It won't string interpolate the tilde. Use a platform independent variable instead or detect the platform and look up the value of either $HOME or $WINHOME using process.env - depending on the OS.

Edit: didn't see it was an NPM script ... Missed the tag. Thought the question mentioned Node.

oligofren
  • 20,744
  • 16
  • 93
  • 180