Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How in grails yml config access to environment variables?

I want to use Openshift to host my Grails application, and setup MySQL database on Openshift.

Openshift provide only login and password for database, but connection string is in form of environment variables OPENSHIFT_MYSQL_DB_HOST:OPENSHIFT_MYSQL_DB_PORT and I do not see what is actual values for this vars for my database. Now I need to setup my YML config to access database, but I need somehow access from YML to environment variables OPENSHIFT_MYSQL*.

How can I do it?

like image 344
sphinks Avatar asked Jun 03 '15 10:06

sphinks


People also ask

How do I set environment variables in Grails?

Download the latest Grails releasePATH under 'System variables' and GRAILS_HOME under 'User variables') Type "grails" at the command line, if a help message is displayed you are ready to start using Grails! If you get an error message, try to chmod +x the grails script inside the bin directory.

Can Yaml read environment variable?

PY-yaml library doesn't resolve environment variables by default. You need to define an implicit resolver that will find the regex that defines an environment variable and execute a function to resolve it. You can do it through yaml.

How do I access .ENV values?

To retrieve environment variables in Node. JS you can use process. env. VARIABLE_NAME, but don't forget that assigning a property on process.

What is config ENV?

You configure your environment by setting environment variables and creating or modifying files that relate to the environment variables. You can control whether environment variables are set at the environment level, for a specific user, or for a database session.


1 Answers

You reference the system environment variable with the name MYVAR via ${MYVAR} in your yaml file.

The values in application.properties are filtered through the existing Environment when they are used, so you can refer back to previously defined values (for example, from System properties).

app.name=MyApp app.description=${app.name} is a Spring Boot application

See http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-placeholders-in-properties

like image 51
cfrick Avatar answered Oct 04 '22 03:10

cfrick