I'm trying to set up my rails app onto a DigitalOcean Server with postgres, following This Tutorial. I am at the point where I am trying to deploy my app with capistrano, but when I run $cap production deploy, it always fails with this error message:
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [1c7e325c] )
DEBUG [1c7e325c]
DEBUG [1c7e325c] To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.1`
DEBUG [1c7e325c] from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
DEBUG [1c7e325c] from /home/deploy/.rbenv/versions/2.6.1/bin/bundle:23:in `<main>'
DEBUG [1c7e325c] Finished in 0.408 seconds with exit status 1 (failed).
INFO [5d18f10c] Running $HOME/.rbenv/bin/rbenv exec bundle install --path /home/deploy/myapp/shared/bundle --jobs 4 --without development test --deployment --quiet as deploy#1.2.3.4
DEBUG [5d18f10c] Command: cd /home/deploy/myapp/releases/20190408225913 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.1" ; $HOME/.rbenv/bin/rbenv exec bundle install --path /home/deploy/myapp/shared/bundle --jobs 4 --without development test --deployment --quiet )
DEBUG [969718b0] /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe'
DEBUG [969718b0] :
DEBUG [969718b0] Could not find 'bundler' (2.0.1) required by your /home/deploy/myapp/releases/20190408225913/Gemfile.lock.
DEBUG [969718b0] (
DEBUG [969718b0] Gem::GemNotFoundException
DEBUG [969718b0] )
DEBUG [969718b0]
DEBUG [969718b0] To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.1`
DEBUG [969718b0] from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
DEBUG [969718b0] from /home/deploy/.rbenv/versions/2.6.1/bin/bundle:23:in `<main>'
This is my deploy file:
set :application, "myapp"
set :repo_url, "git#github.com:user/myapp.git"
append :rbenv_map_bins, 'puma', 'pumactl'
# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# Only keep the last 5 releases to save disk space
set :keep_releases, 5
# Optionally, you can symlink your database.yml and/or secrets.yml file from the shared directory during deploy
# This is useful if you don't want to use ENV variables
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.4.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'capistrano', '~> 3.11'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'
I've already tried running gem install bundler:2.0.1 and gem install bundler on both the deploy#myapp and my local computer. Any suggestions on how I can fix this problem, and fix the error that occurs when I try to deploy my app to production with capistrano rbenv?
EDIT
Capfile:
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
# require "capistrano/bundler"
# require "capistrano/rails/assets"
# require "capistrano/rails/migrations"
# require "capistrano/passenger"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
require 'capistrano/rails'
require 'capistrano/passenger'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.6.1'
First check if you have bundler installed as the deploy user after switching into the proper rbenv:
rbenv global 2.6.1
bundler --version
If not install it: gem install bundler:2.0.1.
Otherwise make sure your Capfile has the rbenv label mentioned (see tutorial).
set :rbenv_type, :user
set :rbenv_ruby, '2.6.1'
Related
I was following a tutorial to test how to deploy an application in Rails but when I tried to run it, it generated several errors that I was solving, first I clarify that I am working locally from windows, and the server I am using as a target for testing is an ubuntu 18 instance of AWS. However I put the unicorn gem with this code in the gemfile.
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.2"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
# Use mysql as the database for Active Record
gem "mysql2", "~> 0.5"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
platforms :ruby do # linux
gem 'unicorn'
end
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
gem "rack-cors"
# Use Sass to process CSS
# gem "sassc-rails"
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails', github: 'capistrano/rails'
gem 'capistrano-rails-console'
gem 'capistrano-sidekiq'
gem 'rvm1-capistrano3', require: false
gem 'airbrussh', require: false
gem 'net-ssh', '>= 6.0.2'
gem 'ed25519', '>= 1.2', '< 2.0'
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end
The error that generates me in the deployment is this:
Execute deploy:restart
00:35 deploy:restart
01 sudo /etc/init.d/unicorn_pruebadespliegue_production restart
01 /etc/init.d/unicorn_pruebadespliegue_production: 26: kill:
01 No such process
01
01 Couldn't reload, starting 'cd /home/web/apps/pruebadespliegue/current; bundle exec unicorn -D -c /home/web/apps/pruebadespliegue/shared/config…
01 master failed to start, check stderr log for details
01
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as web#ec2-44-210-112-191.compute-1.amazonaws.com: sudo exit status: 1
sudo stdout: /etc/init.d/unicorn_pruebadespliegue_production: 26: kill: No such process
Couldn't reload, starting 'cd /home/web/apps/pruebadespliegue/current; bundle exec unicorn -D -c /home/web/apps/pruebadespliegue/shared/config/unicorn.rb -E production' instead
master failed to start, check stderr log for details
sudo stderr: Nothing written
The truth is that I have tried to look for several solutions but I can't find the way to start the deployment and I am stuck in this error, in which I can't find any information.
the code for my deploy.rb is this:
# config valid only for current version of Capistrano
lock '3.17.1'
def deploysecret(key)
#deploy_secrets_yml ||= YAML.load_file('config/deploy-secrets.yml')[fetch(:stage).to_s]
#deploy_secrets_yml[key.to_s]
end
set :rails_env, fetch(:stage)
set :rvm_ruby_version, deploysecret(:rvm_ruby_version)
set :rvm_type, :user
set :application, deploysecret(:application)
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
# If ssh access is restricted, probably you need to use https access
set :repo_url, deploysecret(:repo_url)
#set :scm, :git
#set :revision, `git rev-parse --short #{fetch(:branch)}`.strip
set :log_level, :info
set :pty, true
set :use_sudo, false
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{log tmp public/system public/assets}
set :keep_releases, 10
set :local_user, ENV['USER']
set :deploy_user, deploysecret(:user)
# Run test before deploy
set :tests, []
# Config files should be copied by deploy:setup_config
set(:config_files, %w(
log_rotation
database.yml
secrets.yml
unicorn.rb
sidekiq.yml
nginx.conf
unicorn_init.sh
))
set(:symlinks, [
{
source: 'nginx.conf',
link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
},
{
source: 'unicorn_init.sh',
link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
},
{
source: 'log_rotation',
link: "/etc/logrotate.d/#{fetch(:full_app_name)}"
}
])
namespace :deploy do
# deploy:setup_config
# remove the default nginx configuration as it will tend
# to conflict with our configs.
before 'deploy:setup_config', 'nginx:remove_default_vhost'
before 'deploy:setup_config', 'nginx:enable_virtual_host'
after 'deploy:setup_config', 'nginx:reload'
after 'deploy:setup_config', 'nginx:executable_init'
# Check right version of deploy branch
before :deploy, 'deploy:check_revision'
# Run test aund continue only if passed
before :deploy, 'deploy:run_tests'
# Compile assets locally and then rsync
# after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
after :finishing, 'deploy:cleanup'
# Restart unicorn
after 'deploy:publishing', 'deploy:restart'
end
I recently switched from rvm to rbenv on my ubuntu server. I have followed all instructions in the official documentation https://github.com/rbenv/rbenv. When I try to deploy with capistrano, I run into an error message saying it can't find the /bin/rbenv directory.
00:24 bundler:config
01 RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.5.8 $HOME/.rbenv/bin/rbenv exec bundle config --local deployment true
01 bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
#<Thread:0x00007ff4640d25e0#/Users/kevinsun/.rvm/gems/ruby-2.5.8#wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/kevinsun/.rvm/gems/ruby-2.5.8#wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/kevinsun/.rvm/gems/ruby-2.5.8#wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy#3.133.135.38: bundle exit status: 127 (SSHKit::Runner::ExecuteError)
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#3.133.135.38: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
Caused by:
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
Tasks: TOP => deploy:updated => bundler:install => bundler:config
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy#3.133.135.38: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
On my instance, drilling down into that directory I can confirm there is no /bin/rbenv under /home/deploy/.rbenv/
ubuntu#ip-10-0-0-163:/home/deploy/.rbenv$ ls -a
. .. plugins shims versions
I have tried fiddling around with my deploy file according to this answer but to no avail.
Here is my Gemfile, Capfile, and deploy.rb:
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.8'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem "font-awesome-rails"
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'momentjs-rails'
gem 'bootstrap-toggle-rails'
#Admin user
gem 'activeadmin'
gem 'activeadmin_settings_cached'
gem 'formadmin'
gem 'active_admin_role'
gem "kaminari"
# charts
gem "chartkick"
gem 'groupdate'
#background
gem "redis"
gem 'sidekiq', '5.2.7'
gem 'sidekiq-status'
# copy clipboard
gem 'clipboard-rails'
# ransack
gem 'ransack'
# geocoder
gem 'geocoder'
# Plus integrations with:
gem 'devise'
gem 'cancancan'
gem 'draper'
gem 'pundit'
#design
gem "bootstrap", '~> 4.3.1'
gem 'ckeditor', github: 'galetahub/ckeditor'
gem 'paperclip'
gem 'aws-sdk', '~> 3.0', '>= 3.0.1'
gem 'aws-sdk-s3', '~> 1.83', '>= 1.83.1'
gem 'color'
#payments
gem 'money-rails'
gem 'stripe'
gem 'paypal-sdk-rest'
#nested form
gem 'nested_form_fields'
# slick
gem "jquery-slick-rails"
gem 'jquery-rails'
gem 'jquery-ui-rails'
#gem 'font-awesome-sass'
gem 'remotipart'
# paginate
gem 'will_paginate'
gem 'will_paginate_infinite'
gem 'validates_email_format_of'
# simple form and validations
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
gem 'jquery-validation-rails'
gem 'alertifyjs-rails'
gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47'
#social login
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
#API
gem 'rack-cors', '0.4.0'
gem 'rack-attack', '5.0.1'
gem 'active_model_serializers'
gem 'jwt'
gem 'simple_command'
gem 'bcrypt'
# sitemap
gem 'sitemap_generator'
# notifications
gem 'notifications', '~> 0.6.0'
# enum
gem 'simple_enum'
# recaptcha
gem "recaptcha", :require => "recaptcha/rails"
# cron
gem 'whenever', require: false
# autolink
gem "rails_autolink"
#for read unread
gem 'unread'
#list gem
gem 'acts_as_list'
#cropper and dropzone
gem 'cropper_rails'
gem 'dropzonejs-rails'
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'byebug'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'annotate'
gem 'bullet'
gem "brakeman"
gem "rb-readline"
#deploy
gem 'capistrano', require: false
# gem 'capistrano-rvm', require: false
gem 'capistrano-rbenv', '~> 2.2'
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-sidekiq', require: false
gem 'capistrano3-puma', require: false
gem 'sshkit-sudo', require: false
gem 'capistrano-nvm', require: false
gem 'capistrano3-monit', github: 'naps62/capistrano3-monit'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'language_filter'
gem 'nokogiri', '~> 1.10', '>= 1.10.9'
gem 'figaro'
#gem 'rvm-capistrano'
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
require 'capistrano/rails'
require 'capistrano/bundler'
# require 'capistrano/rvm'
require 'capistrano/rbenv'
require 'capistrano/puma'
require 'capistrano/sidekiq'
require "whenever/capistrano"
require 'capistrano/sidekiq/monit'
install_plugin Capistrano::Puma # Default puma tasks
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Monit
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
deploy.rb
# config valid only for current version of Capistrano
#lock '3.8.1'
#require "rvm/capistrano"
set :application, 'ewagers-noah-rails'
set :repo_url, 'git#gitlab.com:ankush_verma/ewagers.git'
set :branch, 'autoscale-test'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 4
# Don't change these unless you know what you're doing
set :pty, false
set :use_sudo, false
set :sidekiq_user, fetch(:user)
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
set :rvm_ruby_version, 'ruby-2.5.8#wager'
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'puma.rb', 'config/app.yml', "config/sidekiq.yml", "config/env.yml")
set :sidekiq_config, 'config/sidekiq.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads', 'public/watir')
## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
# set :log_level, :debug
set :keep_releases, 2
set :execute_monit_without_sudo, false
## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
namespace :deploy do
desc "Update crontab with whenever"
task :update_cron do
on roles(:app) do
within current_path do
execute :bundle, :exec, "whenever --update-crontab #{fetch(:application)}"
end
end
end
after :finishing, 'deploy:update_cron'
end
namespace :deploy do
desc 'run "CREATE EXTENSION IF NOT EXISTS "pgcrypto"" in sudo mode'
task :sudo_pgcrypto do
on roles(:all) do |host|
execute :sudo, "CREATE EXTENSION IF NOT EXISTS", "pgcrypto"
end
end
end
namespace :logs do
desc "tail rails logs"
task :puma do
on roles(:app) do
execute "tail -f -n 500 #{shared_path}/log/#{fetch(:rails_env)}.log "
end
end
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
set :rbenv_type, :user # or :system, or :fullstaq (for Fullstaq Ruby), depends on your rbenv setup
set :rbenv_ruby, '2.5.8'
set :rbenv_ruby_dir, '/home/deploy/.rbenv/versions/2.5.8'
# in case you want to set ruby version from the file:
# set :rbenv_ruby, File.read('.ruby-version').strip
set :default_env, {
path: '/home/deploy/.rbenv/plugins/ruby-build/bin:/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH',
rbenv_root: '/usr/bin/rbenv' # also tried '/home/deploy/.rbenv' here
}
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
set :rbenv_custom_path, '/usr/bin/rbenv' # also tried '/home/deploy/.rbenv' here
This helps in my case, I had same problem, capistrano was not able to find rbenv binary
set :rbenv_prefix, '/usr/bin/rbenv exec'
thanks to this issue on github, where it is noted
github
I have a rails app where I was installing gems and it worked fine.
Now, I do not knwow what I did, when I add a gem in the Gemfile and run bundle install, the app crashes with the Gem not found error (example.: "We're sorry, but something went wrong. ... Could not find gmaps4rails-2.1.2 in any of the sources (Bundler::GemNotFound)...").
I tried the command:
which gem gmaps4rails
output: /usr/bin/gem
Passenger error shows:
System Information
Ruby interpreter command
/home/webmaster/.rbenv/versions/2.3.3/bin/ruby
User and groups
uid=1001(webmaster) gid=33(www-data) groups=33(www-data),27(sudo),110(lxd)
Environment variables
APACHE_RUN_DIR = /var/run/apache2
APACHE_PID_FILE = /var/run/apache2/apache2.pid
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
APACHE_LOCK_DIR = /var/lock/apache2
LANG = C
APACHE_RUN_USER = www-data
APACHE_RUN_GROUP = www-data
APACHE_LOG_DIR = /var/log/apache2
PWD = /var/www/maus_view
PASSENGER_USE_FEEDBACK_FD = true
SERVER_SOFTWARE = Apache/2.4.18 (Ubuntu) Phusion_Passenger/5.1.5
PASSENGER_DEBUG_DIR = /tmp/passenger.spawn-debug.XXXXIfqFGX
USER = webmaster
LOGNAME = webmaster
SHELL =
HOME = /home/webmaster
IN_PASSENGER = 1
PYTHONUNBUFFERED = 1
NODE_PATH = /usr/share/passenger/node
RAILS_ENV = development
RACK_ENV = development
WSGI_ENV = development
NODE_ENV = development
PASSENGER_APP_ENV = development
BUNDLER_ORIG_PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GEM_PATH = /home/webmaster/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0:/home/webmaster/.gem/ruby/2.3.0
GEM_HOME = /home/webmaster/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0
I've read a lot of stackoverflow's post but I'm not able to debug and find a solution to this issue.
Can somebody help me?
Thank you
--- EDIT ---
This is my Gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
#gem 'gmaps4rails'
for some gems you need to install them through command line instead of just 'bundle installing' them.
So try running:
gem install gmaps4rails
And go to you projects directory and hit bundle install
Hope it helps!
When I do $ bundle install, it attempts to get gems only meant for production, despite me being on development.
I double checked that I'm on development: echo $RAILS_ENV # outputs "development"
Here is a copy of my gem file. If I remove :staging in the last block, then my bundle installs correctly and ignores this group. Why would adding :staging cause my app to include these gems?
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.0'
gem 'bootstrap-sass', '~> 3.0.1.0.rc'
gem 'bcrypt-ruby', '3.0.1'
# generates names, email addresses, and other placeholders for factories.
gem 'faker'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'aws-sdk', '1.11.1'
gem 'd3-rails', '~>3.3.7'
# used for file ajax uploads
gem 'remotipart', '~> 1.2'
# used for making server side variables accessible in JS
gem "iconv", "~> 1.0.4"
gem "roo", "~> 1.13.2"
gem 'underscore-rails'
gem 'gon', '4.1.0'
# gem "introjs-rails"
# High voltage for static pages
gem 'high_voltage', '~> 2.0.0'
gem "koala", "~> 1.8.0rc1"
gem 'acts_as_list'
gem "bugsnag"
gem 'devise'
# EC2 server is passenger
gem 'passenger'
# easily create seeds
gem 'seed_dump'
#add crossfilter for exploring high dimensional datasets and dcjs for charts
gem 'crossfilter-rails'
# gem 'dcjs-rails'
gem 'activeadmin', github: 'gregbell/active_admin'
# Monitor site speed.
gem 'newrelic_rpm'
group :development, :test do
gem 'sqlite3', '1.3.8'
# rspec-rails includes RSpec itself in a wrapper to make it play nicely with Rails.
gem 'rspec-rails'
# replaces Rails' default fixtures for feeding test data to the test suite with much more preferable factories
gem 'factory_girl_rails'
# watches your application and tests and runs specs for you automatically when it detects changes.
gem 'guard-rspec'
end
group :test do
# runs a browser
gem 'selenium-webdriver'
# makes it easy to programatically simulate your users' interactions with your application
gem 'capybara'
# Shows growl notifications (os x only)
gem 'growl'
# opens your default web browser upon failed integration specs to show you what your application is rendering.
gem 'launchy' # tims tutorial
# helps clear out db after using selenium in tests
gem 'database_cleaner' # tims tutorial
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
# fuck turbolinks.
# gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
# added for resizing panes on d3fiddle pages
gem 'jquery-ui-rails'
# added for code highlighting on d3fiddle pages
gem 'codemirror-rails'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production, :staging do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
Use bundle install --without staging production.You can find more information about bundle here.
Update:
It is because of Bundler.require(:default, Rails.env) present in config/application.rb that bundle does not install gems present in test and production by default.
When running autotest, I get the error Could not find ZenTest-4.7.0 in any of the sources. After viewing this article, I deleted gemfile.lock, ran 'bundle install', and then tried rerunning autotest. Now I get the error Could not find rake-10.0.3 in any of the sources. FYI, I am using RBENV, and I have no other problems running my app (rails c, rails s, rake, ...). Here is my gem file (btw, both "missing" files appeared in gemfile.lock):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'rake'
gem 'pg', '0.13.2'
# Sidekiq handles background jobs, using threading
gem 'sidekiq', '>= 2.6.1'
# Need the following gems for sidekiq/web
gem 'slim'
# if you require 'sinatra' you get the DSL extended to Object
gem 'sinatra', :require => nil
gem 'heroku-api' # Need the API for scaling sidekiq
gem 'json'
gem 'premailer'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# Bundle the extra gems:
gem 'mechanize'
gem 'nokogiri'
gem 'spreadsheet'
gem 'xml-simple'
gem 'faker', '~> 0.3.1'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development do
gem 'rspec-rails'
gem 'ruby-debug19'
end
group :test do
gem 'rspec-rails'
gem 'ZenTest'
gem 'shoulda-matchers'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails'
gem 'ruby-debug19'
end
gem 'geoip'
gem 'thin'
gem 'htmlentities'
I'm not 100% certain, but I think you just do:
gem install ZenTest
and probably
gem install autotest-rails
From within your application directory.
These guys are not managed by your gemfile and bundler