Came across an issue when deploying a code change to our development environment via Jenkins. The Jenkins build gets stuck while running rake db:migrate on the following code in the initializer folder.
AMQP_URL_PATH = "#{AMQP_CONFIG[:protocol]}://#{AMQP_CONFIG[:user]}:#{Rails.application.secrets[:amqp_api_password]}##{AMQP_CONFIG[:host]}/#{AMQP_CONFIG[:virtual_host]}"
As you can see it is trying to access two yaml files amqp.yml and secrets.yml. I can confirm both files exist on the dev box within the config folder.
local the code produces the following good url
amqps://user:password#10.118.1.134/virtualhost
development the code only returns ://:#
The Jenkin's build error is this.
15:59:21 URI::InvalidURIError: bad URI(is not URI?): ://:#
As you can see none of the interpolated values are making it to the url string when this is running in Jenkins. This is the only change that has occurred in this push and if I hard code the path the build works perfectly. How do I get Jenkins to access these YAML files when running rake tasks during the build deployment?
Development:
Rails 4.2.5
Ruby 2.2.2
Local:
Rails 4.2.5
Ruby 2.2.3
Related
I have a regular Rails project that is up and running fine, using Rails 5.1.3.
I recently discovered Rails runner and tried it along the documentation (https://guides.rubyonrails.org/command_line.html#rails-runner).
However, my Rails runner seems to be incapable of coping with files. I have a file lib/manual_exports/my_export.rb, and it really exists. I tried running
rails runner lib/manual_exports/my_export.rb
and
rails runner ./lib/manual_exports/my_export.rb
I always get the response
Please specify a valid ruby command or the path of a script to run.
Run 'bin/rails runner -h' for help.
undefined local variable or method `lib' for #<Rails::Command::RunnerCommand:0x00007fb13008b310>
# (or `.' instead of `lib')
This sounds as if runner thought my path was a Ruby command, which shouldn't be the case.
When I try reading in the file directly like
rails runner "eval(File.read 'lib/manual_exports/my_export.rb')"
or
rails runner "eval(File.read '#{Rails.root}/lib/manual_exports/my_export.rb')"
I get no answer at all, until I press ctrl+C, which gives me the stack trace
/Users/marion/.rvm/gems/ruby-2.4.2/gems/railties-5.1.3/lib/rails/commands/runner/runner_command.rb:37:in `read': No such file or directory # rb_sysopen - lib/manual_exports/my_export.rb (Errno::ENOENT)
I tried running a command directly (rails runner 'puts "hi"'), which worked. However, it took incredibly long - about two seconds. Can anybody explain to me what is happening here? Thank you!
Im using Settingslogic gem as alternative to Environment Variables, and I found it more convenient. But, how to deploy the application to Heroku if my file with configs is out of the repo? I mean, all configs I save in application.yml, which is included in .gitignore file (because there is sensitive data). And when I push it to heroku, server can't find this file and can't complete deploy.
I've tried to create the file from heroku bash, but after git push heroku master command, created file disappears, and deploy failes with the same error.
How can I implement this deploy with one config file, and how can I force heroku to read this file or store it if I have no it in Git? Thanks a lot!
My Travis tests for a Rails app have been working fine, but have suddenly started failing about one time in three with:
$ bundle exec rails test
FATAL: Listen error: unable to monitor directories for changes.
Visit
https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
for info on how to fix this.
Looking at that suggested URL, it proposes ways to increase the number of inotify-watchers, but requires the use of sudo to change the limit. That's fine on my dev machine (though I'm actually not experiencing the error on my machine), but I don't know if that's possible (or advisable) in the Travis environment.
I looked at the Travis docs to see if there's a config setting for increasing the number of watchers, but I couldn't find anything.
So: what's the best way to deal with this error in a Travis CI test?
If you're running this on TravisCI and a CI/staging/testing server, you should not need to watch files for changes. The code should be deployed to the server, and then bundle exec rails test should run and that's it. No file watching necessary.
What I suspect is that the config for your environment is not set up correctly and that listen gem is somehow activated for the testing environment when it should only be activated for the development environment.
Try running the tests locally with the same environment as TravisCI (testing in this example):
RAILS_ENV=testing bundle exec test
and see what it says. If it gives you that error, check the config/environments/testing.rb file and look for config.cache_classes.
When config.cache_classes is set to true, the classes are cached and the listen/file-watcher will not be active. In your local development environment, config/environments/development.rb, the config.cache_classes setting should be set to false so that file-watching and reloading happens.
I'm getting the following error while deploying my rails app to an ubuntu server, I have correctly setup ssh keys and I can ssh to the server but I'm getting the following when I try to do
cap production deploy
This is the error message
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxxxxx.xxxxxxx.xxx: agent could not sign data with requested identity
I can't figure out what I am doing wrong since I had previously deployed and I just need to update my app to changes I have made. I have not changed my deploy.rb, Capfile or deploy/production.rb files since I last deployed
I solved a similar issue by just issuing ssh-add. It seems that my current environment hasn't properly picked up the keys and readding them fixed the issue.
I had the same error.
ssh-copy-id user#ipaddress
Helped me to solve this.
I had the same issue but in my case I had to delete file .ssh/known_hosts from my local machine.
After upgrading Rails from 4.1.x to 4.2, I started getting similar errors when trying to bundle. I fixed it by removing the shared bundle directory. Here's the steps I took:
SHH into the server
cd /my/app/shared/bundle/ruby
rm -rf 2.1.0 or whatever "version" directory is there
Re run the deploy cap production deploy
You may, at this point, hit a memory snag (I did while deploying to a DigitalOcean droplet). The fix for that is to create and enable a swap file on the droplet.
I have a Rails 4 application hosted by Heroku.
Seeing as I'm working on an open-source project, there are several unversioned files containing sensitive information listed in .gitignore. For example, I have a .secret file at the root of the app that contains the key with which cookies are encrypted. I created this file by running the rake secret command.
My problem is that I cannot send this file to my heroku app since it is not versioned, it is not included in the deployment. Furthermore, I am using Github and cannot risk having my key disclosed publicly in the commit history.
I have attempted to use the heroku run command to create the file (heroku run 'rake secret > .secret' to no avail). I have attempted to connect with the terminal using heroku run bash but as the filesystem is ephemeral, my changes are not preserved when I exit the terminal.
Do you have any idea how I could achieve having unversioned files on a Heroku application?
Secret data (keys, passwords, etc) should be stored as config vars on Heroku. They are then accessed via the ENV hash in your code.
If you use something like figaro, you can place these vars in an application.yml (don't commit the file)
application.yml:
SECRET_KEY: my_secret_key
Figaro then has a rake task to push these to heroku:
rake figaro:heroku
Or, you can manually set them:
heroku config:set SECRET_KEY=my_secret_key
Finally, access them in your app as:
ENV['SECRET_KEY']