Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUNDLER_VERSION not picked up with ruby 2.5.1-slim base image #32

Open
vrinek opened this issue Feb 9, 2021 · 9 comments
Open

BUNDLER_VERSION not picked up with ruby 2.5.1-slim base image #32

vrinek opened this issue Feb 9, 2021 · 9 comments

Comments

@vrinek
Copy link

vrinek commented Feb 9, 2021

I've tried using dockerdev with the 2.5.1-slim-stretch base docker image and it kept using v1.16 for bundler.

After a little digging, I noticed that the base image explicitly defines the BUNDLER_VERSION as an environment variable: https://hub.docker.com/layers/ruby/library/ruby/2.5.1-slim/images/sha256-f05f349dcb24a2e4d556fc95476753348e4678503689422cd093de7067ea59c5?context=explore

ENV BUNDLER_VERSION=1.16.6

The same issue is not present in the 2.6.3-slim-buster base image.

I am not sure how to fix this elegantly. For now, I have renamed my ARG to not conflict with BUNDLER_VERSION but I cannot consider this optimal.

Any other ideas on how to mitigate this for ruby 2.5.1?

@oliverklee
Copy link
Contributor

@vrinek Have you updated the image version in the Docker compose file? (This might be necessary for Docker to use the changed environment variables.)

@elalemanyo
Copy link

Hi,
I am using RUBY_VERSION: "2.6.5" and I can not install bundler 🤷‍♂️
This is the error that I get when I try to run bundler:

Traceback (most recent call last):
	2: from /usr/local/bin/bundler:23:in `<main>'
	1: from /usr/local/lib/ruby/site_ruby/2.6.0/rubygems.rb:300:in `activate_bin_path'
/usr/local/lib/ruby/site_ruby/2.6.0/rubygems.rb:281:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`

I remove all bundler block and use just: RUN gem install bundler --no-document -v $BUNDLER_VERSION, and bundler was there but not the version that I told to install...

What I am doing wrong?

Thanks!

@palkan
Copy link
Member

palkan commented May 6, 2021

@elalemanyo The problem is with your Gemfile.lock; how did it get into the Docker image? It shouldn't be there at the time of building it.

@elalemanyo
Copy link

@palkan I am almost doing the same way, I did some changes 🙈 All the docker files (Dockerfile, docker-compose.yml) are inside a folder (.docker). I like to have all stuff there, because not all dev team are using docker and is for the moment just for dev. But besides that is almost the same, just a little bit easier.
Dockerfile:

ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-slim-buster

ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION

# Common dependencies
RUN apt-get update -qq \
  && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    build-essential \
    gnupg2 \
    curl \
    less \
    git \
    shared-mime-info \
  && apt-get clean \
  && rm -rf /var/cache/apt/archives/* \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
  && truncate -s 0 /var/log/*log

# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
  && echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list

# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -

# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list

# Install dependencies
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    libpq-dev \
    postgresql-client-$PG_MAJOR \
    nodejs \
    yarn=$YARN_VERSION-1 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
    truncate -s 0 /var/log/*log

# Configure bundler
ENV LANG=C.UTF-8 \
  BUNDLE_JOBS=4 \
  BUNDLE_RETRY=3

# Upgrade RubyGems and install required Bundler version
# See https://github.com/evilmartians/terraforming-rails/pull/24 for discussion
RUN gem update --system && \
    rm /usr/local/lib/ruby/gems/*/specifications/default/bundler-*.gemspec && \
    gem uninstall bundler && \
    gem install bundler -v $BUNDLER_VERSION

# Create a directory for the app code
RUN mkdir -p /app

WORKDIR /app

and docker-compose.yml:

version: "3.9"

services:
  web:
    container_name: ${PROJECT_NAME}-web
    build:
      context: .
      dockerfile: Dockerfile
      args:
        RUBY_VERSION: "2.6.5"
        NODE_MAJOR: "12"
        YARN_VERSION: "1.13.0"
        BUNDLER_VERSION_CUSTOM: "1.17.3"
        PG_MAJOR: "13"
    command: bash -c "rm -f tmp/pids/server.pid && BIND=0.0.0.0 PORT=3000 bin/server"
    environment:
      POSTGRES_HOST: ${POSTGRES_HOST}
      POSTGRES_USER: ${POSTGRES_USER}
      DATABASE_URL: postgres://postgres:postgres@postgres:5432
      SOLR_HOST: "solr"
      SOLR_PORT: 8983
      WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
      NODE_ENV: ${NODE_ENV:-development}
      RAILS_ENV: ${RAILS_ENV:-development}
      YARN_CACHE_FOLDER: /app/node_modules/.yarn-cache
    tmpfs:
      - /tmp
    volumes:
      - ../:/app:cached
      - ./data/bundle:/usr/local/bundle:delegated
      - rails_cache:/app/tmp/cache:delegated
      - node_modules:/app/node_modules:delegated
      - packs:/app/public/packs:delegated

    ports:
      - "3000:3000"
      - "3035:3035"
    depends_on:
      - postgres
      - solr
    stdin_open: true
    tty: true

  postgres:
    container_name: ${PROJECT_NAME}-postgres
    image: postgres:13
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    volumes:
      - ./data/postgres:/var/lib/postgresql/data:delegated
    ports:
      - "5432:5432"

  solr:
    container_name: ${PROJECT_NAME}-solr
    image: solr:6
    ports:
      - "8983:8983"
    volumes:
      - ../solr/configsets/sunspot:/opt/solr/server/solr/configsets/sunspot:delegated
      - ./data/solr:/opt/solr/server/solr/mycores:delegated
    entrypoint:
      - docker-entrypoint.sh
      - solr-precreate # execute solr-precreate script with the parameters below
      - development # core name
      - /opt/solr/server/solr/configsets/sunspot # custom configset
    depends_on:
      - postgres

volumes:
  node_modules:
  rails_cache:
  packs:

thanks for your help

@palkan
Copy link
Member

palkan commented May 6, 2021

Could not find 'bundler' (1.17.3) required by your /app/Gemfile.lock

As far as I understand, the image is build successfully, the exception is raised during bundle install, right?

Then, you should either specify the same version for the Docker image as in your Gemfile.lock or remove the BUNDLED_WITH from the Gemfile.lock and try to run bundle install again.

@elalemanyo
Copy link

@palkan the error is just when I try to check the bundle version 🤷‍♂️, the interesting thing ist that if I remove all bundler stuff from the Dockerfile and check the bundle version I get 1.17.2, maybe is the one that I am getting by default?

@palkan
Copy link
Member

palkan commented May 6, 2021

when I try to check the bundle version

Try to run bundle version outside of the project root. Bundler verifies the version in Gemfile.lock for any command.

@elalemanyo
Copy link

@palkan out of the project root I get this error:

root@0f5e3d748315:/# bundle -v
Traceback (most recent call last):
	2: from /usr/local/bin/bundle:23:in `<main>'
	1: from /usr/local/lib/ruby/site_ruby/2.6.0/rubygems.rb:300:in `activate_bin_path'
/usr/local/lib/ruby/site_ruby/2.6.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

@elalemanyo
Copy link

@palkan now works. I was so stupid and BUNDLER_VERSION was set als string 🙈
image

After doing this change I can install the correct bundler version like this:

RUN gem update --system && \
    gem install bundler:$BUNDLER_VERSION

thanks for all the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants