Skip to content

Commit

Permalink
Simplify docker, shrink production image size! (#409)
Browse files Browse the repository at this point in the history
* lets not load keycloak into our docker image

* cleanups on Docker

* tweak

* Fix the case of the missing tmp/pids, slight optimization to dev
dockerfile

* simplify gem setup, older racc works native with our Ruby 2x

* trying buster not slim-buster again

* lint

* this change drops us to 1.48 GB

Co-authored-by: [email protected] <>
Co-authored-by: Daniel Worley <[email protected]>
  • Loading branch information
epugh and worleydl authored Sep 25, 2021
1 parent 1d505f2 commit 19c4a90
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Dockerfile*
.github
.circleci/**/*
.circleci

# Keycloak config files (not used by Quepid)
keycloak
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
/tmp/*
!/tmp/pids
/tmp/pids/*
!/tmp/pids/.keep

# Ignore bower artifacts
/vendor/assets/bower_components
Expand Down
11 changes: 3 additions & 8 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM ruby:2.7.4-buster

LABEL maintainer="[email protected]"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ENV home .

# Must have packages
Expand All @@ -24,16 +22,13 @@ RUN apt-get update -qq \

# may not need libgbm


# Install Node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
# Node and Yarn
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get update -qq && apt-get install -y --no-install-recommends nodejs yarn netcat \
&& rm -rf /var/lib/apt/lists/*

COPY . /srv/app/

# Clean environment
RUN apt-get clean all
42 changes: 31 additions & 11 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.17.3-buster AS build-dep
FROM node:15.14.0-buster AS build-dep
WORKDIR /srv/app
COPY package.json yarn.lock ./
RUN yarn install --production=true
Expand All @@ -7,16 +7,16 @@ FROM ruby:2.7.4-buster

LABEL maintainer="[email protected]"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Must have packages
RUN apt-get update -qq && apt-get install -y --no-install-recommends vim curl git tmux apt-transport-https ca-certificates \
# The next line is a list of dependencies if we move to slim-buster, however it only shaves 80MB off the image.
# mariadb-server libmariadbclient-dev mariadb-client mysql-common ruby-mysql2 libmariadbd-dev build-essential patch ruby-dev zlib1g-dev liblzma-dev gnupg
RUN apt-get update -qq && apt-get install -y --no-install-recommends vim curl apt-transport-https ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install Node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
# Node and Yarn
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand All @@ -32,17 +32,37 @@ RUN apt-get update \
WORKDIR /srv/app
COPY Gemfile Gemfile.lock ./
RUN gem install bundler:1.17.3
#RUN bundle install

# Clean up Bundle
RUN bundle install --without development test && \
RUN bundle config set without 'development test'
RUN bundle install && \
bundle clean --force && \
rm -rf /app/.bundle/cache && \
rm -rf /app/vendor/bundle/ruby/*/cache

COPY --from=build-dep /srv/app/node_modules ./node_modules/
COPY . .
#COPY . .
COPY ./app ./app
COPY ./app.json ./app.json
COPY ./babel.config.js ./babel.config.js
COPY ./bin ./bin
COPY ./config ./config
COPY ./config.ru ./config.ru
COPY ./db ./db
COPY ./Gemfile ./Gemfile
COPY ./Gemfile.lock ./Gemfile.lock
COPY ./lib ./lib
COPY ./LICENSE ./LICENSE
COPY ./package.json ./package.json
COPY ./postcss.config.js ./postcss.config.js
COPY ./Procfile ./Procfile
COPY ./public ./public
COPY ./Rakefile ./Rakefile
COPY ./README.md ./README.md
COPY ./vendor ./vendor
COPY ./yarn.lock ./yarn.lock

RUN mkdir -p tmp/pids
RUN mkdir -p tmp/pids

RUN RAILS_ENV=production SECRET_KEY_BASE=fake_out_devise bundle exec rake assets:precompile

Expand Down
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ gem 'font-awesome-sass'
gem 'webpacker', '= 5.4.0'
gem 'rack-cors', '~> 1.1'
gem 'foreman'
gem 'racc', '~> 1.4.0'
gem 'ancestry'

group :development, :test do
gem 'annotate'
gem 'bullet'
gem 'byebug'
gem 'memory_profiler'
# rubocop:disable Layout/LineLength
gem 'rack-mini-profiler', git: 'https://github.com/MiniProfiler/rack-mini-profiler' # pending release with PR 505 included
# rubocop:enable Layout/LineLength
gem 'rack-mini-profiler', '>= 2.3.3'
end

group :development do
Expand Down
14 changes: 5 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
GIT
remote: https://github.com/MiniProfiler/rack-mini-profiler
revision: 5f29900d977e690d03a0acd3609f9f6b43c18b7f
specs:
rack-mini-profiler (2.3.2)
rack (>= 1.2.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -260,10 +253,12 @@ GEM
puma (>= 2.7)
pundit (2.1.1)
activesupport (>= 3.0.0)
racc (1.5.2)
racc (1.4.16)
rack (2.2.3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-mini-profiler (2.3.3)
rack (>= 1.2.0)
rack-protection (2.1.0)
rack
rack-proxy (0.7.0)
Expand Down Expand Up @@ -433,8 +428,9 @@ DEPENDENCIES
puma (~> 5.0)
puma_worker_killer
pundit
racc (~> 1.4.0)
rack-cors (~> 1.1)
rack-mini-profiler!
rack-mini-profiler (>= 2.3.3)
rails (= 6.1.4.1)
rails-controller-testing
rails-erd (~> 1.6)
Expand Down
Empty file added tmp/pids/.keep
Empty file.

0 comments on commit 19c4a90

Please sign in to comment.