i have very strange error when deploy my rails app with capistrano. sometimes it's deploy and sometimes not.
for example i add something to css (just one string) e.g. .my_some_class{width:10px}
and after that deployment fails. before i add this - it's deploy ok.
i am sure what nothing else changed cause i make experimental commit which contain only one string of css.
my config:
rails 4.1.0
ruby 2.1.1p76
gem 'capistrano-rails', group: :development
gem 'capistrano-rvm', group: :development
gem 'capistrano-bundler', group: :development
end of deploy log:
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Command::Failed: rake exit status: 137
rake stdout: Nothing written
rake stderr: SafeYAML Warning
----------------
You appear to have an outdated version of libyaml (0.1.4) installed on your system.
Prior to 0.1.6, libyaml is vulnerable to a heap overflow exploit from malicious YAML payloads.
For more info, see:
https://www.ruby-lang.org/en/news/2014/03/29/heap-overflow-in-yaml-uri-escape-parsing-cve-2014-2525/
The easiest thing to do right now is probably to update Psych to the latest version and enable
the 'bundled-libyaml' option, which will install a vendored libyaml with the vulnerability patched:
gem install psych -- --enable-bundled-libyaml
I, [2014-04-30T09:42:41.121037 #12193] INFO -- : Writing /var/www/default/releases/20140430134522/public/assets/Thumbs-82e32ea0cc1ce375db2805ceadd707ef.db
I, [2014-04-30T09:42:41.123108 #12193] INFO -- : Writing /var/www/default/releases/20140430134522/public/assets/agency_no_logo-a8544e60b8a38abeb431c2eb5089f7c6.png
I, [2014-04-30T09:42:41.461121 #12193] INFO -- : Writing /var/www/default/releases/20140430134522/public/assets/swipebox/img/loader-a66dde050b0b2447862919f2c4c37eda.gif
bash: line 1: 12193 Killed ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
As was written above, probably, you have not enough RAM.
I solved problem by adding SWAP file on my Ubuntu 14.04 server:
Under the root:
dd if=/dev/zero of=/swapfile bs=1024 count=512k
mkswap /swapfile
swapon /swapfile
Add next line to /etc/fstab:
/swapfile none swap sw 0 0
and:
echo 0 > /proc/sys/vm/swappiness
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
check SWAP(maybe need reloading):
swapon -s
— How To Add Swap on Ubuntu 14.04 # Digital Ocean Community
if someone have same error - problem was on hosting. server have not enough ram(512mb), and process of compilation css/js was killed every time. than we change rate plan, which has 1gb ram, all deployed successfully. SO if you assets precompile failed - just try to add some resources to server.
P.S. similar problem i found here Capistrano deploy - assets precompile error
Try rebooting the server.Worked for me.
You appear to have an outdated version of libyaml
Update libyaml.
Related
I got this error again... I don't remember how I fixed the first time this time I tried using the .slugignore file to exclude things I don't need my main folder that is taking for slug size is vendor, and node modules, I used
Heroku run bash -a businessappk3400
» Warning: Heroku update available from 7.42.5 to 7.42.8.
Running bash on ⬢ businessappk3400... up, run.8800 (Standard-1X)
~ $ du -sh * | sort -hr
and got :
So I am looking into reducing the vendor and node module files I tried putting them in the .slugignore folder I created in the root folder like this:
.slugignore:
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
./log
./tmp
./storage
./public
./node_modules
./yarn-error.log
./heroku
./vendor
./vendor/bundle
./kevin
./kevin.pug
./package-lock.json
./config/environments/database.yml
./package-lock.json
./vendor/database.yml
./public/packs
./public/packs-test
./yarn-error.log
./yarn-debug.log
.yarn-integrity
but I still pass the 500mb limit on slug... anyone has resolved this issue?
error:
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
builder (1.02 MiB)
js/builder-ba7328e435e703a663b7.js
Asset precompilation completed (268.67s)
Cleaning assets
Running: rake assets:clean
-----> Detecting rails configuration
###### WARNING:
You have not declared a Ruby version in your Gemfile.
To declare a Ruby version add this line to your Gemfile:
```
ruby "2.6.6"
```
For more information see:
https://devcenter.heroku.com/articles/ruby-versions
###### WARNING:
Removing `Gemfile.lock` because it was generated on Windows.
Bundler will do a full resolve so native gems are handled properly.
This may result in unexpected gem versions being used in your app.
In rare occasions Bundler may not be able to resolve your dependencies at all.
https://devcenter.heroku.com/articles/bundler-windows-gemfile
###### WARNING:
Detecting rails configuration failed
set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
-----> Discovering process types
Procfile declares types -> web, worker
Default types for buildpack -> console, rake
-----> Compressing...
! Compiled slug size: 565.7M is too large (max is 500M).
! See: http://devcenter.heroku.com/articles/slug-size
! Push failed
The complete error can be found here: https://codepen.io/apesyntax/pen/oNLvWdB
To reduce the Heroku slug size of my app (Rails 6.0.4.4, Ruby 3.1), I did the following:
Restrict 'wkhtmltopdf-binary' gem to development/test environments & add 'wkhtmltopdf-heroku' gem to production environment in my Gemfile (ref: https://www.eyupatis.com/how-to-decrease-heroku-slug-size-wkhtmltopdf-edition/):
gem 'wkhtmltopdf-binary', group: [:development, :test]
gem 'wkhtmltopdf-heroku', group: :production
Add 'heroku-buildpack-post-build-clean' AFTER the nodejs and ruby buildpacks in Heroku (ref: https://www.eyupatis.com/how-to-decrease-heroku-slug-size-post-build-clean-buildpack-edition/):
heroku buildpacks:add --index 3 https://github.com/Lostmyname/heroku-buildpack-post-build-clean
After this step, running heroku buildpacks listed my buildpacks as:
heroku/nodejs
heroku/ruby
https://github.com/Lostmyname/heroku-buildpack-post-build-clean
Create .slug-post-clean file in the root directory & add the /node_modules path as the only line in the file (ref: https://johntornow.com/tech/2020/04/heroku-slug-size):
/node_modules
(NOTE: the node_modules path for your project may be different than what's shown here)
Compiled slug size:
Before: 525Mb
After: 258Mb 🤯 (a 50% reduction!!!!)
The resolution for this app was:
Use npm to uninstall modules we did not need or use...
The only way we could make the slug change when deploying the app.
we tried before and didn't work:
-Restoring Heroku cache
-Regenerating the slug in a Linux system
-deleting the vendor folder
-deleting files and no Heroku reduction at all
-contacting support
app details:
Ruby 2.3.3
with web pack + webpacker
When I run Capistrano task with dry run it tells me that rbenv Ruby version can't be found. I assume with dry run it should use local environment. But when I run the commands locally I can easily find below mentioned directory and Ruby is installed.
> ./bin/bundle exec cap --dry-run development t
DEBUG [8171d925] Running [ ! -d ~/.rbenv/versions/2.4.3 ] as user#dev
DEBUG [8171d925] Command: [ ! -d ~/.rbenv/versions/2.4.3 ]
ERROR rbenv: 2.4.3 is not installed or not found in ~/.rbenv/versions/2.4.3
> ls ~/.rbenv/versions/2.4.3
bin include lib share
> rbenv global
2.4.3
> ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin16]
> bundle info capistrano
* capistrano (3.4.0)
My Capfile contains below lines.
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.4.3'
I'm using Mac OS and installed rbenv with homebrew.
Check your PATH and make sure it contains $HOME/.rbenv/shims and $HOME/.rbenv/bin
To view your path do:
$ echo $PATH
Also check that you have the following in your ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
To check bash profile enter in terminal:
touch ~/.bash_profile; open ~/.bash_profile
Make sure it's the last setting in your ~/.bash_profile
There must have been some bug in capistrano/rbenv. I have changed my Gemfile as follows and problem is solved.
# gem 'capistrano-rbenv', '2.0.2'
gem 'capistrano-rbenv', '~> 2.1'
I assume with dry run it should use local environment.
This is not true.
A Capistrano dry-run simply prints out the remote commands that it would run in an actual deploy, but it does execute them at all (local or otherwise).
Since Capistrano is not executing any commands, any plugins that rely on results of those commands may not work. For example, the rbenv plugin is apparently expecting to run this command:
[ ! -d ~/.rbenv/versions/2.4.3 ]
In a dry-run scenario, this is not actually executed. Instead, Capistrano just prints the command and continues as if the command succeeded.
In this particular case, for [ ! -d ~/.rbenv/versions/2.4.3 ] to "succeed" means that the ~/.rbenv/versions/2.4.3 does not exist. The rbenv plugin thus prints an error an halts the deployment.
To summarize: in practice, the --dry-run option is not particularly useful.
I'm currently trying to learn Ruby on Rails on Windows 10.
I'm following the excellent railstutorial by Michael Hartl.
However, I'm getting bugged by the 'gem install win32console' message (and lack of colour) appearing when I run rake test. How can I fix this?
Sample output:
$ bundle exec rake test
ansi: 'gem install win32console' to use color on Windows
Started
3/3: [===================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.35885s
3 tests, 6 assertions, 0 failures, 0 errors, 0 skips
My setup:
Base: Ruby 2.2 Rails Installer for Windows.
Running commands using Git Bash.
I also have the minitest-reporters gem installed (step 3.7.1 of tutorial).
What I've tried:
First I ran gem install win32console bu this had no effect, even though the gem is visible when I run gem list.
Then I saw win32console is deprecated so I installed ansicon.
This also had no effect. And it seems colours are supported on Windows 10 anyway.
E.g. I can run the Hello World example puts "\e[34mHello \e[31mWorld\e[0m" found on this blog and it shows blue and red text, whether ansicon is installed or not.
However, colours won't show up correctly in rake test output and I still get the warning.
Hooray got it working!
In the end your comment Jordan plus the suggestions on Paul's Perambulations got me there.
Steps taken, for anyone else stuck on this:
Download and unzip win32console source
Install specific (older) versions of the dependencies:
gem install rake -v 10.4.2
gem install rake-compiler -v 0.9.9 (this is current latest anyway)
gem install hoe -v 3.7.0
Run rake _10.4.2_ gem in the win32console source directory (to use correct version)
Run gem install pkg/win32console-1.3.2.gem (had to change version number and flip the slash around from original instructions)
Add gem "win32console", '1.3.2' to Gemfile
Go back to project directory and run bundle install
Finally run bundle exec rake test - the info message has disappeared and colours are showing correctly!
I was heavily struggling with my Capistrano Setup, when my Hoster migrated the server:
Capistrano3 deploy fails after migrating the server
One thing I ran into that used to work just fine on the old machine and now seems to be a mess is bundler:
I could successfully run bundler through Capistrano:
cap staging bundler:install
This resulted in the following command on the server
/usr/bin/env bundle install --binstubs \
/var/www/mydomain.com/subdomains/dev/shared/bin \
--path /var/www/mydomain.com/subdomains/dev/shared/bundle \
--without development test \
--deployment
But now when I ran my server cap staging deploy:start_passenger which results in the following:
/usr/bin/env passenger start --socket tmp/passenger.socket -e staging -d
Then I got the error in my log file, that Rake was missing:
Could not find rake-10.2.2 in any of the sources (Bundler::GemNotFound)
<pre> /var/www/mydomain.com/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/spec_set.rb:92:in `block in materialize'
What is very weird, is the fact that the ruby version 2.1.2(the one I really use) shows up with 2.1.0. I have no visible reference to2.1.0` in my project, and my Gemfile contains:
ruby '2.1.2'
Since RBENV is used on the server I can run rbenv versions which shows me:
system
* 2.1.2 (set by /var/www/mydomain.com/.rbenv/version)
So where does that weird 2.1.0 come from and how can I make sure that my server has all the dependencies it requires.
I finally managed to deploy my application on the new server.
These steps were required to do it. However since I fought with it for a few hours some of it might be redundant:
gem install bundler && rbenv rehash: This is required since bundler is one of the gems that I need outside of the Rails App context in terms of dependencies.
Another one is gem install passenger && rbenv rehash
I am now using https://github.com/capistrano/rbenv but for this I had to wipe RVM from my system, which was a step I wasn't too enthusiastic of doing.
I had to make sure the current symlink was created so I added this to the deploy.rb
after 'deploy:set_current_revision', 'deploy:symlink:release'
I had to delete some of the shared directories:
rm -fr bin
rm -fr shared/bundle/
rm -fr bundle
When I run
cap production rvm1:install:ruby
I get this error at the end of the console output:
Command: cd ~/apps/foo/releases/20140121133714 && ( PATH=/opt/ruby/bin:$PATH /usr/bin/env /tmp/foo/rvm-auto.sh rvm install . )
Could not determine which Ruby to use; . should contain .rvmrc or
.versions.conf or .ruby-version or .rbfu-version or .rbenv-version, or an appropriate line in Gemfile.
cap aborted!
EDIT
After adding an .ruby-version at the root of my app, with the contents I get
DEBUG [af3b80bc] Command: cd ~/apps/foo/releases/20140121160854 && /usr/bin/env /tmp/foo/rvm-auto.sh rvm install .
DEBUG [af3b80bc] ruby-2.0.0-p247 is not installed.
DEBUG [af3b80bc] To install do: 'rvm install ruby-2.0.0-p247'
DEBUG [af3b80bc] ruby-2.0.0-p247 is not installed.
DEBUG [af3b80bc] Searching for binary rubies, this might take some time.
DEBUG [af3b80bc] ruby-2.0.0-p247 is not installed.
DEBUG [af3b80bc] Searching for binary rubies, this might take some time.
DEBUG [af3b80bc] No binary rubies available for: ubuntu/12.10/x86_64/system.
DEBUG [af3b80bc] Searching for binary rubies, this might take some time.
DEBUG [af3b80bc] Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
DEBUG [af3b80bc] Searching for binary rubies, this might take some time.
DEBUG [af3b80bc] RVM does not have prediction for required space for system, assuming 150MB should be enough, let us know if it was not.
DEBUG [af3b80bc] Searching for binary rubies, this might take some time.
DEBUG [af3b80bc] Either the ruby interpreter is unknown or there was an error!.
I'm running Capistrano 3.1.1 with rvm1-capistrano gem. It's out of the box implementation; nothing special going on.
group :development do
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'rvm1-capistrano3', require: false
# gem 'capistrano-rvm'
end
# capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'rvm1/capistrano3'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
I'm also getting two other errors in the output:
Running /usr/bin/env [ -L ~/apps/foo/releases/20140121135720/public/assets ] on foo.com
Command: [ -L ~/apps/foo/releases/20140121135720/public/assets ]
Finished in 0.291 seconds with exit status 1 (failed).
Running /usr/bin/env [ -d ~/apps/foo/releases/20140121135720/public/assets ] on foo.com
Command: [ -d ~/apps/foo/releases/20140121135720/public/assets ]
Finished in 0.295 seconds with exit status 1 (failed).
Problem
If you go to the remote server and execute this:
cd ~/apps/foo/releases/20140121160854 && /usr/bin/env /tmp/foo/rvm-auto.sh rvm install .
you will get the same error but if you execute this instead
cd ~/apps/foo/releases/20140121160854 && /usr/bin/env /tmp/foo/rvm-auto.sh rvm install ruby-2.0.0-p247
success.
The problem appears when rvm-auto.sh execute the rvm install . command. Not sure if is a rvm problem but it looks so to my eyes..
Workaround
If you specify the desired version of ruby to install in config/deploy.rb:
set :rvm1_ruby_version, "ruby-2.0.0-p247"
before executing any rvm1 tasks. Everything should be fine
The application does not know which version of ruby to use.
All you need to do is add a file called .ruby-version to the root of your application, and have its contents be
1.9.3
Or whatever version of ruby you are using.
You may also need a .ruby-gemset file. In which case, its contents should be
some_gemset_name
You can call your gemset whatever you want. It is local to your application.