206 Configuration of your application

Posted Almost 6 years ago. Visible to the public.

In most cases your application needs configuration data like database endpoints or API keys to work. This section will help you find the correct location for your configuration data.

Ruby on Rails

There are multiple ways to configure your application Show archive.org snapshot .
The database configuration for your application is deliviered via our configuration management (which also creates and configures your database). You can find it in /var/www/$deployment/shared/config/database.yml.

Other configuration data should be stored in the directory shared/config too. It is synced between all your application servers and we will make daily backups of it. If you want us to deliver configuration files (like secrets.yml) for you just contact our operations team. We can deploy these files with our configuration management.

Environment variables

If your rails application expects configuration via environment variables you can place a shared/config/.env file. Environment variables can also be configured by our makandra operations team via our configuration management.

The application processes are invoked via bash so you will have all the variables written to this file available. See down below for more information.

Elixir / Phoenix

We place a database.exs file in the /var/www/$deployment/shared/config/ directory. You can use this file to build your application.
If you create a /var/www/$deployment/shared/config/.env file there will be some default environment variables with configuration for our hosting infrastructure:

  • DATABASE_URL: a database connection string like ecto://dbuser:password@127.0.0.1:false/dbname&pool_size=10
  • APPDIR: path to your application directory
  • PORT: the port your app must listen on

If you want to use environment variables to configure your application at runtime you can place them in /var/www/$deployment/shared/config/.env. Please ensure that your application is started via bash. The environment variables are only read when the application is invoked via a bash shell.

PHP application

There is no default configuration scheme for PHP applications. Ask our operations team for the database credentials. If you want to configure your application via environment variables contact our operations team to configure the variables for you.

Invalidating the PHP cache

When you deploy a new version of your PHP application, the fpm-php workers will not restart and clear your opcache and apc. As you usually want to start using your newly deployed code immediately, we allow clearing the caches using the FPM socket.

We suggest installing and using cachetool Show archive.org snapshot for this. After installation you may use it from your capistrano/compose tasks or on the cli like this:

$ php cachetool.phar opcache:reset --fcgi=/var/run/php/$deployment-fpm.sock

Configuring your application via environment variables

Please mind that this is currently not possible for PHP applications. If you want to pass environment variables to your PHP application contact the makandra operations team to configure it for you.

If your application expects configuration via environment variables you can place a /var/www/$deployment/shared/config/.env file which will be read by the deploy users .bashrc if present. The syntax must be in shell style like this:

# this is a comment and will be ignored
FOO_API_KEY=lahj3987yagxg
FACEBOOK=fb1UYGF1f7dJ # this comment will be ignored
TWITTER="BLCJKJSLU^T!#@&^LC"

Please mind that these environment variables will be loaded if you login with your user and from passenger (rails) processes but are not read by your cronjobs or elixir application by default! You need to prefix your cronjobs with source /var/www/$deployment/shared/config/.env && do_something or you should invoke your cronjob via bash bash -c 'do_something'. Your elixir application must be started via a bash shell.

Claus-Theodor Riegg
Last edit
Over 2 years ago
Marius Schuller
License
Source code in this card is licensed under the MIT License.
Posted by Claus-Theodor Riegg to opscomplete (2018-04-10 08:51)