FROM ruby:2.6.3-alpine AS base ARG BUILD_PACKAGES="build-base git" ARG DEV_PACKAGES="postgresql-dev yarn" ARG RUBY_PACKAGES="tzdata" RUN apk update && \ apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES RUN mkdir /app WORKDIR /app ################################################################################ FROM base AS builder # Copying the Gemfile separately allows the image to be cached. # These steps are not rerun unless the Gemfile or Gemfile.lock is changed. COPY Gemfile Gemfile.lock /app/ RUN bundle install --jobs 4 --retry 5 # Again, copy seperately so we can cache this step. COPY package.json yarn.lock /app/ RUN yarn install && yarn cache clean # Copy our app over now #COPY . /app COPY bin/ /app/bin COPY .rspec .ruby-version Rakefile /app/ COPY vendor/ /app/vendor COPY config.ru /app/config.ru COPY config/ /app/config #COPY config/database.yml.docker /app/config/database.yml COPY public/ /app/public COPY db/ /app/db COPY app/assets/ /app/app/assets COPY app/javascript/ /app/app/javascript COPY lib/ /app/lib #COPY app/ /app/app #COPY spec/ /app/spec # Copy the docker configuration to the correct location #COPY config/database.yml.docker config/database.yml # Compile our assets, moving unneeded directories out of way for the prod image # after compilation has completed. RUN rails assets:precompile --trace && \ rm -rf tmp/cache log && \ mkdir -p /var/cache/app/app && \ mv node_modules /var/cache/app && \ mv app/assets /var/cache/app/app && \ mv app/javascript /var/cache/app/app ################################################################################ FROM base AS dev COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ COPY --from=builder /app/ /app/ COPY --from=builder /var/cache/app/ /app/ COPY lib/ /app/lib COPY app/ /app/app COPY spec /app/spec ################################################################################ FROM base AS prod ENV RAILS_ENV=production # Install only required gems for production, and remove any uneccesary build # packages RUN bundle install --jobs 4 --retry 5 --without development test && \ apk rm $BUILD_PACKAGES $DEV_PACKAGES COPY bin/ /app/bin COPY .rspec .ruby-version Rakefile /app/ COPY vendor/ /app/vendor COPY config.ru /app/config.ru COPY config/ /app/config COPY config/database.yml.docker /app/config/database.yml COPY public/ /app/public COPY db/ /app/db COPY lib/ /app/lib COPY app/ /app/app COPY --from=builder public/ /app/public # Run the server EXPOSE 3000 CMD ["rails", "server", "-b", "0.0.0.0"]