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

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.

Related

Install Bundler failed in Ruby Docker image

I have a very old project I'm giving support. I'm using docker to make my builds and everything was working until this last one try.
This is my Dockerfile:
FROM ruby:2.1
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
git \
ghostscript \
libgs-dev \
build-essential \
libmysqlclient-dev \
locales \
nodejs
# Use en_US.UTF-8 as our locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
COPY vendor/oohlalog_gem ./vendor/oohlalog_gem
RUN gem install bundler && bundle install
# Copy the main application.
COPY . ./
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# Configure an entry point, so we don't need to specify
# "bundle exec" for each of our commands.
ENTRYPOINT ["bundle", "exec"]
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["rails", "server", "-b", "0.0.0.0"]
When I try to run:
docker build . -t my_image
I'm getting:
Step 11 : RUN gem install bundler && bundle install
---> Running in 7f8e7442b423 ERROR: Error installing bundler:
bundler requires Ruby version >= 2.3.0.
I don't know how to fix this.
This is a result of a release of a new Bundler version 2.0.0 that happened on January 03, 2019. According to GitHub issue this is a desired behaviour.
As this is an old and not maintained anymore project the best option for you would be using older bundler.
You can modify the line from your Dockerfile:
RUN gem install bundler && bundle install
to the following:
RUN gem install bundler -v '$OLD_BUNDLER_VERSION' && bundle install
where $OLD_BUNDLER_VERSION should be set to last known working version, i.e. 1.16.1
Try a newer version of ruby image as your base. You are using 2.1 ( FROM ruby:2.1 ) but you need ruby version 2.3.0
My way is to use the correct bundler version and run it like this:
ENV BUNDLER_VERSION 2.2.26
RUN gem update --system \
&& gem install bundler -v $BUNDLER_VERSION \
&& bundle install -j 4

Docker failed to build on Rails bundle Install rake

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...

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 🎉

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