rust diesel-cli setting up multiple env files for different environments - rust

I am new to rust programming. I am trying to learn how disel-cli works. It's quite similar to knex in express node projects.
I have created two migartion files using following commands -
echo DATABASE_URL=postgres://username:password#<dev url>/diesel_demo > .env.dev
echo DATABASE_URL=postgres://username:password#<prod url>/diesel_demo > .env.prod
I want to run migration to one of these two regions (dev/prod) by passing environment varibale. How do I do it?

You can use the argument --database-url to specify the database you want the command on.
For example:
diesel --database-url $(cat .env.prod) migration run

Related

Node js package.json script not getting argument

I have a nodejs server and I'm writing some migrations.
For some reason my script is not recognizing the desired name for the migration:
this is my script:
"create-migrate": "migrate-mongo create $NAME"
This is supposed to let me use something like :
npm run create-migrate init-data
and create a migration named "init-data".
What happens - it's just creating the migration using the "$NAME" as the name...
I'm not sure if it has something to do with me working on windows or not,
anyway I will be thankful for some light here.
Actually you don't need the $NAME argument
just use like this
"create-migrate": "migrate-mongo create"
and what ever you pass after create-migrate will become it name
example
npm run create-migrate init-data

NodeJS Google Vision is unable to detect a Project Id in the current environment

Under Ubuntu environment, NodeJS Google Vision complains:
Error: Unable to detect a Project Id in the current environment.
Even though I already put json credential through
$ export GOOGLE_APPLICATION_CREDENTIALS=/var/credential_google.json"
Please help.
As a quick hack you can try this :
$ GOOGLE_APPLICATION_CREDENTIALS="/var/credential_google.json" node app.js
It's not recommended to use a .json config file locally. I've seen these leak on production servers causing whole platforms to be deleted + the introduce environmental switching and security issues.
Setup Google Cloud CLI.
Now the server will 'look' at the local environment and use that.
If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id.
You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running.
Run
gcloud config set project [some-project-id]
Now if you run (node example)
"dev": "NODE_ENV=dev GCP_PROJECT=some-project-id nodemon index.ts",
It will load the project environment. This also allows you to deploy easier with:
"deploy:dev": "y | gcloud app deploy --project some-dev-project app.yaml",
"deploy:prod": "y | gcloud app deploy --project some-prod-project app.yaml"
App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.
If you are usually a windows user and trying out Ubuntu (like me), the problem is likely with the assumptions that the export command exports variable to all terminal sessions and that you need to open a new terminal to get it to use (as expected in a windows terminal for an environment variable).
The export command doesn't export the variable to another terminal session. So if you export it in a terminal, you use it on the same terminal.
If you would like to export it permanently, then you can try the solution listed here
You can put the path to the JSON credentials directly when instantiating the client, by passing it as an argument.
For example:
const client = new speech.SpeechClient( {keyFilename: "credential_google.json"});
Also, for me setting it in the terminal didn't work.

how to setup multiple paths in user environmental variables in windows 10

I want to set up multiple paths in the user environmental variables in windows 10. but can only set a single path, how to overcome this issue?
If you want to add user defined environment variable then use react-native-config library. So in short if there are variables defined in .env file then you can use it anywhere in the react-native app like below:-
.env file
API_URL = "https://baseurl/endpoint"
//To use the above environment variable
import config react-native-config
function apiCall() { axios(config) }
With the help of react-native-config you can use environment variable in native code also and vise-versa.
For better use define .env.staging file. By default config lib finds .env file. To run the application with .env.staging file see below command.
$ ENVFILE=.env.staging react-native run-ios # bash
$ SET ENVFILE=.env.staging && react-native run-ios # windows
$ env:ENVFILE=".env.staging"; react-native run-ios # powershell
For more information checkout :- https://github.com/luggit/react-native-config
Happy coding mate :)
to add multiple paths for a single environment variable, list them all with a semicolon(";") in between like that:
C:\Cpp_Headers\pybind11;C:\Cpp_Headers\cpython\Include;C:\Users\admin\Cpp_Headers\cpython\PC
(and so forth). From this input Windows will automatically recognize multiple definitions.

How can I make node application see system variables on Google Cloud?

I have variable set in my .bash_rc file:
whoami#cloudshell:~/source/NodePrototype (x-alcove-9999999)$ echo $APP_ENVIRONMENT
LIVE
Yet node.js application out of:
const app_environment_config=require('./APP_ENVIRONMENT/' + process.env.APP_ENVIRONMENT)
produce
2019-02-21 14:18:16 default[20190221t141628] Error: Cannot find module './APP_ENVIRONMENT/undefined'
Eventhough when I enter node shell:
whoami#cloudshell:~/source/NodePrototype (x-alcove-9999999)$ node
> process.env.APP_ENVIRONMENT
'LIVE'
The same part works locally.
It depends on how your Node app is being launched, because looks like is not running in an environment where that variable exists, to make sure print all your current env vars to make this sure: console.log(process.env).
Also, a good practice, when you need something like that, is to use .env files with this module: https://www.npmjs.com/package/dotenv is a good practice to pass configuration to your Node apps.

How can I define my ENV variables once in the DockerFile and pass them down to my spark image which is submitted by a supervisord managed script?

I am building some Docker Spark images and I am a little puzzled on how to pass environment (ENV) variables defined in the DockerFile all the way down into the container via "run -e", on into the supervisord and and then into the spark-submit shell without having to hard-code them again in the supervisord.conf file (as seems to be the suggestion in something somewhat similar here: supervisord environment variables setting up application ).
To help explain, imagine the following components:
DockerFile (contains about 20 environment variables "ENV FOO1 bar1", etc.)
run.sh (docker run -d -e my_spark_program)
conf/supervisord.conf ([program:my_spark_program] command=sh /opt/spark/sbin/submit_my_spark_program.sh etc.)
submit_my_spark_program.sh (contains a spark-submit of the jar I want to run - probably also needs something like --files
•--conf 'spark.executor.extraJavaOptions=-Dconfig.resource=app'
•--conf 'spark.driver.extraJavaOptions=-Dconfig.resource=app' but this doesn't quite seem right?)
I guess I would like to define my ENV variables once in the DockerFile and only once, and I think it should be possible to pass them into the container via the run.sh using the "-e" switch, but I can't seem to figure out how to pass them from there to the supervisord and beyond into the spark-submit shell (submit_my_spark_program.sh) so that they are ultimately available to my spark-submitted jar file. This seems a little over-engineered, so maybe I am missing something here...?
Apparently the answer (or at least the workaround) in this case is to not use System.Property(name, default) to get the Docker ENV variables through the supervisor, but instead use the somewhat less useful System.getenv(name) - as this seems to work.
I was hoping to be able to use System.Property(name, default) to get the Docker ENV variables, since this offers an easy way to supply default values, but apparently this does not work in this case. If someone can improve on this answer by providing a way to use System.Property, then by all means join in. Thanks!

Resources