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

View File

@ -23,7 +23,7 @@ gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# gem 'mini_racer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3.3'
@ -121,7 +121,7 @@ end
gem 'remote_syslog_logger'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'tzinfo-data'
gem 'coveralls', require: false

View File

@ -153,7 +153,6 @@ GEM
railties (>= 3.2.16)
json (2.2.0)
jwt (2.2.1)
libv8 (7.3.492.27.1)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@ -173,8 +172,6 @@ GEM
mimemagic (0.3.3)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
mini_racer (0.2.6)
libv8 (>= 6.9.411)
minitest (5.11.3)
msgpack (1.3.0)
multi_json (1.13.1)
@ -326,6 +323,8 @@ GEM
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo-data (1.2019.3)
tzinfo (>= 1.0.0)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.6.0)
@ -369,7 +368,6 @@ DEPENDENCIES
jquery-ui-rails
listen (~> 3.0.5)
lograge
mini_racer
net-ldap
omniauth
omniauth-bn-launcher!

View File

@ -26,7 +26,7 @@ class ThemesController < ApplicationController
lighten_color = @settings.get_value("Primary Color Lighten") || Rails.configuration.primary_color_lighten_default
darken_color = @settings.get_value("Primary Color Darken") || Rails.configuration.primary_color_darken_default
file_name = Rails.root.join('app', 'assets', 'stylesheets', 'utilities', '_primary_themes.scss')
file_name = Rails.root.join('lib', 'assets', '_primary_themes.scss')
@file_contents = File.read(file_name)
# Include the variables and covert scss file to css

View File

@ -19,6 +19,4 @@ else
bundle exec rake db:schema:load
fi
bundle exec rake assets:precompile
exec bundle exec puma -C config/puma.rb

View File

@ -143,5 +143,5 @@ Rails.application.configure do
config.active_record.dump_schema_after_migration = false
# Set the relative url root for deployment to a subdirectory.
config.relative_url_root = ENV['RELATIVE_URL_ROOT'] || "/b" if ENV['RELATIVE_URL_ROOT'] != "/"
config.relative_url_root = ENV['RELATIVE_URL_ROOT'].present? ? ENV['RELATIVE_URL_ROOT'] : "/b"
end

View File

@ -13,4 +13,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
Rails.application.config.assets.precompile += %w(pickr.min.js monolith.min.scss)
Rails.application.config.assets.precompile += %w(_primary_theme.scss pickr.min.js monolith.min.scss)