I am doing some Clojure pet project. I have some profiles like the following
{:test {:env {:database-name "library_test",
:host-name "192.168.33.10"
:username "library_admin"
:password ""
:dbtype "postgres"
:driver-class-name "org.postgresql.Driver"}},
:dev {:env {:database-name "library",
:host-name "192.168.33.10"
:username "library_admin"
:password ""
:dbtype "postgres"
:driver-class-name "org.postgresql.Driver"}},
:travis {:env {:database-name "test_library_test",
:host-name "localhost"
:username "test_user"
:password "password"
:dbtype "postgres"
:driver-class-name "org.postgresql.Driver"}}}
Now I am trying to setup Travis-CI for the project. I want to override the value of test profile CI while running test, for that I am using the following command
lein with-profile travis test
Here lein is activating the travis profile but it's picking up the environment variables value from test profile instead of travis profile.
Did anyone face such issues?
Why: Lein merges test profile by default. You can see the effective project map with lein with-profile travis,test pprint
Solution: I assume you're using environ or something like that. If so, you can export values with env in UPCASE_WITH_UNDERSCORE (e.g. DATABASE_NAME=test_library_test) and they will override values in profiles
Related
The https://github.com/yogthos/config approach let's you lay out per-profile env variables in separate files, like the below , in a project.clj .
Per the below, one can use lein with-profile prod uberjar or lein with-profile dev repl and the like.
But my issue is I have been unable to figure out how to place some common values into a shared area, accessible by dev, stage, prod profiles.
Basic example
(defproject edn-config-test "0.1.0-SNAPSHOT"
...
:profiles {:shared {:resource-paths ["config/shared"]}
:dev {:resource-paths ["config/dev"]}
:stage {:resource-paths ["config/stage"]}
:prod {:resource-paths ["config/prod"]}}
...
(with files)
config/shared/config.edn
config/dev/config.edn
config/stage/config.edn
config/prod/config.edn
I tried this without luck
lein with-profile shared,prod lein , borrowing from the composite approach in
https://github.com/technomancy/leiningen/blob/stable/doc/PROFILES.md#composite-profiles
When I do that, I only get variables in prod profile, for example.
I think it is a limitation of config. I tried this (more explicit):
:profiles {:dev {:resource-paths ["config/shared" "config/dev"]}
:prod {:resource-paths [ "config/prod" "config/shared"]}}
However, the last file wins and the first is ignored. So for :dev the shared stuff is ignored, and for :prod the prod stuff is ignored (like it doesn't exist):
config/dev/config.edn => {:special-val :dev-val}
config/prod/config.edn => {:special-val :prod-val}
cat config/shared/config.edn => {:shared-val 42}
and results:
> lein with-profile prod run
(:shared-val env) => 42
(:special-val env) => nil
> lein with-profile dev run
(:shared-val env) => nil
(:special-val env) => :dev-val
Perhaps you'd like to submit an enhancement PR to the project?
Here is the problem. It uses io/resource to read config.edn, which implicitly expects there to be only one file config.edn anywhere on the classpath:
(defn- read-config-file [f]
(try
(when-let [url (io/resource f)]
(with-open [r (-> url io/reader PushbackReader.)]
(edn/read r))) ...
(read-config-file "config.edn")
So you'd have to get away from the hard-coded filename config.edn, and make something like config-dev.edn, config-prod.edn, and config-shared.edn. At least then they could all live in a single ./resources dir.
I'm forwarding riemann events by code below in riemann.config:
(def influxdb-creds {
:version :0.9
:host "127.0.0.1"
:port 8086
:db "riemann"
; :username "riemann"
; :password "riemann_password"
})
(def influxBatchSender
(batch 100 1/10
(async-queue! :agg {:queue-size 1000
:core-pool-size 1
:max-pool-size 4
:keep-alive-time 60000}
(influxdb influxdb-creds))))
In my environment I need to use curl --noproxy '*' to access influxdb, how I can code it in my riemann.config?
http_proxy and https_proxy environment variables responsible for this.
Make sure there are no http_proxy and https_proxy variables in your environment.
Right now I'm trying to deploy my Ruby on Rails app to a Virtual Machine on Windows Azure running Ubuntu but I can fix de set environment variables error as below describe.
I have done added variables to my .bashrc and now in /etc/environment but the error is the same:
App 1227 stderr: [ 2015-10-06 04:10:57.3814 1352/0x9020d38(Worker 1) utils.rb:86 ]: *** Exception RuntimeError in Rack application object (Missing `secret_to$
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:534:in `validate_secret_$
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:246:in `env_config'
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:514:in `call'
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:165:in `call'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:151:in `accept_and_process_next_request'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:112:in `main_loop'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:112:in `block in create_thread_and_abort_on_exception'
[ 2015-10-06 04:10:57.3819 988/b5efeb40 age/Cor/Req/Utils.cpp:95 ]: [Client 1-1] Sending 502 response: application did not send a complete response
This is my sudo nano /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
export SECRET_KEY_BASE=2da0d3f0bfd7b9b05110bfad512f42df2d2bb2ef715c4e831caba96a9c0b2141fbfa718dff2f5daf916cd70a70afd1f24df49884c561fbbaf364b36652b2c7d1
ruby -e 'p ENV["SECRET_KEY_BASE"]'
export MATCH_PEOPLE_DATABASE_PASSWORD=2015deployer
ruby -e 'p ENV["MATCH_PEOPLE_DATABASE_PASSWORD"]'
And when I run echo $SECRET_KEY_BASE or echo $MATCH_PEOPLE_DATABASE_PASSWORD I got the exact data.
deploy#vmw-ubuserver:~$ echo $SECRET_KEY_BASE
2da0d3f0bfd7b9b05110bfad512f42df2d2bb2ef715c4e831caba96a9c0b2141fbfa718dff2f5daf916cd70a70afd1f24df49884c561fbbaf364b36652b2c7d1
deploy#vmw-ubuserver:~$ echo $MATCH_PEOPLE_DATABASE_PASSWORD
2015deployer
But I still getting the same error in production, I'm using RVM, Capistrano, Passenger and NGINX on Ubuntu 14.04.
My database.yml :
production:
adapter: mysql2
encoding: utf8
pool: 5
host: localhost
database: matchpeople_production
username: deployer
password: <%= ENV['MATCH_PEOPLE_DATABASE_PASSWORD'] %>
My secrets.yml :
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_token: <%= ENV["SECRET_KEY_BASE"] %>
Any kind of help?
Looking and looking for the correct answer I have been trying too many options but I didn't make it works fine.
So, suddenly I found I solution while I was testing some configurations found on google.
It is simple, just:
Add the next lines:
export SECRET_KEY_BASE=3aa7e349bh345h245hi23452345h234ih52i3u45h$
export MATCH_PEOPLE_DATABASE_PASSWORD=your_pass_here
# Uncomment these lines and restart the server to validate if the variables are read correctly
#ruby -e 'p ENV["SECRET_KEY_BASE"]'
#ruby -e 'p ENV["MATCH_PEOPLE_DATABASE_PASSWORD"]'
At the end of the files below:
sudo nano ~/.bash_profile
sudo nano /etc/environment
If you want you can uncomment the last two lines in ~/.bash_profile and restart your server and when you login to it again, you will see the value of the ENVIRONMENT VARIABLES before your promt as in the picture below.
I recommend you to keep those lines commented do it just for validate and then comment them again.
If you have any question, please leave a comment!
Hope it could be useful.
From my experience, there is no secret_token needed in secrets.yml for Ruby RVM.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
I think to solve the problem, remove the second line from your production: section
In case you need to add environment variables to RVM, edit
# /etc/profile.d/appspecific.sh
add something like
export GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p551:/usr/local/rvm/gems/ruby-1.9.3-p551#global
export GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p551
Good luck!
I am trying to get my ENV variables in production mode ...
but now way .. cannot reach the server ... the SECRET_KEY_BASE is not found ... if I hardcode it , then go trouble w the database creds, and if I hardcode them, got trouble w the SMTP creds...
this means that no ENV[] variables cannot be reached ...
I added the gemfile to get it in :production environment, and bundled it
gem 'dotenv-rails', :groups => [:development, :test, :staging, :production]
my .env file is present in my remote server ( Ubuntu 14 - w .rbenv Ruby 2.0 , Rais 4.2 )
cat /var/www/workshop/shared/.env
SECRET_KEY_BASE=106063d5146566142b6aa4782b874115c73a61ac2505f11f8e
DATABASE_USER_NAME=myself
DATABASE_PASSWORD=mydbpwd
MAILGUN_SMTP_SERVER=smtp.mailgun.org
MAILGUN_SMTP_USER_NAME=postmaster#mydomain.com
MAILGUN_SMTP_PASSWORD=2fc998a7399999999a264b88c
MAILGUN_SMTP_DOMAIN=mydomain.com
I set my secrets.yml file on the remote server
cat secrets.yml
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
I set my database.yml
cat database.yml
production:
adapter: postgresql
database: workshop
encoding: unicode
pool: 5
username: <%= ENV['DATABASE_USER_NAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
and I updated my config/environments/production.rb w smtp creds
cat production.rb
.....
# SMTP settings for mailgun
config.action_mailer.smtp_settings = {
:port => 587,
:address => ENV['MAILGUN_SMTP_SERVER'],
:user_name => ENV['MAILGUN_SMTP_USER_NAME'],
:password => ENV['MAILGUN_SMTP_PASSWORD'],
:domain => ENV['MAILGUN_SMTP_DOMAIN'],
:authentication => :plain,
:enable_starttls_auto => true
}
...
Finally I gave up w .dotenv in production...
I resolved using Rails 4.1 secrets.yml...
as I am deploying w capistrano 3 ,
- I use the gem capistrano-upload-config
- I created : secrets.production.yml , database.production.yml, configuration.production.yml
- I added in my capistrano deploy.rb
set :config_files, %w{config/database.yml config/secrets.yml config/application.yml}
set :linked_files, %w{config/database.yml config/secrets.yml config/application.yml}
capistrano uploads these productions files from the local .production files and link them... so
the server database.yml is loaded/linked (from local database.production.yml)
the server secrets.yml is loaded/linked (from local secrets.production.yml)
the server application.yml is loaded/linked (from local application.production.yml)
regarding the production.rb SMTP settings , I use the secrets file :
:address => Rails.application.secrets.mailgun_smtp_server,
...
all these files are in .gitignore
I'm trying to give Blackfire.io (by Sensiolabs) a try to profile an existing PHP application running on a Vagrant machine (with PHP 5.3) on Mac.
I'm using Chef to provision my machine with Blackfire, but when running "vagrant provision" I get the following error:
default: STDERR: The server ID parameter is not set. Please run
blackfire-agent -register to configure it.
..which I already did
This is my Vagrant file:
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Vagrant.configure("2") do |config|
..
config.vm.box = "covex/ubuntu1204-x64"
config.omnibus.chef_version = :latest
config.vm.provision "chef_solo" do |chef|
chef.json = {
:blackfire => {
:'server-id' => "d4860b49-be67-404b-9fa1-b..",
:'server-token' => "c412751f30d6c724033d8408e.."
}
}
chef.add_recipe "blackfire"
end
end
I followed the installation steps on https://blackfire.io/getting-started, except for the Probe paragraph.
Is my Vagrant file wrongly configured, so it can't read the server ID and token? Is the "brew install blackfire-php53" needed for this, if so, is there a way to configure this through my Vagrant file?
Guessing you are using https://supermarket.chef.io/cookbooks/blackfire
You missed the agent node in the config tree
{
"blackfire" => {
"agent" => {
"server-id" => "your server-id",
"server-token" => "your server-token",
}
}
}