I'm registering a task definition and need to supply the command attribute as a string, not an array. The reason I want this is so that I can easily supply a "multiline" command as such:
taskDefReg.containerDefinitions[0].command = 'git pull whatever; cd whatever; node whatever; etc'
This "shell form" should be valid according to docker docs: https://docs.docker.com/reference/builder/#cmd
However, I get the error msg:
message: 'Expected params.containerDefinitions[0].command to be an Array',
Any way we can add the ability to define CMD in shell form??
Thanks
I would suggest bringing this up in the ECS forums, since this is an API issue that cannot be solved in the JS SDK directly (we simply provide an interface to the public API). That said, according to Docker documentation, "exec form" is the preferred form, since it has better support for arguments with spaces and other issues surrounding accidental interpolation.
If you do not have arguments with spaces or multiple commands, you can easily convert to this format with:
var cmd = 'git pull whatever'.split(' ');
taskDefReg.containerDefinitions[0].command = cmd;
That should allow you to provide the command in the correct format, but won't actually support shell form with variable substitution and multiple commands. If you would like to support that format, this would have to be supported in the public API first.
edit: oops, I misread the shell form portion of the docs! Fixed that.
Thanks for the response @lsegal. I'll try to post something in the forums. In the meantime.... I guess I'll have to write an extra build script (then run only that from docker CMD) instead of compressing everything into a multiline cli command. Too bad.
I'm also going to test if I can make exec form work by inserting '/bin/sh -c' in between each seperate 'line' of my command array. Not ideal though...
Just tested something like this:
["sh", "-c", "git", "clone", "whatever", "sh", "-c", "cd whatever", "sh", "-c", "npm install"]
This does not work. Everything after the first executable (git) just gets parsed as arguments to that first executable. Oh well.
@MeanwhileMedia I think it would work if you quoted the shell command. For example:
var cmd = "sh -c 'echo a && echo b'".split(' ');
Just tried your suggestion, as well as several other variations... turns out you can get it to work simply by doing:
["sh", "-c", "git clone whatever; cd whatever; npm install"]
So if you want to use shell form, you just push your string into array ["sh", "-c"]. Just make sure the entire multi-line command is a single string.
Glad you got it working!
Thanks for your help @lsegal
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
Just tried your suggestion, as well as several other variations... turns out you can get it to work simply by doing:
["sh", "-c", "git clone whatever; cd whatever; npm install"]
So if you want to use shell form, you just push your string into array ["sh", "-c"]. Just make sure the entire multi-line command is a single string.