How to set up environment variables in Digital Ocean? - heroku

Earlier I used Heroku and setting environment variables was very easy.
heroku config:set my_variable="TEST"
Now , I have started using Digital Ocean and I can't figure out how to set it.My server is on Ubuntu.

use command on terminal
export YOUR_VARIABLE=/your/location
Documentation about this
https://help.ubuntu.com/community/EnvironmentVariables

Related

Dokku (Heroku) bulk set environment variables ("config vars")

Heroku docs indicate that "On a traditional host or when working locally, you often set environment variables in your .bashrc file. On Heroku, you use config vars". On Dokku the process is analogous: https://dokku.com/docs/configuration/environment-variables/
With the "traditional" method I can take a .env file append it's contents to .bashrc over ssh with a single automated standard unix command.
The Heroku docs only describe how to set "config vars" one by one. It would take unacceptably long to do this.
On Heroku one could perhaps use the api. But Dokku does not have an API.
Question is similar to Setting Dokku environment variables
The accepted answer there speaks about a local CLI for dokku where you can run $ dokku config:set:file <path/to/.env>. I can't find documentation on this command with "standard" dokku. I don't need a local CLI I can ssh and scp to my server.
Question is similar to Bulk set the environment variables in Heroku pipeline except that I don't know what a Heroku pipeline is and I'm not using one (and the question has no answer).
Is there a mechanism short of creating a bash script or installing a local Dokku CLI for bulk updating config vars in Heroku based on a .env file with a long list of variables?
Sure, use heroku config:set ENV_ONE=value ENV_TWO=value ENV_THREE=value from the heroku CLI in your terminal.
Make sure it's all a single line, use spaces, not line breaks.

How do you get all ENV variables from Heroku (Including internal variables)

How do I get HEROKU specific ENV variables? (Such as $HEROKU_API_KEY_ENC)
I'm writing a buildpack to perform some operations on app deploys (not dyno restart, just deploy) but I need to know which variables are available at that point.
I know I have access to my own environment variables and HEROKU runtime dyno metadata but I'd like to see what else is there, such as which git user is making the deploy, or whether there's a variable to determine it is a deploy or a restart etc.
I appreciate your help.
P.S I already tried deployhooks and it doesn't solve my problem.
The linux printenv command will display every available environment variable.
How about this
heroku config --app your_app_id | grep "your_variable"

How to add .env file or otherwise set environment variables in a Heroku app?

I've tried many different solutions on the web for this problem, but all have been unsuccessful.
Here's the problem: My app needs to know whether it is being run on Heroku (production mode) or locally (development mode). For this purpose, we want to use environment variables. I've understood that environment variables on Heroku can be set in a .env file. So my attempt was to run heroku run bash -a <app-name> and then to install vim by doing this:
mkdir ~/vim
cd ~/vim
# Staically linked vim version compiled from https://github.com/ericpruitt/static-vim
# Compiled on Jul 20 2017
curl 'https://s3.amazonaws.com/bengoa/vim-static.tar.gz' | tar -xz
export VIMRUNTIME="$HOME/vim/runtime"
export PATH="$HOME/vim:$PATH"
cd -
Apart from crashing repeatedly, vim didn't work anymore when I logged in and out of the shell:
~ $ vim // in the heroku shell
vim: error while loading shared libraries: libXt.so.6: cannot open shared object file: No such file or directory
I also tried heroku plugins:install heroku-vim but running heroku vim after that only resulted in a long delay followed by the normal heroku shell opening, no vim.
I don't really care if I get vim to work. I just want to be able to write in a file named .env on Heroku so I can set environment variables in it.
How can I achieve this?
There is no need for an .env file on Heroku. In fact, such a file won't work very well since
Heroku gets all of its files from your Git repository,
has an ephemeral filesystem, meaning that changes to files like .env will be quickly lost, and
the .env file won't be available on other dynos if you scale your app
As such, creating an .env file on Heroku isn't a good approach.
Instead, you can use its built-in support for environment variables, using heroku config:set <var> <value> or its web UI. Either way, you'll get a regular environment variable.
It is fairly simple.
Just as you added them in your .env file, do the same with heroku's command line and you will see heroku restart and you are all set to fly again.
Just use the command :
(heroku config:set VARIABLE=this_is_the_value)
Remember to use the underscores in the value as spaces are not allowed not inverted quotes (" ")to turn it into a single string is permissible.

I set environment variable port for heroku but later I read that heroku set this it self , how can i remove that?

I set environment variable port for heroku but later I read that heroku set this it self ,port is also not shown in environment variable in advanced system settings but shown in command line when i enter SET or ENV how can i remove that?
Because my heroku app is not running?
If you have manually set the Heroku PORT env var, you need to unset it. It is dynamically set by Heroku at build time.
heroku config:unset PORT
https://devcenter.heroku.com/articles/config-vars

Heroku is switching my play framework 2 config file

I have a Play! application which is on Heroku.
My config file is different between my local application and the same on Heroku. Especially for the URL of my MongoDB base.
On localhost my base address is 127.0.0.1 and on heroku it's on MongoHQ. So when I push my application to Heroku I modify my config file.
But some times, like this morning Heroku change the config file. I pushed my application correctly configured on Heroku this morning and everything worked until now.
When I watch the logs I see that Heroku changed my config and try to connect to my local MongoDB base.
Is someone knowing what ? I hope I'm clear :)
Thanks everybody !
If there are differences in your application in different environments (e.g. local vs production), you should be using assigning the values with environment variables. For Play apps, you can use environment variables in your application.conf file, like this:
`mongo.url=${MONGO_URL}`
Then, on Heroku you can set the environment variables with config vars, like this (note, this may already be assigned for you by the add-on provider):
$ heroku config:add MONGO_URL=...
Locally, you can use Foreman to run your application with the environment variables stored in an .env file in your project root.

Resources