Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Split onbuild and base in to two images #5

@jmervine

Description

@jmervine

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"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions