PureDevOps Community

Base Dockerfile for Ruby on Rails Application

I want to have a base dockerfile for ROR application along with other dependant libraries ?

Here is the Dockerfile that can be referred,

FROM heroku/heroku:16-build.v16

ARG VAR_UID=1000
ARG STACK_BUNDLER_VERSION=1.17.3
ARG STACK_NODE_VERSION=12.18.4
ARG STACK_RUBY_VERSION=2.5.8
ARG STACK_YARN_VERSION=1.19.2

# Install Ruby
RUN git clone --depth=1 https://github.com/rbenv/ruby-build.git \
    && ruby-build/install.sh \
    && RUBY_CONFIGURE_OPTS=--disable-install-doc ruby-build $STACK_RUBY_VERSION /usr/local \
    && rm -rf ruby-build

# Create non-root user
# https://devcenter.heroku.com/articles/container-registry-and-runtime#run-the-image-as-a-non-root-user
#
RUN USER_NAME=flek && \
    UID=$VAR_UID && \
    GID=$VAR_UID && \
    groupadd --gid $GID $USER_NAME && \
    useradd --uid $UID --gid $GID --shell /bin/bash -m $USER_NAME && \
    chown -R $USER_NAME:$USER_NAME /usr/local

USER flek
ENV HOME /home/flek
WORKDIR $HOME
ENV PATH=$HOME/bin:$PATH \
    BUNDLE_DISABLE_VERSION_CHECK=1

# Install Bundler and other gems not installed in rails app
#
RUN \
  echo 'gem: --no-document' > .gemrc && \
  gem install bundler --version $STACK_BUNDLER_VERSION && \
  gem install faraday --version 0.15.4 --no-document && \
  gem install danger --version 5.7.0 --no-document && \
  gem install bundler-audit --no-document

# Install Node
#
RUN \
  wget https://nodejs.org/download/release/v$STACK_NODE_VERSION/node-v$STACK_NODE_VERSION-linux-x64.tar.gz &&\
  mkdir -p $HOME/node/ && \
  tar -C $HOME/node --strip-components 1 -xzf node-v$STACK_NODE_VERSION-linux-x64.tar.gz && \
  rm node-v$STACK_NODE_VERSION-linux-x64.tar.gz
ENV PATH $HOME/node/bin:$PATH

# install yarn
RUN npm install -g yarn

# install wait-for-it
RUN cd /tmp \
    && wget https://github.com/vishnubob/wait-for-it/archive/master.zip \
    && unzip master.zip \
    && mv wait-for-it-master/wait-for-it.sh /usr/local/bin \
    && rm master.zip \
    && rm -r wait-for-it-master

ENV STACK_BUNDLE_CORES=3 \
    ENV=local-docker \
    APP_ROOT=/home/app

RUN mkdir -p $APP_ROOT


WORKDIR $APP_ROOT

CMD ["/bin/bash"]