GRN2-241: Switched Docker base image to Alpine (#853)

* Switched to alpine image

* Switch Docker base image to alpine

* Removed uneeded code

* Slimmed it down even further
This commit is contained in:
Ahmad Farhat
2020-01-09 14:13:14 -05:00
committed by farhatahmad
parent c13a83a3f3
commit 734f7a757e
8 changed files with 52 additions and 30 deletions

View File

@ -1,34 +1,60 @@
FROM ruby:2.5
FROM ruby:2.5.1-alpine AS base
# Install app dependencies.
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev curl
ADD https://dl.yarnpkg.com/debian/pubkey.gpg /tmp/yarn-pubkey.gpg
RUN apt-key add /tmp/yarn-pubkey.gpg && rm /tmp/yarn-pubkey.gpg && \
echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && apt-get install -y nodejs yarn
# Set an environment variable for the install location.
ENV RAILS_ROOT /usr/src/app
# Set a variable for the install location.
ARG RAILS_ROOT=/usr/src/app
# Set Rails environment.
ENV RAILS_ENV production
ENV BUNDLE_APP_CONFIG="$RAILS_ROOT/.bundle"
# Make the directory and set as working.
RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT
# Set Rails environment.
ENV RAILS_ENV production
ARG BUILD_PACKAGES="build-base curl-dev git"
ARG DEV_PACKAGES="postgresql-dev sqlite-libs sqlite-dev yaml-dev zlib-dev nodejs yarn"
ARG RUBY_PACKAGES="tzdata"
# Install app dependencies.
RUN apk update \
&& apk upgrade \
&& apk add --update --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
COPY Gemfile* ./
RUN bundle install --without development test --deployment --clean
COPY Gemfile Gemfile.lock $RAILS_ROOT/
RUN bundle config --global frozen 1 \
&& bundle install --deployment --without development:test:assets -j4 --path=vendor/bundle \
&& rm -rf vendor/bundle/ruby/2.5.0/cache/*.gem \
&& find vendor/bundle/ruby/2.5.0/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/2.5.0/gems/ -name "*.o" -delete
# Adding project files.
COPY . .
# Precompile assets
RUN SECRET_KEY_BASE="$(bundle exec rake secret)" bundle exec rake assets:clean
RUN SECRET_KEY_BASE="$(bundle exec rake secret)" bundle exec rake assets:precompile
RUN SECRET_KEY_BASE="1" bin/rails assets:precompile
# Remove folders not needed in resulting image
RUN rm -rf tmp/cache app/assets vendor/assets spec
############### Build step done ###############
FROM ruby:2.5.1-alpine
# Set a variable for the install location.
ARG RAILS_ROOT=/usr/src/app
ARG PACKAGES="tzdata postgresql-client sqlite-libs nodejs bash"
ENV RAILS_ENV=production
ENV BUNDLE_APP_CONFIG="$RAILS_ROOT/.bundle"
WORKDIR $RAILS_ROOT
RUN apk update \
&& apk upgrade \
&& apk add --update --no-cache $PACKAGES
COPY --from=base $RAILS_ROOT $RAILS_ROOT
# Expose port 80.
EXPOSE 80