Home > Blockchain >  Problem deploying Ruby on Rails 7 app on Heroku
Problem deploying Ruby on Rails 7 app on Heroku

Time:08-19

I am trying to deploy my project to Heroku and I have this error:

Running: rake assets:precompile rake aborted! SyntaxError: /tmp/build_c99702b3/config/environments/production.rb:22: syntax error, unexpected constant, expecting 'do' or '{' or '(' ...oku config:set RAILS_MASTER_KEY=ENV['RAILS_MASTER_KEY']

Although I have seen very similar errors and problems described here, nothing is working for me. I have credentials.yml.enc file and master.key file. Everything is working fine on localhost:3000,but when I try to deploy it I received this error. I am running VMWare VM Ubuntu 22.04 LTS (although I have run it as well on 20.04 LTS) on Windows 10 machine. Here is my Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.1'
gem 'rails', '~> 7.0.3'
gem 'sprockets-rails'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'importmap-rails'
gem 'turbo-rails'
gem 'stimulus-rails'
gem 'tailwindcss-rails'
gem 'jbuilder'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'bootsnap', require: false
gem 'devise', '~> 4.7'
gem 'finnhub_ruby', '~> 1.1.16'
gem 'dotenv-rails', groups: %i[development test]
group :development, :test do
    gem 'debug', platforms: %i[mri mingw x64_mingw]
    %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
      gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
    end
end

group :development do
    gem 'web-console'
end

I also try to use .env file and had my master key defined there as well like this:

ENV['RAILS_MASTER_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx'

but it did not help as well.

Could you, please, let me know what is the problem and if somebody could provide detailed instructions on how to do this, I mean especially where and how the master key has to be placed, so it could deploy to Heroku? Thanks in advance for your answers.

CodePudding user response:

heroku config:set is CLI command, you don't need to put this line to your production.rb

If you need to set this env variable to Heroku just execute in your terminal after heroku create command and before deploy

heroku config:set RAILS_MASTER_KEY=`cat config/master.key`

or

heroku config:set RAILS_MASTER_KEY="$(< config/master.key)"
  • Related