I have a directory structure like the following:
my-app/
.git/
db/ <-- Database stuff
lib/ <-- Business logic
spec/
web/ <-- Rails
Rails is in the web/ subdirectory of the repository. Heroku doesn't like this by default.
I have a partially working heroku buildpack. It basically calls Dir.chdir to change into the APP_SUBDIR environment variable (if it exists) before running any tasks.
I'd like to deploy to Heroku, but I can't get the asset pipeline task to work. When it comes time to precompile assets, the customized buildpack changes to the web/ directory and attempts to run the task.
However, I get this error, with the following important bit:
Could not detect rake tasks
ensure you can run `$ bundle exec rake -P` against your app with no environment variables present
and using the production group of your Gemfile.
Your Ruby version is 1.9.2, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
Which is weird since Heroku clearly says I'm running 2.0 in that very same pastie. In fact, when I run:
$ heroku run 'cd web; bundle exec rake -P'
it work just fine.
TL;DR (Summary)
Heroku thinks my ruby version is 1.9.2 when it's really the 2.0.0 shown in its own build process. Why might this be?
You can push only the subdirectory the Rails app lives in to Heroku:
git subtree push --prefix web heroku master
Where web is the subdirectory.
Related
I have deployed a rails application using capistrano on a linux server and it is running without any problems. When I connect to my remote server via ssh, the folder structure of my app is quite different from what I have on my local machine. I would like to go to project root and say rails console so that I can have access to the console of my application. Is there a way to achieve this?
When I go to ~MyApp/ folder and run rails console it says command rails not found. I think that is probably because the app is running in another folder.
bundle exec to the rescue inside of project folded:
$ RAILS_ENV=production bundle exec rails console
If you've installed with rbenv it could be that you are defaulting to the wrong Ruby version. So you can run rbenv exec to get it to run on the right version, along with bundle exec to run the right version of Rails
So try running this:
rbenv exec bundle exec rails console
To sum up for anyone having the same problem in the future,
I went to MyApp/releases/2020331231231231 which is the latest release of my app and there I used this command RAILS_ENV=production bundle exec rails console and I was able to do whatever I wanted to do in the console.
First you need to move inside the folder where the code is.
Check Capistrano config if deploy_to is defined. (If it's not it should be set to /var/www/#{application}/ by default read here)
Since Capistrano keep older versions of your app go to the current folder which is a symlink of the latest deployed version.
And run ENVIRONMENT=production bundle exec rails c or ENVIRONMENT=production bin/rails c. If doesn't work try with rbenv ENVIRONMENT=production rbenv exec bundle exec rails c
I´m having trouble to access the rails console in production.
I used Capistranoto deploy the app to a VPS
If I cd to deploy#myapp:~/myapp/current$and run bundle exec rails cthere I always get the option list for creating new rails project, like rails new
I've also tried bundle exec rails console --productionand rails consoleetc all with the same outcome.
the thing is I must be able to access the console because I have to create an admin user for active admin
might be worth adding that I'm using Passenger/Capistrano and Nginx on Ubuntu 16
Does anyone know what is going on here? Am I doing something wrong?
*EDIT
After running RAILS_ENV=production bundle exec rails c I get this message
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
like any other source code, rather than stubs that are generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
Loading production environment (Rails 4.2.5)
irb(main):001:0>
You are missing executable files of bin folder in Production after Capistrano deployment.
You need to remove bin from set :linked_dirs from your Capistrano deploy.rb in order to avoid symlinking it.
You can again try cap production deploy, it would take all the executable files from bin to Production.
Now, you can access the rails console using:
RAILS_ENV=production bundle exec rails c
If you are using Capistrano 3, you can include the rails:console option which will allow you to do this from your local machine to gain access to the console on the remote host:
bundle exec cap production rails:console
https://rubygems.org/gems/capistrano-rails-console
The Rails project is deployed in /deploy/your_project_name/current on the server by default. So, you can access it via SSH or ... and run bundle exec rails c to access the Rails console. It works for me!
check if rvm and regarding gemset is suitable for the app
rvm gemset list
rvm list
and then do
bin/rails rails c -e production
I am trying to upload RoR application to Heroku.
OS - Ubuntu, ruby version - 2.2.2p95, rails version - 4.2.1, database - PostgreSQL, installed RoR via BrightBox (Tutorial from treehouse), using git push heroku master to upload.
On the local server app works fine. When I push it to heroku, it gives out an error:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
Log files say:
/usr/bin/env: ruby2.2: No such file or directory
I've tried all the possible variants, I could find on the Internet:
rake rails:update:bin
Remove bin from ~/.gitignore (But there is no such file)
heroku config:set PATH=bin:vendor/bundle/ruby/2.2.2/bin:/usr/local/bin:/usr/bin:/bin
Adding this to the GemFile: ruby '2.2.2'
Changed #!/usr/bin/env ruby2.2(.2 (not sure about ".2")) to #!/usr/bin/env ruby (in bin/rake, bin/bundle and bin/rails)
heroku run rails db:migrate
rake rails:update:bin
ln -s /usr/bin/nodejs /usr/bin/node
To upload to heroku, I've configured git, after that logged in heroku, after that "heroku create", after that "git push heroku master", then "heroku open"
And many others... Any ideas how to solve that problem?
Do you have the gem rails12_factor installed and config.assets.compile = true ?
Not sure you mistyped or something else. but heroku run rails db:migrate will not work it should be heroku run rake db:migrate . It might be because you don't have root page. Precompile issue etc.
Run heroku logs -a app_name to see actual logs.
I am new to ruby and I want to learn more about how it works. So I have been testing a server configuration in a virtual machine to make quick Rails deployments.
I have RVM, Ruby, Rails, Git, Gitolite, PostgreSQL, Thin and Nginx running in an Ubuntu 10.04 environment.
Now I want to tie everything together. I got stuck, though, in the deployment process.
After I commit the project to the Git trunk, I want to hook a deployment action to put the application in the correct place, set to production, install the bundles, make the migrations and restart Nginx.
But I fail to find simple references on how it works. All I find in google are guides to use passenger, capistrano and others. I want to trigger the deployment on the git commit action, similar to heroku, but what would be the best tools to do that 100% server-side?
What about making some shell scripts? How do I deploy a project manually? What are the steps? Are there any guides out there that do not assume I know every details in Rails deployment?
Thanks!
The think you are probably looking for is a git post-receive hook (a tutorial could be found here: http://toroid.org/ams/git-website-howto).
By this hook you should trigger eg. a shell script which should perform all the steps you need - which are:
checkout HEAD commit from the git repo (git checkout -f, see linked tutorial)
run bundle install
run bundle exec rake db:migrate - this assumed that you have already created your DB
restart/start the Thin server cluster (no sure exactly here, if it is similar to passenger which I use this operation is just to create some restart.txt file) - I presume that you have your nginx as a reverse proxy in front of it, right?
This is the long-story short. It is little bit more complicated, eg. if you use the asset pipeline (rails >= 3.1), you would like to precompile you assets, etc. But the above is a good starting point.
Well, I managed to get it almost completely operational.
The main actions I could trace until now are:
User pushes to trunk, must use git hooks to trigger the next steps using a script.
The script must do the following:
Clone the project to the /var/www folder;
Insert the 'thin' gem into the Gemfile;
Run 'bundle' command in the application folder;
Precompile the assets in the application folder;
Migrate the database;
Stop nginx and thin;
Restart thin and nginx again.
If the application is new, we must also:
Create a new user that matches the database information;
Create the production database;
Insert a new nginx configuration file;
Export the thin configuration from the application folder, like this:
thin config -C /etc/thin/app.yml -c /var/www/app --servers 1 -e production
The sequence of actions is more or less this:
$ bundle package
$ bundle install --deployment
$ RAILS_ENV=production rake db:migrate
$ rake assets:precompile
$ thin start -C /etc/thin/app.yml
This is the basic by now. I want to make it work 100% and then I want to post a guide on the Internet.
Update
The guide I said I would do:
https://github.com/sentient06/RDH/wiki
The problem with this app is that is WIP, so we are not using anything to deploy it to our production server, we just clone it from github and we are doing a git pull every time we have something done, rake assets:precompile task takes more than 30 minutes to finish!, WTF?.
We are doing this:
$ bundle exec rake assets:clean
$ bundle exec rake assets:precompile
Our production server:
ruby 1.9.3p194 (rbenv)
rails 3.2.3
unicorn
nginx
Our rails + unicorn + rbenv + init.d daemon configuration is here: https://gist.github.com/2776085
Now, here's our assets manifests, Gemfile and our production.rb files: http://pastie.org/3958070
So, somebody knows why this takes so long? or there's a way to speed up assets compilation in production?.
Thank you.
UPDATE: Assets compilation times locally: http://pastie.org/3961734
Rails's asset pipeline looks a little bit further than app/assets/{javascripts,stylesheets}.
As mentioned in the guides, there are also other locations where you can put your application's assets:
app/assets
lib/assets
vendor/assets
I suggest you to read the complete guide on Rails's asset pipeline to get more information about all this and also some tips for your production environment, such as nginx rules for caching, speeding up the assets pre-compilation, etc.
Was our fault, we have an extra folder inside app/assets, like app/assets/blah with a lot of folders inside, so the assets pipeline was looking over there, still, we don't know why the assets pipeline isn't just looking inside app/assets/javascripts and app/assets/stylesheets.