From 65c3e171f6104598831c51c92cda43736957bdde Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Sat, 26 Sep 2020 14:14:16 +1000 Subject: [PATCH] make docker image smaller --- Dockerfile | 33 +++++++++++++++++++++++++++------ Gemfile | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index dbc7df9..e641b77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,35 @@ -FROM ruby:2.7 +FROM ruby:2.7-alpine AS build-env + +WORKDIR /usr/src/app + +# Upgrade +RUN apk update --no-cache + +COPY Gemfile Gemfile.lock ./ +RUN bundle config --global frozen 1 \ + && bundle config --local deployment true \ + && bundle config --local path vendor/bundle \ + && bundle config --local without development \ + && bundle config --local jobs 5 \ + && bundle install \ + && rm -rf vendor/bundle/ruby/2.7.0/cache/*.gem \ + && find vendor/bundle/ruby/2.7.0/gems/ -name "*.c" -delete \ + && find vendor/bundle/ruby/2.7.0/gems/ -name "*.o" -delete + +COPY amber-electric.rb . + +# Main image +FROM ruby:2.7-alpine ENV INFLUXDB_HOSTNAME influxdb ENV INFLUXDB_DATABASE amber_electric WORKDIR /usr/src/app -RUN bundle config --global frozen 1 -COPY Gemfile Gemfile.lock ./ -RUN bundle install +# Upgrade +RUN apk update --no-cache -COPY . . +COPY --from=build-env /usr/src/app /usr/src/app +COPY --from=build-env /usr/local/bundle/config /usr/local/bundle/config -CMD ["./amber-electric.rb"] +CMD ["bundle", "exec", "./amber-electric.rb"] diff --git a/Gemfile b/Gemfile index 0fac012..aebf07f 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,10 @@ source 'https://rubygems.org' git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } +gem 'amazing_print' gem 'httparty' gem 'influxdb' group :development do - gem 'amazing_print' gem 'rubocop' end