Install Adva-CMS on Heroku
Adva CMS is the Latest of the Rails based CMS on the Scene and it is a real cool deal. Extremely easy to use with an easy interface, easily extendible, it harnesses the power of Rails engines. I wanted to Install it on Heroku once I finished making the site on my local system. Here is what followed.Note that this article assumes that we have an up and running Adva CMS app.
Sign Up for an Account on Heroku. Prepare Heroku local environment. They have done some amazing Documentation
sudo gem install heroku
Now goto the application directory and start a new application in heroku and add the remote
heroku create adva-trial
Created http://adva-trial.heroku.com/ | git@heroku.com:adva-trial.git
git remote add heroku git@heroku.com:adva-trial.git
I ran into four kinds of Problems
- Heroku is a Read Only File System,so no uploads, which makes Photo Gallery Useless at least for me because my application was not a huge one
- Heroku does not Identify git submodules
- Symlinks Do not go into commits out of the box
- Migrations Wont run because they were inside the engines and heroku only recognises db/migration in the main app while running the rake:migrate.
Now,the solution to First Problem came easily. I placed all the images in public/photos inside my adva-cms application and made images the part of the commit. That however is not very advisable because in Heroku each slug or a slot assigned to us is 20 MB and image takes a lot of it. They advise to keep it below 10 MB to get the best performance.
I Checked out heroku docs at Heroku Contraints Section where they have mentioned the First two problems and their work arounds. As mentioned there, the soution to the second problem was easy.
$ cd adva-trial
$ find . -mindepth 2 -name .git
git$ rm -rf `find . -mindepth 2 -name .git`
$ git add .
$ git commit -m "brought submodules into the main repo"
This workaround brings the git submodules into the main repository.Then, once you push your next commit, you will have engines in your repository.
The Final problem was the most annoying, because most of the things worked but not the JS and the css did not appear despite being present in the slug. The point is git sometimes ignores the symlinks in the commits. So I googled and found a workaround to that, which was a bit cumbersome but that was the only solution that made it work properly.
$ git add symlink/
$ git commit -m "Added Symlinks"
Make sure you tab the symlink name and add each symlink separately. This is what makes it pretty cumbersome.Finally add a .gems file in the mail application directory in this format and Push the changes to heroku.
$ nano .gems
nokogiri --version 1.3.2
$ git push heroku master
Solution to 4th Problem was provided by Casper on the Adva-CMS and Heroku mailing list.I added a rake task and ran it.It basically Copies all the migrations from engine to db/migrations folder.This also i must warn is not a very good practice, but it is an essential work around. Maybe we should clean the directory once done.
saurabh@laptop:~/adva/adva/lib/tasks$ cat adva.rake
Rake::Task["db:migrate"].clear_actions
namespace :db do
task :migrate do
Rake::Task["db:migrate:original_migrate"].invoke
end
desc "Copy Adva migrations from plugins to db/migrate"
task :copy_adva => :environment do
target = "#{Rails.root}/db/migrate/"dirs = Rails.plugins.values.map(&:directory)
files = Dir["{#{dirs.join(',')}}/db/migrate/*.rb"]unless files.empty?
FileUtils.mkdir_p target
FileUtils.cp files, target
puts "copied #{files.size} migrations to db/migrate"end
end
end
$ rake db:copy_adva
$ git add .
$ git commit -m "add migrations"
$ git push heroku master
$ heroku rake db:migrate
Now Browse to your application URL and you have it deployed !