Docker failed to build on Rails bundle Install rake - ruby-on-rails

I use Docker for Windows which I use to run a Image for a Rails(v5) App.
When I do docker-compose build I get this error. I don't known where to look to debug and/or resolve this.
Here is my Dockerfile:
FROM ruby:2.3.3-slim
RUN apt-get update && apt-get install -y build-essential
RUN apt-get install -y libmysqlclient-dev
RUN apt-get install -y mysql-client
RUN apt-get install -y libmagickwand-dev imagemagick
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y git
#RUN npm install -g phantomjs
RUN gem update --system
RUN mkdir -p /MyImage
WORKDIR /MyImage
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN gem install bundler
RUN bundle install
COPY package.json package.json
RUN npm update
RUN npm install
COPY . /MyImage
CMD [ "foreman", "start" ]
Here is a log if my error:
Step 15/20 : RUN bundle install
---> Running in 4bf360b89cb7
The git source `git://github.com/acrogenesis/owlcarousel-rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/sinatra/sinatra.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Fetching source index from https://rubygems.org/
Fetching source index from https://rails-assets.org/
Fetching git://github.com/sinatra/sinatra.git
Fetching git://github.com/acrogenesis/owlcarousel-rails.git
Fetching gem metadata from https://rails-assets.org/..
Fetching rake 12.1.0
Installing rake 12.1.0
Errno::ENOENT: No such file or directory # rb_sysopen -
/usr/local/lib/ruby/site_ruby/2.3.0/bundler/templates/Executable
An error occurred while installing rake (12.1.0), and Bundler cannot continue.
Make sure that `gem install rake -v '12.1.0'` succeeds before bundling.
In Gemfile:
autonumeric-rails was resolved to 2.0.0.1, which depends on
jquery-rails was resolved to 4.3.1, which depends on
railties was resolved to 5.0.6, which depends on
rake
ERROR: Service 'MyImage' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 5
But when I do gem install rake -v '12.1.0' directly into the shell of my container, everything install just fine.

Just try to install rake by yourself as described in the error message:
gem install rake -v '12.1.0'
To debug:
Comment out all lines in your Dockerfile starting from RUN bundle install and to end;
Then run docker build -t test:0.0 .;
To start interactive session: docker run -it test:0.0 /bin/bash;
Try to execute gem install rake -v '12.1.0' manually...

Related

"Could not find rake-12.3.3 in any of the sources."

I tried running these commands:
gem uninstall rake
rm Gemfile.lock
bundle install
gem install rake --version=12.3.3
I also tried adding rake 12.3.3 to the gemfile and running bundle install:
gem 'rake', '12.3.3'
This is my Dockerfile:
FROM ruby
RUN apt-get update -qq && apt-get install -y build-essential
# for postgres
RUN apt-get install -y libpq-dev
# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev
# for a JS runtime
RUN apt-get install -y nodejs
ENV APP_HOME /readpaths
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
RUN bundle install
ADD . $APP_HOME
I've just noticed something curios: No matter how often I run gem uninstall rake (I tried five times) I always get a message saying:
Successfully uninstalled rake-12.3.1
When I run gem install rake I get:
Successfully installed rake-12.3.3
Then, when I run gem uninstall rake again, I get again:
Successfully uninstalled rake-12.3.1
If you come to this error because of Heroku/Jekyll, this is how I fixed it:
Make sure you only have this buildpack: https://github.com/heroku/heroku-buildpack-ruby
Make sure your dyno is actually on
Your Procfile should have this: web: jekyll serve --no-watch --port $PORT --host 0.0.0.0
Make sure your have PORT configured in the config vars section of your settings
Try rebuilding the docker container.

Error building docker image with Dockerfile

I’m trying to build docker image with a configuration in Dockerfile:
FROM ubuntu
MAINTAINER axiom88guru(axiom88guru#gmail.com)
Configuration for app below.
Run upgrades
RUN apt-get update
Install basic packages
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
Install Ruby
RUN apt-get -qq -y install ruby-full
RUN gem install bundler --no-ri --no-rdoc
RUN gem install foreman
Install rails-new-docker
WORKDIR /app
RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
RUN bundle install --without development test
Run rails-new-docker
ENV SECRET_KEY_BASE dockerkeybase
ENV RAILS_ENV production
EXPOSE 5959
CMD foreman start -f Procfile
When I run these commands in bash they work as expected, but not during docker build:
Removing intermediate container 344e99851852
Step 8/14 : WORKDIR /app
—> 3c204a395f23
Removing intermediate container 680b1841a3fc
Step 9/14 : RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
—> Running in d7a9de9f6ab5
/bin/sh: 1: git: not found
The command ‘/bin/sh -c git clone https://github.com/axiom88-guru/rails-docker.git /app’ returned a non-zero code: 127
Could anyone help me find out the solution please?
Need to have git installed since the base ubuntu image provides only a minimal set of installed packages (this is done to keep image size small).
FROM ubuntu
MAINTAINER axiom88guru(axiom88guru#gmail.com)
# Configuration for app below.
# Run upgrades
RUN apt-get update
# Install basic packages
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs git
# Install Ruby
RUN apt-get -qq -y install ruby-full
RUN gem install bundler --no-ri --no-rdoc
RUN gem install foreman
# Install rails-new-docker
WORKDIR /app
RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
RUN bundle install --without development test
# Run rails-new-docker
ENV SECRET_KEY_BASE dockerkeybase
ENV RAILS_ENV production
EXPOSE 5959
CMD foreman start -f Procfile
This version should work. I just added git to the first apt-get install step.

ImageMagick on Google Cloud

I use ImageMagick on the Google Cloud Platform. I use rails and Google's App Engine Flexible Environment. So the problem is I want to upload an Image to process in more sizes. I use paperclip.
The error is:
Could not run the identify command. Please install ImageMagick.
So my question is how I can solve this issue? Uploading a Image without processing works 100%. But the issue is the processing I think. So paperclip needs ImageMagick to process the images.
The problem is I use App Engine Flexible Environment so I am not sure how to install it. I already tried it with apt-get install imageMagick
Okay really simple you need just a Dockerfile.
# This Dockerfile for a Ruby application was generated by gcloud.
# The base Dockerfile installs:
# * A number of packages needed by the Ruby runtime and by gems
# commonly used in Ruby web apps (such as libsqlite3)
# * A recent version of NodeJS
# * A recent version of the standard Ruby runtime to use by default
# * The bundler and foreman gems
FROM gcr.io/google_appengine/ruby
# Install ruby 2.3.0 if not already preinstalled by the base image
RUN cd /rbenv/plugins/ruby-build && \
git pull && \
rbenv install -s 2.3.0 && \
rbenv global 2.3.0 && \
gem install -q --no-rdoc --no-ri bundler --version 1.11.2 && \
gem install -q --no-rdoc --no-ri foreman --version 0.78.0
ENV RBENV_VERSION 2.3.0
# To install additional packages needed by your gems, uncomment
# the "RUN apt-get update" and "RUN apt-get install" lines below
# and specify your packages.
# RUN apt-get update
# RUN apt-get install imagemagick -y
RUN apt-get update && apt-get install imagemagick -y
# Install required gems.
COPY Gemfile Gemfile.lock /app/
RUN bundle install && rbenv rehash
# Start application on port 8080.
COPY . /app/
ENTRYPOINT bundle exec rackup -p 8080 -E production config.ru
After that just run gcloud preview app deploy and it will work for you.
Don't forget to change in your app.yaml runtime: ruby to runtime: custom
That's it happy coding 🎉

Installed gems not found by bundler when BUNDLE_PATH changed with Docker

I'm using docker to develop a rails application. The docker file looks like this:
FROM ruby:1.9.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev vim
ENV APP_HOME /next-reg
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ENV BUNDLE_PATH /box
ADD . $APP_HOME
RUN gem install gem1.gem gem2.gem
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
As you can see I change the BUNDLE_PATH, this is because of an article showing how we can persist gem downloads. So that overtime when the docker cache gets warm, it re-bundles and takes FOREVER.
When I docker build it successfully installs the gems, then it fails to find them on bundle. Could someone give me a hand with persisting gems, installing my own gems, and getting it to work?
Before I changed the BUNDLE_PATH the build worked, it just re bundled frequently without changes to the gem file (because, I guess the docker image cache got warm).
My docker-compose is like this:
db:
image: postgres
volumes:
- ~/.docker-voumes/postgres/data:/var/lib/postgresql/data
# This is to hold and persist ruby gems, referenced in web and in web's dockerfile.
gem_files:
image: busybox
volumes:
- /box
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/next-reg
volumes_from:
- gem_files
ports:
- "3000:3000"
- "8000:8000"
links:
- db
env_file:
- .myenv.env
I think that there is a lack of GEM_HOME/GEM_PATH in your code.
GEM_HOME/GEM_PATH will be used by gem install xxx to install gems in a specific folder.
BUNDLE_PATH will be used by bundle install to install gems in a specific folder but not by gem install xx
To have a working system you should do :
FROM ruby:1.9.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev vim
ENV APP_HOME /next-reg
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ENV BUNDLE_PATH /box
ENV GEM_PATH /box
ENV GEM_HOME /box
ADD . $APP_HOME
RUN gem install bundler
RUN gem install tzinfo -v 1.2.2
COPY Gemfile Gemfile
RUN bundle install
With this Gemfile :
source 'https://rubygems.org'
gem 'tzinfo', '1.2.2'
Wich will produce :
Step 11/13 : RUN gem install tzinfo -v 1.2.2
---> Running in 8a87fa54fa19
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.2
2 gems installed
---> 3c91d59bde8a
Removing intermediate container 8a87fa54fa19
Step 13/13 : RUN bundle install
---> Running in 20f1e4ec93b1
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.
Fetching gem metadata from https://rubygems.org/...
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Rubygems 1.8.23.2 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Installing rake 12.0.0
Using thread_safe 0.3.6
Using bundler 1.14.6
Using tzinfo 1.2.2
Bundle complete! 2 Gemfile dependencies, 4 gems now installed.
Bundled gems are installed into /box.
As you can see in the result output, the bundle install re-use the preloaded gems from gem install

bundler installed gems not persisting in fig/docker

I am trying to use fig and docker to set up a local development environment for an existing rails app.
In the build process, I clearly see bundler installing the app's gems, but when I try to start the container with fig up or even reopen it with the /bin/bash command, the gems are not visible.
Here is the Dockerfile:
FROM ubuntu:14.04
# REPOS
RUN apt-get -qq update
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"
RUN add-apt-repository -y ppa:chris-lea/node.js
RUN apt-get -y update
#INSTALL
RUN apt-get install -y -q build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison pkg-config libpq-dev make wget unzip git vim nano nodejs gawk libgdbm-dev libffi-dev
#RUBY
RUN mkdir -p /download
WORKDIR download
RUN wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
RUN tar xvfz ruby-2.1.2.tar.gz
WORKDIR /download/ruby-2.1.2
RUN ./configure
RUN make
RUN make install
RUN gem update --system
RUN gem install bundler
RUN mkdir /rent
WORKDIR /rent
ADD Gemfile /rent/Gemfile
ADD Gemfile.lock /rent/Gemfile.lock
RUN bundle install --deployment
And here is the fig.yml file:
web:
build: .
command: bundle exec rails s -p 3000
volumes:
- .:/rent
ports:
- "3000:3000"
Running fig build clearly shows the app's gems being installed.
Running fig up fails with the message
bundler: command not found: rails
If I run fig run web /bin/bash and check the contents of
/local/lib/ruby/gems/2.1.0/gems
it only has bundler, rdoc, rake and a few others installed.
If I navigate to the app's directory and run the bundle command, it will install the app's gems and I can see that they are installed in the directory above. I can even start the app with rails server.
Why aren't the bundled gems being persisted in the image(container?).
I ran the rails tutuorial from the fig website and didn't have this problem.
Thanks
It seems that the problem was caused by using the --deployment flag with bundle install.
This flag's main effect is to deploy the gems to the vendor/bundle/ directory instead of the normal gem location. I checked and the gems were there, so I'm not sure why ruby couldn't find them.
Anyways, removing --deployment fixed the problem.
If you're using fig and mounted volumes, I found a solution which allows updates to the mounted files in development (like Gemfile.lock when you do fig run web bundle install) while still keeping container caching behavior.
See this for the full thing: https://gist.github.com/fotinakis/04077671bec4edf77c08
It's slightly convoluted, but basically you always install bundler and the gems as the non-root application user:
# Add 'web' user which will run the application.
RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos ""
# Add directory where all application code will live and own it by the web user.
RUN mkdir /app
RUN chown -R web:web /app
# Install gems separately here to take advantage of container caching of `bundle install`.
# Also, ensure that gems are installed as the web user and not system-wide so that we can run
# `fig web bundle install` and the web user will have permissions to update the shared Gemfile.lock.
ADD Gemfile /app/
ADD Gemfile.lock /app/
RUN chown -R web:web /app
USER web
ENV HOME /home/web
ENV PATH $PATH:/home/web/.gem/ruby/2.1.0/bin
ENV GEM_HOME /home/web/.gem/ruby/2.1.0
ENV GEM_PATH $GEM_HOME
RUN gem install --user-install bundler
WORKDIR /app/
RUN bundle install
USER root
# Add the whole application source to the image and own it all by web:web.
# Note: this is overwritten in development because fig mounts a shared volume at /app.
ADD . /app/
RUN chown -R web:web /app
Running this will now work and update your local Gemfile.lock:
$ fig run web bundle install

Resources