[feature] different exec according to environment #10

Closed
florentvaldelievre opened this Issue Mar 12, 2015 · 7 comments

Projects

None yet

2 participants

@florentvaldelievre

Hi Mark,

At the moment, we only have one endpoint to exec something inside our container: common.yaml.
It would be nice to externalize this logic to have it per environment based.

Use case:

For production environment we need to launch td-agent to collect stats. It is not necessary to have it for development environment.
Currently, the only way to do it, is to have a script called launch.sh and to put the logic inside it.

Maybe it would be more versatile if we move the 'exec:' from common.yaml to environments/{env}.yaml.

Let me know what you think.

Cheers and keep up your good work

@markround
Owner

Code comitted to develop branch; this will be in the upcoming 0.5.0 release. You can override any of the settings in common.yaml by adding a common: block in your environment file, e.g.

common:
  api_enable: true
  exec: foo -n

and so on...

@florentvaldelievre

Amazing, good job !

@markround
Owner

Release 0.5.0 pushed. Note that this version now requires ruby >= 1.9.2. Let me know how it works out for you, if it's all good just close this issue :)

@florentvaldelievre

I must do something wrong, but it does not seem to take my environment sent as environment variable into account. Any idea ?

Update: It works by sending a plain environment variable docker run -it -e environment=development api-test but does not work using tiller_json

common.yaml

exec: echo "common exec"
data_sources:
  - file
  - environment_json
template_sources:
  - file
default_environment: default

environments/default.yaml

server.xml.erb:
  target: /var/lib/tomcat7/conf/server.xml
  config: {}
hibe-webapp-config.groovy.erb:
  target: /root/.grails/hibe-webapp-config.groovy
  config: {}
td-agent.conf.erb:
  target: /etc/td-agent/td-agent.conf
  config: {}

environments/development.yaml

common:
  exec: echo "overrided from dev"
docker run -it -e tiller_json='{"environment":"development"}' api-test

output

[shopmedia@staging3:/tmp/api] $docker run -it -e tiller_json='{"environment":"development"}' api-test
tiller v0.5.0 (https://github.com/markround/tiller) <github@markround.com>
Using configuration from /app/tiller
Using plugins from /var/lib/gems/2.1.0/gems/tiller-0.5.0/lib/tiller
Using environment default
Template sources loaded [FileTemplateSource]
Data sources loaded [FileDataSource, EnvironmentJsonDataSource]
Templates to build ["server.xml.erb", "hibe-webapp-config.groovy.erb", "td-agent.conf.erb"]
Warning, merging duplicate global values.
environment => 'default' being replaced by : 'development' from EnvironmentJsonDataSource
Building template server.xml.erb
Setting ownership/permissions on /var/lib/tomcat7/conf/server.xml
Building template hibe-webapp-config.groovy.erb
Setting ownership/permissions on /root/.grails/hibe-webapp-config.groovy
Building template td-agent.conf.erb
Setting ownership/permissions on /etc/td-agent/td-agent.conf
Template generation completed
Executing echo "common exec"...
Child process forked with PID 8.
common exec
Child process finished, Tiller is stopping.

@florentvaldelievre

It actually make sense we have to use -e environment={env} and not tiller_json. I close the issue, and thanks again!

@markround
Owner

Cool. Oh, and one other thing - as you're running a recent Tiller, you don't need the empty

config: {}

lines. You can just omit them, and it'll still work...

@florentvaldelievre

brillant thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment