Bitbucket Pipelines - Failed to build gem native extension - ruby-on-rails

Am I missing build tools in my configuration file?
I'm trying to integrate Bitbucket Pipelines with a Ruby project.
I am unable to build native gem extensions. My C knowledge is limited. If anyone has experience with this input is appreciated. The build fails where trying to install faraday
Installing faraday 0.9.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
Makefile:241: recipe for target 'fast.o' failed
make: *** [fast.o] Error 1
make failed, exit code 2
My bitbucket-piplines.yml looks like
image: ruby:2.4.0
pipelines:
default:
- step:
caches:
- bundler
script:
- echo $PRIVATE_KEY > ~/.ssh/id_rsa.tmp
- base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- base64 ~/.ssh/id_rsa
- gem install oj -v '2.9.9'
- gem install faraday -v '0.9.2'
- bundle config git.allow_insecure true
- bundle install
- bundle exec rspec
definitions:
caches:
bundler: ./vendor

So it was an issue with my Ruby version. Fixnum is no longer a function in Ruby 2.4. It was a matter of downgrading the Ruby Docker image, or updating the failing gems. I downgraded while I'm getting my tests set up to image: ruby:2.3.4

Related

Gitlab CI/CD Job fails when installing Bundler

I want to run the tests after every commit. When installing the bundler, however, the following error message appears: "You must use Bundler 2 or greater with this lockfile" although I install version 2.2.5
stages:
- test
test-job:
stage: test
image: ruby:2.5.1
script:
- gem install bundler -v 2.2.5
- bundle install
- bundle exec rails test
bundler 1.16.6 is included in ruby:2.5.1 and is used per default as you can see here:
$ gem list bundler
bundler (2.2.5, 1.16.6, default: 1.16.2)
Try this instead:
test-job:
stage: test
image: ruby:2.5.1
before_script:
- gem update --system
script:
- bundle install
- bundle exec rails test

bundler: Using a custom path while using system gems is unsupported

I am using GitLab-CI/CD to build my Rails application. I have noticed my builds are failing due to Using a custom path while using system gems is unsupported error, which were working perfectly fine before.
Tried to check newer update releases but didn't find any issues. Does any one have any idea on recent updates or somthing on mentioned issue?
Bellow is my gitlab-ci.yml
variables:
GIT_SUBMODULE_STRATEGY: recursive
cache:
key: ${CI_JOB_NAME}
paths:
- vendor/ruby
before_script:
- apt-get update -qq
- ruby -v
- which ruby
- gem --version
- git --version
- gem update --system 2.7.6
- gem install bundler -v 2.0.1
- bundle -v
- bundle config ${REPO_URL} ${BUNDLE_GITLAB__TOKEN}
- bundle config --global disable_shared_gems true
- bundle install --jobs $(nproc) "${FLAGS[#]}" --path vendor
rubocop:
tags:
- rubocop
script:
- bundle exec rubocop
# rspec:
# stage: test
# script:
# - bundle exec rspec
And bellow is the brief error I'm getting
$ apt-get update -qq
$ ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
$ which ruby
/usr/local/bin/ruby
$ gem --version
3.0.3
$ git --version
git version 2.20.1
$ gem update --system 2.7.6
Updating rubygems-update
Successfully installed rubygems-update-2.7.6
Installing RubyGems 2.7.6
Bundler 1.16.1 installed
RubyGems 2.7.6 installed
Regenerating binstubs
------------------------------------------------------------------------------
RubyGems installed the following executables:
/usr/local/bin/gem
/usr/local/bin/bundle
RubyGems system software updated
$ gem install bundler -v 2.0.1
Successfully installed bundler-2.0.1
1 gem installed
$ bundle -v
Bundler version 2.0.1
$ bundle config https://gitlab.com/dharshannn/test-star.git ${BUNDLE_GITLAB__TOKEN}
$ bundle config --global disable_shared_gems true
$ bundle install --jobs $(nproc) "${FLAGS[#]}" --path vendor
Using a custom path while using system gems is unsupported.
path:
Set for your local app (/usr/local/bundle/config): "vendor"
path.system:
Set via BUNDLE_PATH__SYSTEM: true
disable_shared_gems:
Set for the current user (/root/.bundle/config): true
ERROR: Job failed: exit code 1
The same happened to me today. I am pretty sure that there was no update to bundler or gem. The Docker image however has been updated (I was using ruby:2.6.3). I also added a new dependency when this started happening, so I suspect it was dependent on a gem which was already installed in the system path thus the error message.
You can get around it by specifying the following configuration variables in your .gitlab-ci.yml:
variables:
BUNDLE_DISABLE_SHARED_GEMS: "true"
BUNDLE_PATH__SYSTEM: "false"
This will configure Bundler to not use shared gems and disable system gems fully.
See https://bundler.io/v2.0/bundle_config.html
disable_shared_gems (BUNDLE_DISABLE_SHARED_GEMS): Stop Bundler from accessing gems installed to RubyGems' normal location.
and
path.system (BUNDLE_PATH__SYSTEM): Whether Bundler will install gems into the default system path (Gem.dir).

