Skip to content

Instantly share code, notes, and snippets.

@ryhmrt
Created June 23, 2020 08:50
Show Gist options
  • Save ryhmrt/3c882c0508ebbec516fb038811fd2a7a to your computer and use it in GitHub Desktop.
Save ryhmrt/3c882c0508ebbec516fb038811fd2a7a to your computer and use it in GitHub Desktop.
FROM ruby:2.7.1-alpine3.11 AS base
ENV LANG="C.UTF-8"
ENV RUNTIME_LIBS="mariadb-connector-c tzdata"
ENV BUILD_LIBS="build-base mariadb-connector-c-dev"
ENV WORKSPACE="/opt/app/src"
RUN mkdir -p $WORKSPACE && \
apk add --no-cache $RUNTIME_LIBS
WORKDIR $WORKSPACE
EXPOSE 3000
FROM base AS dev
RUN apk add --no-cache $BUILD_LIBS
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
RUN chmod +x /wait
ENV ENTRYKIT_VERSION 0.4.0
RUN wget https://github.com/progrium/entrykit/releases/download/v${ENTRYKIT_VERSION}/entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& tar -xvzf entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& rm entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz \
&& mv entrykit /bin/entrykit \
&& chmod +x /bin/entrykit \
&& entrykit --symlink
ENTRYPOINT [ \
"prehook", "sh -c /wait", "--", \
"prehook", "bundle install", "--" ]
FROM base AS build
RUN apk add --no-cache $BUILD_LIBS
COPY src/.bundle $WORKSPACE/.bundle
COPY src/Gemfile.cache $WORKSPACE/Gemfile
COPY src/Gemfile.lock.cache $WORKSPACE/Gemfile.lock
RUN bundle install --deployment
COPY src/Gemfile $WORKSPACE
COPY src/Gemfile.lock $WORKSPACE
RUN bundle install --deployment
FROM base
COPY src $WORKSPACE
COPY --from=build $WORKSPACE/vendor $WORKSPACE/vendor
COPY --from=build /usr/local/bundle /usr/local/bundle
RUN addgroup --gid 1000 --system rails && \
adduser \
--disabled-password \
--gecos "" \
--ingroup rails \
--no-create-home \
--uid 1000 \
rails && \
chown -R rails:rails $WORKSPACE
USER rails
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment