Gem Permission Error When installing fluentd plugin - ruby

When running docker on Jenkins i am getting the following error:
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/3.1.0 directory.
[0m[91m /usr/lib/ruby/3.1.0/rubygems/installer.rb:712:in `verify_gem_home'
/usr/lib/ruby/3.1.0/rubygems/installer.rb:902:in `pre_install_checks'
/usr/lib/ruby/3.1.0/rubygems/installer.rb:302:in `install'
/usr/lib/ruby/3.1.0/rubygems/resolver/specification.rb:104:in `install'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:194:in `block in install'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:182:in `each'
/usr/lib/ruby/3.1.0/rubygems/request_set.rb:182:in `install'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:210:in `install_gem'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:226:in `block in install_gems'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:219:in `each'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:219:in `install_gems'
/usr/lib/ruby/3.1.0/rubygems/commands/install_command.rb:167:in `execute'
/usr/lib/ruby/3.1.0/rubygems/command.rb:323:in `invoke_with_build_args'
/usr/lib/ruby/3.1.0/rubygems/command_manager.rb:185:in `process_args'
/usr/lib/ruby/3.1.0/rubygems/command_manager.rb:149:in `run'
/usr/lib/ruby/3.1.0/rubygems/gem_runner.rb:51:in `run'
/usr/bin/gem:21:in `<main>'
I've seen forums suggest that it is the alpine version 3.14 > used in fluentd image. This image uses alpine 3.16 and the docker version is 20.10.22 so it is the very latest one. This works locally with no issues and same docker version. I have also checked which user it is running as and directory permissions both which are root and have wrx on the user level.
Docker file is below:
FROM fluent/fluentd:v1.14.6-1.1
USER root
RUN apk add --no-cache \
ca-certificates
COPY cert.cer /usr/local/share/ca-certificates/
RUN update-ca-certificates
RUN apk add --update --virtual .build-deps \
build-base ruby-dev
RUN apk add --update mariadb-dev
COPY cert.cer /usr/lib/ruby/3.1.0/rubygems/ssl_certs/cert.cer
RUN gem install fluent-plugin-sql --no-document
RUN gem install mysql2
RUN gem install bigdecimal
RUN gem install elasticsearch -v 7.17.0
RUN gem install --minimal-deps fluent-plugin-elasticsearch
RUN gem source --clear-all
RUN apk del .build-deps
USER fluent
I've tried changing the directory permissions and removing sudo altogether and no luck. Changing to other docker versions has no luck either.

Related

Unable to install ruby from source in ubuntu 18.04 docker image

I am installing ruby 2.7.2 on a docker container that uses ubuntu:18.04.c I first tried to install rbenv but it did not offer the version I need so I resorted to installing from source. However when installing from source the make install does not pass. This is the method I used to install from source https://coderwall.com/p/3u__pq/install-ruby-from-source-on-ubuntu and this is what I looked at to resolve my issues to no avail Unable to locate package openssl-dev. Also I cannot install rvm as it is not picked up by bash.
docker file
#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
#
# Pull base image.
FROM ubuntu:18.04
ARG APP_NAME=<appname>
# Install.
RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential openssl libssl-dev zlib1g-dev&& \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget openssl libffi-dev &&\
rm -rf /var/lib/apt/lists/*
RUN \
wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2 &&\
tar -xf ruby-2.7.2.tar.bz2
RUN cd ruby-2.7.2
RUN pwd
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
RUN make
RUN make install
# Set environment variables.
EXPOSE 5000
ENV HOME /root
ENV PATH="${PATH}:/my/ruby/dir"
# Define working directory.
WORKDIR /root
COPY ${APP_NAME}/ ./${APP_NAME}/
# Define default command.
CMD ["bash"]
When I did make install it is complaining that openssl is not installed however I did do apt install openssl
*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/ruby-2.7.2/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
Check ext/openssl/mkmf.log for more details.
dbm:
Could not be configured. It will not be installed.
Check ext/dbm/mkmf.log for more details.
readline:
Could not be configured. It will not be installed.
/ruby-2.7.2/ext/readline/extconf.rb:62: Neither readline nor libedit was found
Check ext/readline/mkmf.log for more details.
gdbm:
Could not be configured. It will not be installed.
Check ext/gdbm/mkmf.log for more details.
zlib:
Could not be configured. It will not be installed.
Check ext/zlib/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
Later on this is the error message
Traceback (most recent call last):
11: from ./tool/rbinstall.rb:947:in `<main>'
10: from ./tool/rbinstall.rb:947:in `each'
9: from ./tool/rbinstall.rb:950:in `block in <main>'
8: from ./tool/rbinstall.rb:799:in `block in <main>'
7: from ./tool/rbinstall.rb:835:in `install_default_gem'
6: from ./tool/rbinstall.rb:835:in `each'
5: from ./tool/rbinstall.rb:845:in `block in install_default_gem'
4: from ./tool/rbinstall.rb:279:in `open_for_install'
3: from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem'
2: from /ruby-2.7.2/lib/rubygems/specification.rb:2430:in `to_ruby'
1: from /ruby-2.7.2/lib/rubygems/core_ext/kernel_require.rb:92:in `require'
/ruby-2.7.2/lib/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- openssl (LoadError)
I think your problem is here
RUN cd ruby-2.7.2
RUN pwd
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
You cd into ruby-2.7.2 then attempt ./ruby-2.7.2/configure ... but you are already in the directory ruby-2.7.2 so this line
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
should fail.
Try replacing
RUN ./ruby-2.7.2/configure --prefix=/my/ruby/dir
with
RUN ./configure --prefix=/my/ruby/dir
You could clean up your Docerfile a bit as well by removing lines like
RUN pwd

Problem with Jekyll and Nokogiri installation

Im on ubuntu 18.04.2 LTS on Windows, and I have a rudimentary question. My objective is to use github template https://github.com/github/personal-website and publish it to username.github.io
I've a problem with step 4:
Build the site and make it available on a local server
bundle exec jekyll serve
hafidz#LAMBDA05:~/personal-website$ bundle exec jekyll serve
**Could not find nokogiri-1.10.1 in any of the sources**
Run `bundle install` to install missing gems.
It's already a runaround to install bundle, jekyll and nokogori, but i thought have that done. Does it need a path setup?
hafidz#LAMBDA05:~/personal-website$ bundle -v
Bundler version 2.0.1
hafidz#LAMBDA05:~/personal-website$ jekyll -v
Traceback (most recent call last):
12: from /usr/local/bin/jekyll:23:in `<main>'
11: from /usr/local/bin/jekyll:23:in `load'
10: from /var/lib/gems/2.5.0/gems/jekyll-3.8.5/exe/jekyll:11:in `<top (required)>'
9: from /var/lib/gems/2.5.0/gems/jekyll-3.8.5/lib/jekyll/plugin_manager.rb:50:in `require_from_bundler'
8: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler.rb:107:in `setup'
7: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:20:in `setup'
6: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:108:in `block in definition_method'
5: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:226:in `requested_specs'
4: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:237:in `specs_for'
3: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/definition.rb:170:in `specs'
2: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `materialize'
1: from /var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `map!'
/var/lib/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find nokogiri-1.10.1 in any of the sources (Bundler::GemNotFound)
hafidz#LAMBDA05:~/personal-website$ nokogiri -v
# Nokogiri (1.10.1)
---
warnings: []
nokogiri: 1.10.1
ruby:
version: 2.5.3
platform: x86_64-linux-gnu
description: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux-gnu]
engine: ruby
libxml:
binding: extension
source: packaged
libxml2_path: "/var/lib/gems/2.5.0/gems/nokogiri-1.10.1/ports/x86_64-pc-linux-gnu/libxml2/2.9.9"
libxslt_path: "/var/lib/gems/2.5.0/gems/nokogiri-1.10.1/ports/x86_64-pc-linux-gnu/libxslt/1.1.33"
libxml2_patches:
- 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
libxslt_patches: []
compiled: 2.9.9
loaded: 2.9.9
appreciate helps
I saw something similar using Ubuntu WSL. I'd been following the Jekyll WSL instructions and got stuck. There was a nice hint on Dave Rupert's blog (link) that recommended the following and unblocked me: apt install zlibc zlib1g-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev
Here's a dump of my bash history for the session:
24 sudo apt install ruby
26 gem update jekyll
27 code .
28 sudo apt-get update -y && sudo apt-get upgrade -y
30 sudo gem update
31 sudo apt-add-repository ppa:brightbox/ruby-ng
32 sudo apt-get update
33 sudo apt-get install ruby2.5 ruby2.5-dev build-essential dh-autoreconf
35 sudo gem update
37 sudo gem install jekyll bundler
38 jekyll -v
40 sudo bundle update
45 sudo bundle install
47 sudo apt install zlibc zlib1g-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev
48 sudo gem install nokogiri -v '1.8.2' --source 'https://rubygems.org/'
49 sudo bundle install
51 bundle exec jekyll -v
52 bundle exec jekyll serve
54 sudo bundle update
56 bundle exec jekyll serve
57 history
58 history > history.txt

How to correctly load a gem extension in AWS Lambda

I'm having trouble working through a gem load error on AWS Lambda.
{
"errorMessage": "LoadError: libpq.so.5: cannot open shared object file: No such file or directory - /var/task/vendor/bundle/ruby/2.5.0/gems/pg-1.1.4/lib/pg_ext.so",
"errorType": "Function<Sequel::AdapterNotFound>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/pg-1.1.4/lib/pg.rb:4:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/adapters/postgres.rb:6:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/database/connecting.rb:88:in `load_adapter'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/database/connecting.rb:17:in `adapter_class'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/database/connecting.rb:45:in `connect'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/core.rb:121:in `connect'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/core.rb:399:in `adapter_method'",
"/var/task/vendor/bundle/ruby/2.5.0/gems/sequel-5.16.0/lib/sequel/core.rb:406:in `block (2 levels) in def_adapter_method'",
"/var/task/lib/warehouse/loader.rb:5:in `connection'",
"/var/task/lib/warehouse/loader.rb:24:in `initialize'",
"/var/task/lib/warehouse/update.rb:43:in `new'",
"/var/task/lib/warehouse/update.rb:43:in `block in handle'",
"/var/task/lib/warehouse/update.rb:42:in `each'",
"/var/task/lib/warehouse/update.rb:42:in `handle'",
"/var/task/lambda.rb:11:in `handler'"
]
}
I am using the Sequel library to make a PSQL connection from AWS Lambda, but it seems that the function cannot find the so file. I have packaged the dependencies in vendor/bundle, built in Ubuntu on CodeBuild, and verified that the .so file is present in the resulting artifacts uploaded to lambda. I've also edited the $LOAD_PATH, but that doesn't seem to help.
Anyone else encountered this difficulty? Any further tips on resolving or debugging?
Do you have libpq.so.5 on your lib folder?
Your error is saying that did not find libpq.so.5 on the $PATH, in AWS Lambda the folder lib is automatically loaded on the path, thus, you just need to have this file there.
Executables created outside the lambda world do not run on Lambda, furthermore, you need to compile the executables by your own on a Lambda image. This is an example in how to do that:
Gemfile
source "https://rubygems.org"
gem "pg"
gem "mysql2"
handler.rb
require 'pg'
require 'mysql2'
def run(event:, context:)
{
postgres_client_version: PG.library_version,
mysql_client_version: Mysql2::VERSION
}
end
Dockerfile
FROM lambci/lambda:build-ruby2.5
RUN yum install -y postgresql postgresql-devel mysql mysql-devel
RUN gem update bundler
ADD Gemfile /var/task/Gemfile
ADD Gemfile.lock /var/task/Gemfile.lock
RUN bundle install --path /var/task/vendor/bundle --clean
This is going to build your image, then run it to generate the PG and MYSQL executables, then copy it to your lib folder.
build.sh
#!/bin/bash -x
set -e
rm -rf lib && rm -rf vendor && mkdir lib && mkdir vendor
docker build -t pg_mysql_layer -f Dockerfile .
CONTAINER=$(docker run -d pg_mysql_layer false)
docker cp \
$CONTAINER:/var/task/vendor/ \
./
docker cp \
$CONTAINER:/usr/lib64/libpq.so.5.5 \
lib/libpq.so.5
docker cp \
$CONTAINER:/usr/lib64/mysql/. \
lib/
docker rm $CONTAINER
After running ./build.sh it is going to generate the folder lib and vendor with all you need, now you just need to deploy your lambda function.
To test locally you can run:
docker run --rm -it -v $PWD:/var/task -w /var/task lambci/lambda:ruby2.5 handler.run
It is going to return something similar to this:
REF: https://www.stevenringo.com/ruby-in-aws-lambda-with-postgresql-nokogiri/
REF: https://www.reddit.com/r/ruby/comments/a3e7a1/postgresql_on_aws_lambda_ruby/
There are few good plugins to manage dependencies for AWS lambda. serverless-ruby-layer for ruby and serverless-python-requirements for python.
For your ruby case, you can use serverless-ruby-layer simply by adding plugin related config to your serverless.yml.
service: using-docker-yums
plugins:
- serverless-ruby-layer
custom:
rubyLayer:
use_docker: true
docker_yums:
- postgresql-devel
native_libs:
- /usr/lib64/libpq.so.5
provider:
name: aws
runtime: ruby2.5
functions:
hello:
handler: handler.hello
And you need to install the plugin with the below command inside your serverless project folder,
sls plugin install -n serverless-ruby-layer
Now running sls deploy will automatically deploy the gems and libs to the layer.
Check out this example here in the docs
Here's a solution like #ruan-carlos', but in one step and a bit easier to understand.
#!/bin/bash
set -e
cat >Dockerfile <<EOF
FROM public.ecr.aws/lambda/ruby:2.7
RUN yum install -y postgresql-libs
EOF
rm -rf lib
docker build -t pg-layer-source .
mkdir lib
docker create -ti --name dummy pg-layer-source bash
docker cp dummy:/usr/lib64/libpq.so.5.5 lib/libpq.so.5
docker cp dummy:/usr/lib64/libldap_r-2.4.so.2.10.7 lib/libldap_r-2.4.so.2
docker cp dummy:/usr/lib64/liblber-2.4.so.2.10.7 lib/liblber-2.4.so.2
docker cp dummy:/usr/lib64/libsasl2.so.3.0.0 lib/libsasl2.so.3
docker cp dummy:/usr/lib64/libssl3.so lib
docker cp dummy:/usr/lib64/libsmime3.so lib
docker cp dummy:/usr/lib64/libnss3.so lib
docker rm -f dummy
zip -r $(date +%Y-%m-%d-%s)-lib-pg-layer.zip lib
2022 UPDATE using newer pg gem versions:
FROM public.ecr.aws/lambda/ruby:2.7
# Get PostgreSQL 10 available in amazon-linux-extras
RUN yum install -y amazon-linux-extras
RUN amazon-linux-extras enable postgresql10
RUN yum install -y postgresql postgresql-devel
ADD . ${LAMBDA_TASK_ROOT}
ENV GEM_HOME=${LAMBDA_TASK_ROOT}
RUN bundle install
CMD [ "functions.my_function" ]
You will now need to install amazon-linux-extras inside the lambda/ruby:2.7 docker image. This will make available the postgresql10 package. Enable it and then install postgresql-devel. If you try to install postgresql-devel without specifying at least postgresql9.3 or greater, then it will attempt to install PostgreSQL9.2 and the pg gem will raise an error that the version of postgres client is out of date.

Unable to reinstall or uninstall broken brew package(didn't delete anything)

brew cask install android-sdk
Warning: A Cask for android-sdk is already installed.
brew cask reinstall android-sdk
or
brew cask uninstall android-sdk
==> Caveats We will install android-sdk-tools, platform-tools, and build-tools for you. You can control android sdk packages via the
sdkmanager command. You may want to add to your profile: 'export
ANDROID_HOME=/usr/local/share/android-sdk'
This operation may take up to 10 minutes depending on your internet
connection. Please, be patient.
==> Downloading https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
Already downloaded:
/Users/ishandutta2007/Library/Caches/Homebrew/Cask/android-sdk--25.2.3.zip
==> Verifying checksum for Cask android-sdk Error: No such file or directory - /usr/local/share/android-sdk Follow the instructions here:
https://github.com/caskroom/homebrew-cask#reporting-bugs
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:1439:in
`unlink'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:1439:in
`block in remove_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:1444:in
`platform_support'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:1438:in
`remove_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:785:in
`remove_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:563:in
`block in rm'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:562:in
`each'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:562:in
`rm'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:57:in
`block (2 levels) in load'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb:35:in
`instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb:35:in
`block in abstract_phase'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/set.rb:232:in
`each_key'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/set.rb:232:in
`each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb:34:in
`abstract_phase'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb:28:in
`uninstall_phase'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:330:in
`block in uninstall_artifacts'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:327:in
`each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:327:in
`uninstall_artifacts'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:312:in
`uninstall'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb:27:in
`block in install_casks'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb:6:in
`each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb:6:in
`install_casks'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/install.rb:10:in
`run' /usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:115:in
`run_command'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:158:in
`process' /usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:8:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:91:in `<main>'
Tried this but no luck, and I have not deleted anything like mentioned in this question.
I observed no such directory /usr/local/share/android-sdk as the error stated:
$ sudo find /usr -name "android-sdk"
/usr/local/Caskroom/android-sdk
I also ran into these errors:
Error: It seems there is already a Binary at '/usr/local/bin/adb'; not linking.
Error: It seems there is already a Binary at '/usr/local/bin/fastboot'; not linking.
I deleted the mentioned files and then was able to install:
$ rm -rf /usr/local/Caskroom/android-sdk
$ rm -rf /usr/local/bin/adb
$ rm -rf /usr/local/bin/fastboot
$ brew cask install android-sdk
I had a very similar issue after the recent relocation of android-sdk into caskroom/cask managed to break one of my install scripts. I ended up fixing it by manually messing around directly with the cask-installed directories (/usr/local/share/android-sdk, /usr/local/opt/android-sdk, and so on). I either deleted what was there or created empty directories, then re-running the remove/reinstall/delete commands finally worked. Sorry I can't be more specific, but it was basically a case of getting my directories to look like brew expected them to look.

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