Rbenv unable to find Yarn during Capistrano deployment - yarnpkg

I've been using Capistrano for deployment of my Rails app. It is failing on the following step:
01 $HOME/.rbenv/bin/rbenv exec bundle install --path /var/www/bubblin.io/shared/bundle --without development test --deployment --quiet
✔ 01 marvin#bubblin.io 1.053s
00:26 yarn:install
01 $HOME/.rbenv/bin/rbenv exec yarn install --production
01 rbenv: yarn: command not found
$HOME/.rbenv/bin/rbenv exec yarn install --production
01 rbenv: yarn: command not found
#<Thread:0x00007fb9b626fcd8#/Users/sa/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/sa/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/sa/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as marvin#bubblin.io: yarn exit status: 127 (SSHKit::Runner::ExecuteError)
yarn stdout: rbenv: yarn: command not found
yarn stderr: Nothing written
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as marvin#bubblin.io: yarn exit status: 127
yarn stdout: rbenv: yarn: command not found
yarn stderr: Nothing written
I ssh'ed into the server and tried the following, which works:
$ yarn install --production
yarn install v1.10.1
[1/4] Resolving packages...
success Nothing to install.
success Saved lockfile.
Done in 0.06s.
But when I prefix the same command with rbenv exec it fails.
$ rbenv exec yarn install --production
rbenv: yarn: command not found
All dependencies appear to be installed correctly, but rbenv isn't able to find yarn for some reason?

