GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

Environment variable #98

Open WolfastGuzmanLopez opened 3 years ago

WolfastGuzmanLopez commented 3 years ago

Hello kolban,

I'm using your palette in NodeRed for a university project but I'm running into some problems with the GOOGLE_CLOUD_PROJECT environment variable.

My NodeRed is installed with the use of Docker and I'm not able to set environment variables in the container running NodeRed so that they are read by the Google Cloud nodes.

Is there any workaround for this environment variable so that it is input in another field or it is not necessary?

Thank you very much in advance, Kind regards

Guzmán

kolban-google commented 3 years ago

Howdy my friend. Which platform are you running Node-RED on? Is it a PC, a Pi, Windows/Mac/Linux? What have you tried regarding passing environment variables into the container? What is the symptom/issue/story if you don't specify a GOOGLE_CLOUD_PROJECT environment variable?

vixlima commented 2 years ago

I have same problem with local(ubuntu) docker container with node-red.

When I tried connect to pub/sub I received this message:


Error: Unable to detect a Project Id in the current environment. 
To learn more about authentication and Google APIs, visit: 
https://cloud.google.com/docs/authentication/getting-started

But, I have configured a variable GOOGLE_CLOUD_PROJECT

andrelima@RD-005053:~$ docker exec -it nodered bash
bash-5.0$ export -p
declare -x FLOWS="flows.json"
declare -x GOOGLE_CLOUD_PROJECT="inforsolution-greenhouse"
declare -x HOME="/usr/src/node-red"
declare -x HOSTNAME="ceb6a0e261a9"
declare -x NODE_PATH="/usr/src/node-red/node_modules:/data/node_modules"
declare -x NODE_RED_VERSION="v2.1.4-1"
declare -x NODE_VERSION="14.18.2"
declare -x OLDPWD
declare -x PATH="/usr/src/node-red/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare -x PWD="/usr/src/node-red"
declare -x SHLVL="1"
declare -x TERM="xterm"
declare -x YARN_VERSION="1.22.15"
bash-5.0$ 
kolban-google commented 2 years ago

Howdy ... lets see if we can't find a solution. Can you describe to me how you set the environment variable for the container? Can you describe the exact command you used to start the docker container?

vixlima commented 2 years ago

Hello, I created a file $HOME/.bashrc with this content: export GOOGLE_CLOUD_PROJECT=inforsolution-greenhouse

I start docker container with this command: ~$ docker start nodered

kolban-google commented 2 years ago

When you say you created $HOME/.bashrc with the export of the environment variable ... was that in the machine hosting docker or was that in the docker container itself? Either way, I don't think that's the right answer.

I'm no great hero on docker, but I believe one has to pass in environment variables into Docker in a different way.

It appears to be:

https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file

vixlima commented 2 years ago

I created this file into the container.

kolban-google commented 2 years ago

I'm going to assume that when NodeRED runs "inside" the container, it won't run the .bashrc shell script as a precursor to it running. This would imply that when the NodeRED runtime runs inside the container, it won't have GOOGLE_CLOUD_PROJECT in its environment. We could run some tests. First, I think there is a "ps" command that will show the environment variables of a running process. If we ran this, we could see whether or not the NodeRED runtime actually has the variable (I'm assuming not). Other solutions would be edit the /etc/environment file in the container to include the variable and restart. The other thought is to set the environment variable globally on the container using something like:

--env GOOGLE_CLOUD_PROJECT=inforsolution-greenhouse

this would be supplied on docker run command.

vixlima commented 2 years ago

Hi, I fixed the problem with steps: 01 - stop docker service: sudo snap stop docker 02 - change config.v2.json from the nodered container adding: "GOOGLE_CLOUD_PROJECT=inforsolution-greenhouse" in ENV node. 03 - start docker service.

thanks Kolban-google for all suport.

vixlima commented 2 years ago

Kalban, I tried all approaches overhead without success. Only modifying config.v2.json that I could connect to GCP.

kolban-google commented 2 years ago

Sadly I'm not at all familiar with config.v2.json. Is there a document or link we can look at that describes that file? I couldn't find an obvious one with a Google search.