how can i manually set GrailsUtil.environment variable in Bootstrap.groovy - grails

At the time bootstrap.groovy is running GrailsUtil.environment is automatically switch to development.
Can any one explain,How can i manually change that variable before bootstrap starts..??
Where it is setting as default to development in grails framework..??
Thanks.

Your grails environment is specified on the command line when you type run-app, for example. I don't believe you can switch the environment setting within Bootstrap.groovy--or any file--at runtime. Instead, you can change it by how you execute the grails commands:
-Dgrails.env=production run-app-- you can create your own environments to run, just change the value for -Dgrails.env to your custom environment.
Some of the grails tasks will run in a given environment by default; you don't need to set it explicitly.
run-app -- defaults to run in the development environment
test-app -- defaults to test environment
war -- defaults to production environment
More info here: http://www.grails.org/Environments

Related

Node-config custom-environment-variables not Picking Docker environment Variables

Working on Windows OS.
My node app using node-config isn't using docker environment variables. It's always using the default config.
I am using node-config custom environment variables as described here: https://github.com/lorenwest/node-config/wiki/Environment-Variables#custom-environment-variables
Everything is working well when running the app locally. The config by passes the default ones and takes the ones defined in my User variables when set.
Problem
I start a docker instance with all required Environment variables
set.
I verify the env variables by running docker exec container_name env
However, the node app still uses the default config, instead of the environment variables.
I am not sure what setup I may be missing.
I'm a maintainer of node-config. I don't test with Docker or Heroku, but this most be an ordering problem. As long as the environment variables are set before require('config') happens, they will work-- at that point Docker or Heroku doesn't matter. The activity is happening inside the Node.js JavaScript engine at that point.
Try this simple test: Just before your line where you require('config'), use console.log or an equivalent to print out the environment variables that you care about. I expect you'll find that when it's not working it's because the environment variables are not set before node-config is loaded.

Grails change Environment from Development to Test

Is there any way to change current environment from DEVELOPMENT to TEST?
I have tried,
if(Environment.getCurrent().equals(Environment.DEVELOPMENT)){
Environment.currentEnvironment = Environment.TEST
println("Current Environment : "+Environment.getCurrent())
}
But it is showing error like :
Error There was an error loading the BuildConfig: Cannot set readonly property: currentEnvironment for class: grails.util.Environment
How can I change this ENVIRONMENT property?
I need to change my development environment into TEST for some AES encryption algorithms, as it is not working in Development environment.
Now am using grails test run-app command for running app in test environment, How can I fix it in TEST environment permanently?

How to undefine an environment variable in ant

I am running Ant to exec another process. This other process has problems with some environment variables that are present. I want these environment variables to be undefined when I exec the other process.
Of course I can undefine the environment variable prior to running Ant. However I am interested in undefining the variable within Ant prior to execing the other process.
So I have at the time of calling Ant an environment with:
SOME_VAR=a-value
And I have in my build.xml:
..<exec exacutable="program.exe>...
And my program.exe chokes on the fact that SOME_VAR is defined.
The exec task has a newenvironment attribute which when set to true clears the current environment. Use together with nested env elements.

Customise behaviour of a Grails environment

I was wanting to run a custom environment called "local"...as in a local dev. I would use the config (eg DB connections) of this before a war would be deployed to the "shared" development server. But I noticed that it lacks the behavior of the standard Grails "development" Environment, such as Changes to a GSP were not available when you refresh the browser.
So this led me to wonder how do you change the behaviours of a custom environment? How can you copy all the settings for "development" to another environment?
You can enable reloading of modified gsp in a custom environment specifying the run-app flag:
-Dgrails.gsp.enable.reload=true
I don't think the automatic reloading is environment dependent. If you execute grails run-app, reloading will happen regardless of which environment you run under. In other words, automatic reloading will happen for all of
grails dev run-app
grails prod run-app
grails test run-app
On the other hand, reloading will not happen if you build a war using grails war, then deploy it. So reloading depends on how you run the app, not the environment. The easiest way to define a custom environment that is similar to dev, is to define a set of default configuration, then selectively override the settings for each environemnt, e.g.
//default config
myApp {
userRoleName = 'ROLE_USER'
adminRoleName = 'ROLE_ADMIN'
dateFormat = 'yyyy-MM-dd'
}
environments {
// config overrides for dev
development {
myApp.dateFormat = 'yyyy/MM/dd'
}
// config overrides for local
local {
myApp.dateFormat = 'MM/yy/dd'
}
}

Grails environments

I couldn't find an answer in the documentation so I'm asking here.
In Grails when you create an app you get the Production, Development etc environments by default.
If you want to build a WAR for Production you can run either of these commands:
grails war
OR
grails -Dgrails.env=prod war
If you want to create a WAR for the development environment you use the command:
grails -Dgrails.env=dev war
My questions;
1) Can I use the word 'production' instead of 'prod' and use 'development' instead of 'dev'? I assume that 'prod' and 'dev' are just shorthand for 'production' and 'development', so I should be able to use either?
2) If so, if I introduce my own environment called 'Stage' can I create a shorthand for use in setting -Dgrails.env? Something like 'stg' for example.
Thanks.
1) Can I use the word 'production' instead of 'prod' and use 'development' instead of 'dev'? I assume that 'prod' and 'dev' are just shorthand for 'production' and 'development', so I should be able to use either?
The short answer is yes. You can use either the short name or full name of an environment to the grails.env parameter. The short and full names of the environments defined by Grails are shown below
short name|full name
prod |PRODUCTION
dev |DEVELOPMENT
test |TEST
The value provided for grails.env is matched case-insensitively against the short and full name of all environments.
2) If so, if I introduce my own
environment called 'Stage' can I
create a shorthand for use in setting
-Dgrails.env? Something like 'stg' for example.
No, the short names are stored within a private static field of grails.util.Environment, which you should not access

Resources