I think yarn is nodejs package manager, should not run via rbenv exec perhaps?
So, in this case, you could simply use it from regular shell rather than rbenv.
For example, try to create task like the following should do the job.
desc "Yarn Install"
task :yarn_install do
on roles(:all) do |host|
execute :yarn, :install, "--production"
end
end
Then, run it with
bundle exec cap production yarn_install
Or, invoke the task from another task you have etc.
Update:
If not using yarn,
In Gemfile, remove or comment 'capistrano-yarn'
#gem 'capistrano-yarn'
In Capfile, remove or comment 'capistrano/yarn'
#require 'capistrano/yarn'
For creating a new project:
rails new <name> --skip-yarn
But, on existing project, set webpacker.check_yarn_integrity to false in app env files (i.e. app/config/development.rb app/config/production.rb)
config.webpacker.check_yarn_integrity = false
Find javascript_pack_tag or stylesheet_pack_tag in app/views/* path, then comment them out, like so:
<%# javascript_pack_tag "" %>
<%# stylesheet_pack_tag "" %>

Related

Azure devops pipeline on mac agent : Could not locate Gemfile when bundle install

I try to install via Azure DevOps pipeline on Mac agent and i keep getting this error :
- task: CmdLine#2
inputs:
script: 'mkdir ios'
- script: |
cd ios
gem install bundler
bundle update --bundler
bundle install
workingDirectory: ios
displayName: 'Ruby bundle setup'
Error :
2020-09-06T11:54:07.5917840Z ##[section]Starting: Ruby bundle setup
2020-09-06T11:54:07.5928350Z ==============================================================================
2020-09-06T11:54:07.5928740Z Task : Command line
2020-09-06T11:54:07.5929150Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2020-09-06T11:54:07.5929490Z Version : 2.164.2
2020-09-06T11:54:07.5929750Z Author : Microsoft Corporation
2020-09-06T11:54:07.5930170Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2020-09-06T11:54:07.5930590Z ==============================================================================
2020-09-06T11:54:07.7401990Z Generating script.
2020-09-06T11:54:07.7424640Z ========================== Starting Command Output ===========================
2020-09-06T11:54:07.7456160Z [command]/bin/bash --noprofile --norc /Users/runner/work/_temp/d9733c1e-f521-48ca-aa7c-9d3b24c88953.sh
2020-09-06T11:54:07.7526110Z /Users/runner/work/_temp/d9733c1e-f521-48ca-aa7c-9d3b24c88953.sh: line 1: cd: ios: No such file or directory
2020-09-06T11:54:12.3083310Z Successfully installed bundler-2.1.4
2020-09-06T11:54:12.3084130Z Parsing documentation for bundler-2.1.4
2020-09-06T11:54:12.3084780Z Installing ri documentation for bundler-2.1.4
2020-09-06T11:54:12.3085110Z Done installing documentation for bundler after 3 seconds
2020-09-06T11:54:12.3085430Z 1 gem installed
2020-09-06T11:54:12.6954440Z Could not locate Gemfile
2020-09-06T11:54:13.1617230Z Could not locate Gemfile
2020-09-06T11:54:13.1694000Z
2020-09-06T11:54:13.1763400Z ##[error]Bash exited with code '10'.
2020-09-06T11:54:13.1779990Z ##[section]Finishing: Ruby bundle setup
even if i follow this tutorial :
https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/ruby?view=azure-devops
i still getting :
2020-09-06T12:27:31.6476200Z ##[section]Starting: bundle install
2020-09-06T12:27:31.6490380Z ==============================================================================
2020-09-06T12:27:31.6490780Z Task : Command line
2020-09-06T12:27:31.6491150Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2020-09-06T12:27:31.6491570Z Version : 2.164.2
2020-09-06T12:27:31.6491830Z Author : Microsoft Corporation
2020-09-06T12:27:31.6492250Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2020-09-06T12:27:31.6492690Z ==============================================================================
2020-09-06T12:27:31.8007410Z Generating script.
2020-09-06T12:27:31.8038100Z ========================== Starting Command Output ===========================
2020-09-06T12:27:31.8070710Z [command]/bin/bash --noprofile --norc /Users/runner/work/_temp/79d6c766-b735-4025-8576-a11120d84585.sh
2020-09-06T12:27:36.4057030Z Successfully installed bundler-2.1.4
2020-09-06T12:27:36.4068290Z Parsing documentation for bundler-2.1.4
2020-09-06T12:27:36.4073040Z Installing ri documentation for bundler-2.1.4
2020-09-06T12:27:36.4116410Z Done installing documentation for bundler after 3 seconds
2020-09-06T12:27:36.4130600Z 1 gem installed
2020-09-06T12:27:36.7989650Z Could not locate Gemfile
2020-09-06T12:27:36.8083080Z
2020-09-06T12:27:36.8160820Z ##[error]Bash exited with code '10'.
2020-09-06T12:27:36.8177100Z ##[section]Finishing: bundle install
Azure devops pipeline on mac agent : Could not locate Gemfile when bundle install
According to the error message:
Could not locate Gemfile
It seems we do not have Gemfile in the workspace directory.
To resolve this issue, we need run bundle init first and after that bundle install.
As test, I add bundle init in your CmdLine task like following, and it works fine:
- script: |
mkdir ios
cd ios
gem install bundler
bundle init
bundle update --bundler
bundle install
displayName: 'Ruby bundle setup'
The result:

Error when jenkins slave run fpm command (/usr/bin/env: ruby_executable_hooks: No such file or directory)

I installed fpm by using a command:
rvm #global do gem install --no-user-install -no-ri --no-rdoc --bindir /usr/local/bin/ fpm
on docker image. But I could only execute the fpm command in /bin/bash mode, and couldn't with /bin/sh mode as shows an error:
/usr/bin/env: ruby_executable_hooks: No such file or directory
therefore, build job was failed when running the jenkins build.
How can I fix this?

CI/CD Gitlab deployment Failed - dbl command not found

The pipeline .gitlab-ci.yml code successfully works till yesterday, but today i got the error which says “dpl command not found”
the below is my .gitlab-ci.yml file
image: node:8.9.3
stages:
- job1
- test
- production
job1:
stage: job1
script: "ls -l"
test:
stage: test
script:
- npm install
production:
type: deploy
stage: production
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=quailapp --api-key=$HEROKU_PRODUCTION_API_KEY
only:
- master
This is the log Generated,
Setting up rake (10.5.0-2) ...
Setting up libruby2.3:amd64 (2.3.3-1+deb9u2) ...
Setting up ruby2.3 (2.3.3-1+deb9u2) ...
Setting up ruby2.3-dev:amd64 (2.3.3-1+deb9u2) ...
Setting up ruby-dev:amd64 (1:2.3.3) ...
Setting up ruby (1:2.3.3) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
$ gem install dpl
Successfully installed dpl-1.9.6
1 gem installed
$ dpl --provider=heroku --app=quailapp --api-key=$HEROKU_PRODUCTION_API_KEY
/bin/bash: line 68: dpl: command not found
ERROR: Job failed: exit code 1
please help me for finding the solution.
Same here, Issuing the command to install dpl with verbosity: gem install dpl --verbose I've been able to see something weird:
/usr/local/bundle/bin/dpl
Successfully installed dpl-1.9.6
1 gem installed
I don't know why but it is installed in a non-default path. As a workaround I've added the /usr/local/bundle/bin in $PATH environment variable issuing the following command:
export PATH=$PATH:/usr/local/bundle/bin
It works for me and my gitlab ci pipelines are now working again.
BTW, It would be great to know why it has changed suddenly...
Same problem here. I think, it's a problem in docker image. See https://github.com/docker-library/ruby/pull/209
They made some changes and broke path for gems binaries. We have to wait until they merge fix.
UPDATE:
It's already merged and their fix works for me.

Grunt - bundler: failed to load command: scss-lint

I have bootstrap 4 set up locally and when I ran grunt watch I get the following warning:
Running "scsslint:docs" (scsslint) task
Warning:
bundleExec options set but no Bundler executable found in your PATH.
More info: https://github.com/ahmednuaman/grunt-scss-lint
Use --force to continue.
Aborted due to warnings.
To fix this I ran the following command:
sudo gem install bundler -n /usr/local/bin
Then I got the following message:
Running "scsslint:docs" (scsslint) task
Running scss-lint on docs
>> 1. Please make sure you have ruby installed: `ruby -v`
>> 2. Install the `scss-lint` gem by running:
>> gem update --system && gem install scss-lint
So I ran the following commands:
sudo gem update --system -n /usr/local/bin
sudo gem install scss_lint -n /usr/local/bin
Now when I run grunt watch I get the following:
Running "scsslint:docs" (scsslint) task
Running scss-lint on docs
bundler: failed to load command: scss-lint (/usr/local/bin/scss-lint)
Warning: Task "scsslint:docs" failed. Use --force to continue.
I am on OSX El Capitan. Anyone have an idea how to fix this?
FYI I had to use the -n /usr/local/bin parameter on the commands because it would give me
Not sure what the issue is, but scss-lint is basically a syntax checker. I find that if I remove scss-lint that TWBS complies.
Try:
sudo gem uninstall scss-lint
Hopefully there will be a better answer than this, but for now this will get you going.

Whenever gem 'failed to load command: rake'

looking for some help.
I am running a rails app (v3.2.5) with the whenever gem (v0.9.7) and rake (v11.2.2). I am also doing this in a docker container image ruby:2.3 (cron was installed and bundle install was ran)
Here is my schedule.rb
set :environment, ENV['RAILS_ENV']
every '*/2 9,10,11,12,13,14,15,16 * * 1-5' do
rake "import_csv", output: {:error => 'log/import_csv_errors.log', :standard => 'log/import_csv.log'}'
end
note RAILS_ENV is set at container launch to development
Here is my cron job that is on the container after build (crontab -l):
# Begin Whenever generated tasks for: /usr/src/app/config/schedule.rb
*/2 9,10,11,12,13,14,15,16 * * 1-5 /bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
# End Whenever generated tasks for: /usr/src/app/config/schedule.rb
When this cron job runs, the logs return:
import_csv_errors.log
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
import_csv.log
bundler: failed to load command: rake (/usr/local/bin/rake)
Now here is the odd thing. If I copy the cron job command:
/bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
and run this in the container, it works fine, but if the cron job runs it, I get thos errors in the logs!!! I am at a lost here...
I've tried adding
env :PATH, ENV['PATH']
env :GEM_PATH, '/usr/local/bundle'
to the top of schedule.rb and I tried doing
command 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'
Instead of using rake in the task and I get the same errors..
Any help is appriciated
I've fixed the same error by modifying the Dockerfile with:
RUN gem update --system 2.6.12
RUN gem install bundler --version 1.14.6
And schedule.rb:
ENV.each { |k, v| env(k, v) }
I have updated my rake version and it worked for me. Below are the steps I followed:
sudo bundle update rake
sudo bundle install
Open a Rakefile and replace the line rake/rdoctask with require 'rdoc/task'.
I resolved my issue by using a different image and building as I needed it instead of using docker hub image ruby:2.x.
Dockerfile (edited to fit thread):
FROM ubuntu:14.04
# Installs needed to run rails on ubuntu 14.04 (must use mysql 5.6 or 5.5):
RUN apt-get update && apt-get install -y apache2 curl git build-essential libmysqlclient-dev mysql-server-5.6 nodejs make
RUN apt-get update && apt-get install -y ruby-dev zlib1g-dev
RUN gem install rails --version 3.2.5 --no-ri --no-rdoc
# Update ruby to v2.2 (optional)
RUN apt-get install -y software-properties-common && apt-add-repository ppa:brightbox/ruby-ng
RUN apt-get update && apt-get install -y ruby2.2
# Install cron
RUN apt-get install -y cron
# Finish the build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# If you code is in the same directory you ran docker build then:
COPY . /usr/src/app
RUN bundle install
RUN whenever --update-crontab
CMD ["passenger start"]

Resources