GitLab Hosted Ruby Version Issue

I'm testing out a simple Rails project with hosted GitLab. My repository has Ruby version 2.3.0 and Rails version 5.0.1. I created the basic gitlab-ci.yml file with the below code for CI. When GitLab goes to run this file through the pipeline to add it I get the error:
activesupport-5.0.1 requires ruby version >= 2.2.2, which is incompatible with
the current version, ruby 2.1.10p492
I'm not sure how to change the version of Ruby that GitLab is using. Any suggestions on how to resolve this issue?
gitlab-ci.yml
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler --no-ri --no-rdoc
- bundle install --jobs $(nproc) "${FLAGS[#]}"
rspec:
script:
- bundle exec rspec
rubocop:
script:
- bundle exec rubocop
You define the environment in which the code is run by using a Docker image.
Try adding
image: ruby:2.3.0
to the top of your .gitlab-ci.yml file

Deployment to Elastic Beanstalk fails with 'Cannot allocate memory' error

I built a rails application that I want to deploy to elastic beanstalk. I was able to deploy it to my AWS account but now I want to deploy it to my clients account. For some reason it I get errors when trying to deploy it. Have been able to deploy it to my account from scratch and been able to deploy it to heroku but every time I try to deploy it to my clients account I get a bunch of errors. Are there possible settings that would be different between the two accounts? I don't understand why deploying to the two accounts would be any different. I have tried every solution I could find.
Here are the logs. I am not sure if they will help
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
gem 'puma'
group :development, :test do
gem "letter_opener"
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
# gem 'pg'
gem 'rails_12factor'
end
+ '[' -d /var/app/ondeck/vendor/cache ']'
+ bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Warning: the running version of Bundler is older than the version that created the lockfile. We sugg
est you upgrade to the latest version of Bundler by running `gem install bundler`.
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Using rake 11.1.2
Using i18n 0.7.0
Installing json 1.8.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-1pc5aw8.rb extconf.rb
Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-1pc5aw8.rb extcon
f.rb 2>&1
Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/json-1.8.3 for in
spection.
Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/js
on-1.8.3/gem_make.out
Using minitest 5.9.0
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using pkg-config 1.1.7
Using rack 1.6.4
Using mime-types-data 3.2016.0521
Using arel 6.0.3
Using execjs 2.7.0
Installing bcrypt 3.1.10 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-myt7e8.rb extconf.rb
Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-myt7e8.rb extconf.rb 2>&1
Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/bcrypt-3.1.10 for inspection.
Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/bcrypt-3.1.10/gem_make.out
Using sass 3.4.22
Using coffee-script-source 1.10.0
Using thor 0.19.1
Using concurrent-ruby 1.0.2
Using multi_json 1.12.1
Using libv8 3.16.14.15
Installing puma 3.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-kv1g4s.rb extconf.rb
Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-kv1g4s.rb extconf.rb 2>&1
Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/puma-3.4.0 for inspection.
Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/puma-3.4.0/gem_make.out
Using bundler 1.12.1
Using rails_serve_static_assets 0.0.5
Using rails_stdout_logging 0.0.4
Using ref 2.0.0
Using tilt 2.0.5
Installing sqlite3 1.3.11 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-5lnc3v.rb extconf.rb
Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-5lnc3v.rb extconf.rb 2>&1
Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11 for inspection.
Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/sqlite3-1.3.11/gem_make.out
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling. (Executor::NonZeroExitStatus)
[2016-07-08T19:47:55.300Z] INFO [424] - [Application update app-d3f5-160708_124551#2/AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
[2016-07-08T19:47:55.301Z] INFO [424] - [Application update app-d3f5-160708_124551#2/AppDeployStage0/AppDeployPreHook] : Activity failed.
[2016-07-08T19:47:55.301Z] INFO [424] - [Application update app-d3f5-160708_124551#2/AppDeployStage0] : Activity failed.
[2016-07-08T19:47:55.302Z] INFO [424] - [Application update app-d3f5-160708_124551#2] : Completed activity. Result:
Application update - Command CMD-AppDeploy failed
[2016-07-08T20:17:06.267Z] INFO [1271] - [CMD-TailLogs] : Starting activity...
[2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/TailLogs] : Starting activity...
[2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...
I found that the answer from #osazemeu based on the blog article needed a tweak, because the container_commands execute too late (after the application was already set up), and thus it was never run.
I changed the container_command into a command (see this AWS documentation for detail on the difference between the two), and also created the file inline rather than having a separate .sh file since I didnt want to have to keep track of what directory that was being put in at deployment time. I called the file 01setup_swap.config and placed in the directory .ebextensions in the root of my project. This did the trick for me. The contents is as follows:
files:
"/home/ec2-user/setup_swap.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
# based on http://steinn.org/post/elasticbeanstalk-swap/
SWAPFILE=/var/swapfile
SWAP_MEGABYTES=2048
if [ -f $SWAPFILE ]; then
echo "Swapfile $SWAPFILE found, assuming already setup"
exit;
fi
/bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES
/bin/chmod 600 $SWAPFILE
/sbin/mkswap $SWAPFILE
/sbin/swapon $SWAPFILE
commands:
01setup_swap:
command: "bash setup_swap.sh"
cwd: "/home/ec2-user/"
Just ran in to this error. Here is what I learned and how I got passed this issue:
With the free tier of AWS elastic beanstalk, by default the EC2 instance type you get, as of the date of this answer, is t1.micro. t1.micro has a very small amount of memory. So little that the gem install process for this gem fails as it is evident by the post. t1.micro is now considered a previous generation instance type (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html). To get past this memory allocation failure, you must update the EC2 instance of your AWS elastic beanstalk app from t1.micro to t2.micro. This worked for me.
I encountered similar issues a couple of days back and this was how I solved it. Only proceed to the next step if the present step fails.
Step 1:
Increase the swap memory of your ElasticBean EC2 instance
yourapp/.ebextensions/setup_swap.sh
#!/bin/bash
SWAPFILE=/var/swapfile
SWAP_MEGABYTES=2048
if [ -f $SWAPFILE ]; then
echo "Swapfile $SWAPFILE found, assuming already setup"
exit;
/bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES
/bin/chmod 600 $SWAPFILE
/sbin/mkswap $SWAPFILE
/sbin/swapon $SWAPFILE
Step 1.1 In your yourapp/.ebextensions/01_setup_swap.config
container_commands:
01setup_swap:
command: "bash .ebextensions/swap/setup_swap.sh"
source: elasticbeanstalk-swap
Step 2:
Increase the size of your ElasticBeanstalk instance, and try to deploy again.
Step 3:
If all else fails, run this command in your rails app.
bundle exec bundle package
This compiles the gems and saves it to a local folder (vendor/cache) in your rails app. This folder is accessed during deployment, and there will be no for compilation.
Commit these files to your repo, and attempt to deploy. It should work without hitches.

Travis build fails in Yeoman Angular generated app

I'm not being able to build an angular application generated with Yeoman using angular-generator. It fails when uses compass gem. I've already added the compass gem installation to the build descriptor.
This is my .travis.yml file:
language: node_js
node_js:
- '0.8'
- '0.10'
before_script:
- 'gem update --system'
- 'gem install compass'
- 'npm install -g bower grunt-cli'
- 'bower install'
The error I'm getting is the following:
Warning: /home/travis/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sass/script/node (LoadError)
I solved similar problem following this link.
In short, I put the following versions in the .travis.yml file:
'gem install sass --version "=3.2.12"'
'gem install compass --version "=0.12.2"'

Resources