I need to set some environment variables programmatically before my rubber instances start the webserver. I've set the environment variables in the config/rubber/common/rubber.profile file. When I ssh into the instance, the Env variables are set properly and if I run the Rails console the variables are loaded in the environment. However, the webserver appears to be loaded prior to the env variables being set. The apis fail on the web server due to the initializers having blank ENV vars. How do I make sure that Rubber sets the bash profile prior to starting the web server?
Related
Is it wrong to put env variables in the express server file ? is it going to be seen by any one?
env variables in server file
You should include it in gitignore file so no one gets the repo has access to env variables, also if you are using docker make sure to let it know about your env files when you deploy it as a service,
in case you are using cloud for hosting, include the env variables into the service configurations that way the info in the env file won't be exposed
you should create an env file and put it in gitgnore so that in production you variables can not be exposed.This make env file not to be exposed on version control like git, but you will have to define those env variables in your third party hosting service provider.
I swear this is the hardest thing to find on the internet.
My Redis instance has a password.
How do i configure this from an environment variable in the Rocket.toml file?
Here is what i have inside Rocket.toml. And it works perfectly if redis has no password.
[release.databases.redis]
url = "redis://redis_trending_server"
redis_trending_server here is my redis server given from docker-compose file. This works. But now I have set a redis password.
I have also passed this password in an environment variable to Rust ${MY_REDIS_PASSWORD}
Now inside the Rocket.toml file how do i first
Grab that environment variable
and then
configure that password in the url above?
I cant find a single documentation any where on this -__-
I am wondering if you call setenv() on a shared web host, in general, is this allowed? Or would such a feature be disabled on most hosts as you are setting a global environment variable. I.e. if you have a cgi program, on most web hosts would setenv actually work?
Wondering if it is a security issue and they have it disabled..
Reason I ask is because for some programs, setting up PATH variables as a setenv call would be very useful, but if this feature is not portable to all servers and some servers disable this then it would not be very portable code if you ever change servers.
And I do not mean a cgi variable or post variable, I mean an actual operating system setenv call that really sets a real environment variable on unix, not just an apache server variable or http variable or such.
Yes, it's allowed but note that it will only have an effect on processes that your CGI script launches.
This is true in general and not specific to CGI. setenv() only affects the current program's environment and (in general) the environment of any child processes. Setting of "systemwide" environment variables is done in various startup scripts, etc.
I tried to set up sensitive information as environment variables in CentOS, and pass them to Flask config file used in main file, i.e. init.py . But it did not work. The Flask application is running under Apache.
I first edit /etc/environment as root user
MAIL_USERNAME="abcde#abc.com"
then logout, login again
Then verify MAIL_USERNAME is set by running
echo $MAIL_USERNAME
This works fine
And in configuration.py, this is how I set MAIL_USERNAME.
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
for testing purpose,
I print out MAIL_USERNAME
in __init__.py
print(MAIL_USERNAME)
Then from terminal, if I run
python3.4 __init__.py
it print out correct values of MAIL_USERNAME
However, if I tested on web browser, MAIL_USERNAME is just not set. it shows NONE. I verify this by looking Apache log.
Any idea of how this works would be really appreciated.
Thanks
With your CLI, set the environment variable as you want. On Linux and macOS, this is done with export KEY=value.
After that, the environment variable KEY will be available for your Python script or Flask app via os.environ.get('KEY'), like this:
import os
print os.environ.get('key')
>>> value
I had a very similar problem because I used PyCharm terminal to run flask. A similar issue was described and solved here.
My solution was switching to regular cmd (I worked on Windows 10) and just running everything there:
>> set MAIL_USERNAME='bla#example.com'
... (other env variables sets)
>> py manage.py runserver (I run my flask app through a manage script)
I could successfully send an email using my flask app - all the environment variables used in the app were read correctly.
On Linux you can just use export instead of set.
I hope it helps.
Maybe you can use Apache directive PassEnv as mentioned here on Apache's official web documenting how to use environment variables.
There are two kinds of environment variables that affect the Apache HTTP Server.
First, there are the environment variables controlled by the underlying
operating system. These are set before the server starts. They can be used in
expansions in configuration files, and can optionally be passed to CGI scripts
and SSI using the PassEnv directive.
Second, the Apache HTTP Server provides a mechanism for storing information
in named variables that are also called environment variables. This information
can be used to control various operations such as logging or access control.
The variables are also used as a mechanism to communicate with external programs
such as CGI scripts. This document discusses different ways to manipulate and
use these variables.
Although these variables are referred to as environment variables, they are
not the same as the environment variables controlled by the underlying
operating system. Instead, these variables are stored and manipulated in an
internal Apache structure. They only become actual operating system environment
variables when they are provided to CGI scripts and Server Side Include scripts.
If you wish to manipulate the operating system environment under which the server
itself runs, you must use the standard environment manipulation mechanisms
provided by your operating system shell.
I make some of the text cited above bold to make things clearer and maybe easier to explain.
Hope this helps.
N00b question here, but I am currently deploying my Rails webapp on my EC2 server instance using rubber. I was previously deploying on heroku (got frustrated with how slow it was on each startup) and decided to switch hosts last night.
There are a few environment variables I'd like to set upon deploying (for stripe). In my heroku case, I was able to just set the environment variables at the command line using something like:
heroku set ENV_VAR1=xxxxyyyyzzzz ENV_VAR2=xxxxyyyyzzzz
I was wondering if there was either a cap command, or some file I could alter to set those evironment vars on EC2, or even a command from the command line I could run to set them? I am not super familiar with rubber / cap, as I was just following one of the rails cast videos last night.
Thanks everyone.