Cli: Add mechanism to sync site `env` vars to local process

Created on 10 Oct 2018  ·  10Comments  ·  Source: netlify/cli

We need a way to sync the Remote netlify sites build enviroment variables down to the local terminal process.env

Not sure what the command is but something like

netlify env:sync # ¯\_(ツ)_/¯

This would use the API to call into the site ID and pull back all the build env variables on process.env of the current terminal session.

need-info

Most helpful comment

Love this idea. As a contribution to this conversation, I love how Kontena handles this.

Here's my idea as a heavy cmdline user:

$ netlify env:write FOO=bar # creates or overrides
$ netlify env:write BAZ=candy
$ netlify env:read FOO
FOO=bar
$ netlify env:ls
FOO=bar
BAZ=candy
$ netlify env:rm BAR
$ netlify env:push /path/to/env_in # overrides all
# or even $ netlify env:push | cat /path/to/env_in
$ netlify env:pull /path/to/env_out

All 10 comments

Hehe, this is what I _thought_ #134 was talking about, mostly because I was reading into it the idea I already had in my head. Now, _this_ is what I actually had in mind!

I was thinking of some similar possible commands, like env:list (to see in terminal but not change files), and possibly env:push and env:pull.

I've been toying with how to handle variables you don't want syncing with Netlify. Possibly a comment wrapper to limit the syncing to a section of the file.

I also like the fact that you're authenticated as your Netlify user, so permissions are pretty clear - if you have permission to see/edit the variables in the Netlify UI, you have permission to sync them with the CLI.

Love this idea. As a contribution to this conversation, I love how Kontena handles this.

Here's my idea as a heavy cmdline user:

$ netlify env:write FOO=bar # creates or overrides
$ netlify env:write BAZ=candy
$ netlify env:read FOO
FOO=bar
$ netlify env:ls
FOO=bar
BAZ=candy
$ netlify env:rm BAR
$ netlify env:push /path/to/env_in # overrides all
# or even $ netlify env:push | cat /path/to/env_in
$ netlify env:pull /path/to/env_out

I like it, wouldn't be hard to add.

Yeah it makes sense! Very similar to how heroku env vars work https://devcenter.heroku.com/articles/config-vars#accessing-config-var-values-from-code

# Set vars
netlify env:set FOO=bar BAZ=lol

# Get vars
netlify env:get FOO
# Get vars output to json for piping
netlify env:get FOO --json

# List all vars
netlify env:list
netlify env:list --json
netlify env:list --output file/path

# Sync vars. Syncs remote vars with terminal process.env
netlify env:sync

(^ something like this)

We want to try and keep command semantics similar. IE netlify sites:list and netlify env:list etc. This is to keep the API easy to reason about when switching between commands

Any progress on this?

@muhajirframe Not yet, sorry.

@bcomnes how about now? Happy new year! 🥳

An app running in the terminal can't really manipulate terminal's env variables. You can just print them but the user will have to set them manually. Or they would need to do run $(netlify env:sync), where netlify env:sync would just print export SOMETHING=ELSE.

We already have mechanisms for setting the remote env variables to Netlify Dev in both app server and functions server. Not sure what purpose this would serve.

Closing this because a similar functionality already exists. (Read above 👆🏽). Feel free to reopen if not the case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cco3 picture cco3  ·  4Comments

karl-cardenas-coding picture karl-cardenas-coding  ·  4Comments

karl-cardenas-coding picture karl-cardenas-coding  ·  3Comments

mrlubos picture mrlubos  ·  5Comments

RaeesBhatti picture RaeesBhatti  ·  4Comments