Skip to content

Commit

Permalink
make docker image smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Sep 26, 2020
1 parent 23744ee commit 65c3e17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 65c3e17

Please sign in to comment.