heroku / docker-ruby

Ruby image for the heroku-docker project
17 stars 30 forks source link

Split onbuild and base in to two images #5

Open jmervine opened 9 years ago

jmervine commented 9 years ago

For local development, where someone doesn't want to build their code in to a container, but rather mount their code in, it could awesome if we could split these in to two images...

This will allow for people to do things like: docker run --rm -it -v $(pwd):. heroku/ruby-base:2.2.2 bash and enter a development environment, without building their code in. Super useful to me, not sure about everyone else.

Something like (but untested):

base: heroku/ruby-base:{ruby_version}

# file:Dockerfile-base
FROM heroku/cedar:14
MAINTAINER Terence Lee <terence@heroku.com>

ENV RUBY_VERSION=2.2.3
ENV RUBY_MAJOR=2.2.2
ENV NODE_VERSION=0.12.7

RUN mkdir -p /app/user
WORKDIR /app/user

ENV GEM_PATH /app/heroku/ruby/bundle/ruby/${RUBY_MAJOR}
ENV GEM_HOME /app/heroku/ruby/bundle/ruby/${RUBY_MAJOR}
RUN mkdir -p /app/heroku/ruby/bundle/ruby/${RUBY_MAJOR}

# Install Ruby
RUN mkdir -p /app/heroku/ruby/ruby-${RUBY_VERSION}
RUN curl -s --retry 3 -L https://heroku-buildpack-ruby.s3.amazonaws.com/cedar-14/ruby-${RUBY_VERSION}.tgz | tar xz -C /app/heroku/ruby/ruby-${RUBY_VERSION}
ENV PATH /app/heroku/ruby/ruby-${RUBY_VERSION}/bin:$PATH

# Install Node
RUN curl -s --retry 3 -L http://s3pository.heroku.com/node/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz | tar xz -C /app/heroku/ruby/
RUN mv /app/heroku/ruby/node-v${NODE_VERSION}-linux-x64 /app/heroku/ruby/node-${NODE_VERSION}
ENV PATH /app/heroku/ruby/node-${NODE_VERSION}/bin:$PATH

# Install Bundler
RUN gem install bundler -v 1.9.10 --no-ri --no-rdoc
ENV PATH /app/user/bin:/app/heroku/ruby/bundle/ruby/${RUBY_MAJOR}/bin:$PATH

onbuild: heroku/ruby:{ruby_version}

# file:Dockerfile
FROM heroku/ruby-base:latest

ENV BUNDLE_APP_CONFIG /app/heroku/ruby/.bundle/config

# Run bundler to cache dependencies
ONBUILD COPY ["Gemfile", "Gemfile.lock", "/app/user/"]
ONBUILD RUN bundle install --path /app/heroku/ruby/bundle --jobs 4
ONBUILD ADD . /app/user

# How to conditionally `rake assets:precompile`?
ONBUILD ENV RAILS_ENV production
ONBUILD ENV SECRET_KEY_BASE $(openssl rand -base64 32)
ONBUILD RUN bundle exec rake assets:precompile

# export env vars during run time
RUN mkdir -p /app/.profile.d/
RUN echo "cd /app/user/" > /app/.profile.d/home.sh
ONBUILD RUN echo "export PATH=\"$PATH\" GEM_PATH=\"$GEM_PATH\" GEM_HOME=\"$GEM_HOME\" RAILS_ENV=\"\${RAILS_ENV:-$RAILS_ENV}\" SECRET_KEY_BASE=\"\${SECRET_KEY_BASE:-$SECRET_KEY_BASE}\" BUNDLE_APP_CONFIG=\"$BUNDLE_APP_CONFIG\"" > /app/.profile.d/ruby.sh

COPY ./init.sh /usr/bin/init.sh
RUN chmod +x /usr/bin/init.sh

ENTRYPOINT ["/usr/bin/init.sh"]
paulodiovani commented 8 years ago

:+1:

itsmeduncan commented 8 years ago

Would this allow developers also to add pre-requisites to their Dockerfile? For local development, we need to run capybara-webkit which has an upstream dependency on qt5. There is currently no way to do this today... #10 :sob:

paulodiovani commented 8 years ago

@itsmeduncan No. This PR is to allow running a container without building an image.

paulodiovani commented 8 years ago

@itsmeduncan Docker does not allow to change ONBUILD steps neither add extra steps before they. If you need different dependencies/steps, the solution if to create your own Dockerfile from heroku/cedar:14, as I did in paulodiovani/docker-heroku-ruby