ManageIQ / container-ruby

Container with Ruby and built on CentOS, for ManageIQ
Apache License 2.0
2 stars 15 forks source link

image should run in openshift #2

Open durandom opened 7 years ago

durandom commented 7 years ago

I was trying to build upon this image to run a bundled ruby script and was running into various problems:

FROM durandom/container-ruby:latest
MAINTAINER hild@b4mad.net

RUN adduser app

RUN echo "RUBY_GEMS_ROOT=/opt/rubies/raby-2.3.1/lib/ruby/gems/2.3.0" >> /home/app/.bashrc && \
    echo 'PATH=$PATH:/opt/rubies/ruby-2.3.1/bin:/home/app/.gem/ruby/2.3.0/bin' >> /home/app/.bashrc && \
    echo 'export PATH' >> /home/app/.bashrc

COPY app/ /home/app/app
COPY docker-assets/container-entrypoint /home/app/container-entrypoint

RUN chown -R app /home/app/app && chmod 755 /home/app

USER app
WORKDIR /home/app/app
RUN source ~/.bashrc && \
    gem install --user-install bundler && \
    bundle install --path .bundle

ENTRYPOINT ["/home/app/container-entrypoint"]
CMD bundle exec ./persister.rb

The entrypoint just execs

#!/bin/bash

source /home/app/.bashrc
exec "$@"

Openshift assigns a random user to run the image:

This is my last error:

❯ docker run --user=1001 --rm -ti durandom/kafka-client-persister
/usr/bin/id: cannot find name for user ID 1001
/opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'bundler' (>= 0.a) among 11 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/.gem/ruby/2.3.0:/opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0', execute `gem env` for more information
        from /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
        from /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in`gem'
        from /home/app/.gem/ruby/2.3.0/bin/bundle:22:in `<main>'
durandom commented 7 years ago

switching to the ruby onbuild image from docker https://hub.docker.com/_/ruby/ got me running

https://github.com/durandom/manageiq-kafka-client/commit/f5d5dee17497cc7f138309863b83277ed3b8f9c0

carbonin commented 7 years ago

For one it looks like you typoed the RUBY_GEMS_ROOT path: RUBY_GEMS_ROOT=/opt/rubies/raby-2.3.1/lib/ruby/gems/2.3.0

But that's not likely to be causing: /usr/bin/id: cannot find name for user ID 1001

durandom commented 7 years ago

/usr/bin/id: cannot find name for user ID 1001 is negleable here, thats from running the container with an unknown UID. Maybe I left id -a in the entrypoint.sh

The failure is, that /home/app/.gem/... is not in the GEM_PATH and thats where my build installed all gems.

I think I want something as easy as https://github.com/durandom/manageiq-kafka-client/blob/master/persister/Dockerfile to build a container with my ruby script / app.

Not sure if thats a use case for our base ruby container. I'm fine with the docker ruby onbuild container for now...