caprover / caprover-cli

Command Line Interface for https://github.com/caprover/caprover
72 stars 39 forks source link

Can't set envVars via CLI #47

Closed darkspirit510 closed 4 years ago

darkspirit510 commented 4 years ago

Hi all, using the web GUI it is possible to set container env vars both on creation (at least for one-click-apps) and in 'app configs' tab. Both of those will send a JSON to /user/apps/appDefinitions/update with:

{
...
"envVars": [
    {
      "key": "some-env-key",
      "value": "some-env-value"
    }
  ]
}

When I try to do the same with CLI:

caprover api -t "/user/apps/appDefinitions/update" -m POST -d "{\"appName\":\"mysql\",\"instanceCount\":1,\"captainDefinitionRelativeFilePath\":\"./captain-definition\",\"notExposeAsWebApp\":true,\"volumes\":[{\"volumeName\":\"mysql-data\",\"containerPath\":\"/var/lib/mysql\"}],\"ports\":[],\"envVars\":[{\"key\":\"MYSQL_ROOT_PASSWORD\",\"value\":\"asdf1234\"}]}"

no environment variable is set. Any idea how to set env vars from CLI?

githubsaturn commented 4 years ago

What do get as response back? Does it say "Updated App Definition Saved" ?

Is the problem limited to env vars? Or other parameters, such as notExposeAsWebApp cannot be set?

darkspirit510 commented 4 years ago

Response of mentioned command:

------------

CapRover CLI has recently been refactored. Please report potential bugs here: https://github.com/caprover/caprover-cli/issues

------------

Call generic CapRover API [Experimental Feature]...

Ensuring authentication...

API call completed successfully!

{}

Good, that you asked. Single values like notExposeAsWebApp are set. No array values get persisted (neither envVars nor volumes. did not test ports)

Another error I forgot to mention: Setting forceSsl (even if false) in the given command throws Error Code: 1108 Message: Cannot force SSL without at least one SSL-enabled domain!. Leaving it out works. GUI sends this as false.

Edit: notExposeAsWebApp is not set 😔, but other values (container port, instance count, description) work.

githubsaturn commented 4 years ago

@darkspirit510

Thanks for the detailed info. Turned out to be a bug in the JSON parse that the CLI uses to send API request. I fixed the bug in https://github.com/caprover/caprover-cli/commit/00693aae03538ac110db6519a232b0ce9aff0d80

I'll publish the new version with the bugfix in next few minutes...

Boscop commented 3 weeks ago

@githubsaturn Is there a more concise way to just set env vars via the CLI (without having to specify/overwrite the other fields of the app definition)? 🙂

githubsaturn commented 3 weeks ago

Not at the moment. The update endpoint takes a snapshot of the entire config object and updates it. Of course, you can simply write a script that: