Rails 5.2, master.key, capistrano deployment - ruby-on-rails-5

Upgraded from rails 5.1 to 5.2, and implemented credentials instead of secrets. Works great in development mode, works in production mode locally.
It’s got me foxed why when I deploy using capistrano to the server, it makes the symlink to master.key, but fails every time. The symlink file links back to correct master.key, and has the correct permissions.
I get this
02 ~/.rvm/bin/rvm 2.3.4 do bundle exec rake assets:precompile
02 rake aborted!
02 ActiveSupport::MessageEncryptor::InvalidMessage: Cannot load `Rails.application.database_configuration`:
02 ActiveSupport::MessageEncryptor::InvalidMessage
02 /www/mountain_penguins/shared/bundle/ruby/2.3.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt’
and further down
02 Caused by:
02 OpenSSL::Cipher::CipherError: key length too short
To me this looks like it’s not finding the master.key, but see no reason why. Any ideas?

I was having the same problem with a docker build on our CI, and discovered that my master.key file was empty.
In your capistrano deploy, see if you can cat out the master.key file contents, to see that if it is as you expect it to be. You might need a custom task for this, but hopefully it resolves your problem.

Related

How can I run oink in heroku?

I'm having a problem running the oink gem on my app in Heroku. I've included it in my gemfile and gemfile.lock, uploaded those, and it installs. It even creates the oink.log (which I have no way of viewing, unfortunately). When I run
heroku run bundle exec oink --threshold=0 log/* --app my_app
I get
Running bundle exec oink --threshold=0
log/delayed_job.log log/development.log log/oink.log log/production.log log/test.log attached to terminal... up, run.3
/app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:88:in get_file_listing':
Could not find "log/delayed_job.log" (RuntimeError)
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:86:ineach'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:86:in get_file_listing'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:59:inprocess'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/oink:4
from /app/.bundle/gems/ruby/1.8/bin/oink:19:in 'load'
from /app/.bundle/gems/ruby/1.8/bin/oink:19
I've tried running each of the individual files, too, and get the same result. This command runs fine on my local machine.
In my production.rb file, I have
config.logger = Hodel3000CompliantLogger.new(config.paths.log.first)
config.middleware.use( Oink::Middleware )
as configuration.
Can you enlighten me on what I'm doing wrong here? My understanding is that the logs are read only, but I don't know if that means they're only accessible through the heroku logs command. If there's a way I can see the oink.log file, too--knowing how to do that is also appreciated, or knowing how to see it in the actual Heroku log using heroku logs.
UPDATE: The configuration for oink shown above allows the commands to be run successfully on my localhost.
Thanks!
-Andrew

Rails Reporting Wrong Environment in Multi-stage Setup

Using capistrano 2.12.0, capistrano-ext 1.2.1, Rails 3.2.7 and Phusion Passenger 3.0.15.
For no logical reason, my 'playground' server has started reporting that it's actually running in development mode.
I've reinstalled things, restarted apache etc but am still stuck.
Don't really want to hardcode as I've got a production environment to think about.
In my apache conf. I've set
RailsEnv playground
There's a gist of my deploy.rb file here
Capistrano is sending to the correct location etc. so I think it's rails or passenger rather than cap.
What else can I do to get this going properly??
---- EDIT ----
I've just tested with Unicorn and it's also reporting that it's running in development mode.
Starting unicorn with the following:
unicorn -E playground -l 8000
After much experimentation, I found the root cause to be a line in one of my models:
- if Rails.env = 'development'
Obviously, this should have been a '==' not a single one.

LoadError: no such file to load -- rack/handler/glassfish

I have Successfully installed glassfish-1.0.3-universal-java, but when I run Rails Server using the command Jruby -S rails server glassfish. The output is follows:
f:\Program Files\BitNami JRubyStack\jruby\depot>Jruby -S rails s glassfish
Exiting
LoadError: no such file to load -- rack/handler/glassfish
require at org/jruby/RubyKernel.java:1033
try_require at F:/Program Files/BitNami JRubyStack/jruby/lib/ruby/gems/1.8/gem
s/rack-1.4.1/lib/rack/handler.rb:63
......
Any questions? Should I run Tomcat or Glassfish first?
You don't need to run rails server anymore, you just run glassfish.
f:\Program Files\BitNami JRubyStack\jruby\depot>glassfish
That will start up glassfish for your depot project. Check out their documentation for a little more information about this. That being said I think the glassfish project is kind of dying. From what I understand Oracle has killed glassfish (http://www.infoq.com/news/2010/04/glassfish-gem-alternatives-jruby). I would take a look at using Trinidad or Torquebox as alternatives.

Bundler::GemNotFound when compiling assets from cap deploy

I'm deploying to servers with capistrano and doing a bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile as the last step. Problem is when it gets to this point FROM cap deploy, i get the following error:
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/spec_set.rb:90:in `block in materialize': Could not find Platform-0.4.0 in any of the sources (Bundler::GemNotFound)
Platform-0.4.0 IS in fact on the server. And when i go into the server and run this exact command, all works great.
Couple of facts about my server: its using RVM, but that doesn't seem to be an issue with cap as the stack trace above would suggest. The other fact of interest is that this server was first created with a custom script I wrote that downloads an archived version of the git repo and then manually runs what cap does on a deploy. The reason I'm doing this, if anyone asks, is for automation with AWS AutoScaling. If i do a normal deploy:setup (not using my AWS script), it works fine with deployments. But the gem list is the same, and the site works all the same either way. Its just something with the cap deploy
Any thoughts?
I figured out what I was doing wrong. on my custom AMI scripts, i was naming the initial release folder 'first' when it should be a timestamp the way capistrano normally names it. That screwed things up on subsequent deployments.

How to display RoR app code version on heroku?

For my Rails apps I normally deploy to production from a tagged version, and then display the tag in the user interface assigning the output of git describe --always to a variable in config/application.rb.
Now I'm moving an app over to Heroku, and deployment to heroku only happens using the master branch, so this trick won't work any more.
Are there any other ways to assign a version number to my code and display it on the UI when I've deployed to heroku?
Thanks,
Stewart
You can add a variable to the Heroku configuration by running this command locally whenever you push new changes to Heroku:
heroku config:add GIT_TAG=`git describe --always`
Then you can access this in your app's configuration:
version = ENV['GIT_TAG'] || `git describe --always`
When the app is running on Heroku, it will pick up the config variable (ENV['GIT_TAG']) and when it's running locally in development it will fall back to running git describe --always.
You will need to update the Heroku config variable each time you deploy, but I generally add this kind of thing to a deploy script or rake task (along with useful things like creating a new tag marking the deploy and running any new database migrations on Heroku).
Doesn't git tag fit your needs?
And why wouldn't the old trick work anymore?
If you want to display it on the UI then a git SHA output probably isn't particularly useful - you have two options, set a Heroku config variable with a user friendly version number in or a set a version number in your code that you increment when you deploy from master. You could probably wrap the deploy up in a rake task that incremented the version number either a file (and then readded it to git and commits it) or simply increments a value in a config variable.
Also, don't forget Heroku release management http://blog.heroku.com/archives/2010/11/17/releases/ which you may also be able to employ here to get the version number from that perhaps.