From a6e861da8ec77ff474f0d710d1918d9b27db8667 Mon Sep 17 00:00:00 2001 From: Max Fierke Date: Fri, 6 Dec 2019 15:43:10 -0600 Subject: [PATCH 1/3] Run Docker under Ruby 2.6.5 and use an alpine image --- .ruby-version | 2 +- Dockerfile | 58 +++++++++++++++++++++++++++++----------- docker/litmus_unicorn.rb | 3 --- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.ruby-version b/.ruby-version index f3a9c9a..57cf282 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -1.9.3-p194 +2.6.5 diff --git a/Dockerfile b/Dockerfile index 24e757f..72a76a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,48 @@ -FROM debian:stretch +FROM ruby:2.6.5-alpine3.11 + EXPOSE 9293/TCP EXPOSE 9294/TCP -WORKDIR /home/litmus_paper -RUN apt-get update && apt-get install -y ruby ruby-dev git curl rsyslog build-essential -RUN gem install --no-ri --no-rdoc bundler \ - && gem install sinatra --no-ri --no-rdoc --version "~> 1.3.2" \ - && gem install remote_syslog_logger --no-ri --no-rdoc --version "~> 1.0.3" \ - && gem install unicorn --no-ri --no-rdoc --version "~> 4.6.2" \ - && gem install colorize --no-ri --no-rdoc \ - && gem install rspec --no-ri --no-rdoc --version "~> 2.9.0" \ - && gem install rack-test --no-ri --no-rdoc --version "~> 0.6.1" \ - && gem install rake --no-ri --no-rdoc --version "~> 0.9.2.2" \ - && gem install rake_commit --no-ri --no-rdoc --version "~> 0.13" -ADD . /home/litmus_paper -RUN ln -sf /home/litmus_paper/docker/litmus.conf /etc/litmus.conf \ - && ln -sf /home/litmus_paper/docker/litmus_unicorn.rb /etc/litmus_unicorn.rb + +ENV APP_USER litmus_paper +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +RUN apk add --update --no-cache \ + build-base \ + linux-headers \ + tzdata \ + rsyslog \ + libgcc libstdc++ \ + git \ + curl \ + procps + +# Create non-root user +RUN addgroup -g 1000 -S $APP_USER && \ + adduser -u 1000 -S $APP_USER -G $APP_USER -D + +ADD litmus_paper.gemspec /home/$APP_USER/ +ADD lib/litmus_paper/version.rb /home/$APP_USER/lib/litmus_paper/version.rb +ADD Gemfile* /home/$APP_USER/ + +WORKDIR /home/$APP_USER + +RUN bundle config --global frozen 1 && \ + bundle install \ + -j2 \ + --retry 3 \ + # Remove unneeded files (cached *.gem, *.o, *.c) + && rm -rf /usr/local/bundle/cache/*.gem \ + && find /usr/local/bundle/gems/ -name "*.c" -delete \ + && find /usr/local/bundle/gems/ -name "*.o" -delete + +ADD . /home/$APP_USER +RUN ln -sf /home/$APP_USER/docker/litmus.conf /etc/litmus.conf \ + && ln -sf /home/$APP_USER/docker/litmus_unicorn.rb /etc/litmus_unicorn.rb RUN gem build litmus_paper.gemspec && gem install litmus_paper*.gem +RUN chown -R $APP_USER:$APP_USER /home/$APP_USER + +# Drop to app user +USER $APP_USER CMD ["bin/litmus", "-p", "9293", "-c", "/etc/litmus_unicorn.rb"] diff --git a/docker/litmus_unicorn.rb b/docker/litmus_unicorn.rb index 2ac6673..bd59964 100644 --- a/docker/litmus_unicorn.rb +++ b/docker/litmus_unicorn.rb @@ -1,10 +1,7 @@ # vim: set ft=ruby require 'remote_syslog_logger' -APP_ROOT = '/var/lib/gems/2.3.0/gems/litmus_paper-1.1.1' - worker_processes 5 -working_directory APP_ROOT logger(RemoteSyslogLogger.new('127.0.0.1', 514, :program => 'litmus_paper', :facility => 'daemon')) From 9956eae4519e07af179f28f45db9a1c2aaff894c Mon Sep 17 00:00:00 2001 From: Max Fierke Date: Tue, 7 Jan 2020 16:16:57 -0600 Subject: [PATCH 2/3] Use slim-buster base image instead --- Dockerfile | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72a76a6..ab010cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,29 @@ -FROM ruby:2.6.5-alpine3.11 +FROM debian:buster-slim EXPOSE 9293/TCP -EXPOSE 9294/TCP ENV APP_USER litmus_paper ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 -RUN apk add --update --no-cache \ - build-base \ - linux-headers \ - tzdata \ - rsyslog \ - libgcc libstdc++ \ - git \ - curl \ - procps +RUN apt-get update && apt-get install -y --no-install-recommends \ + ruby \ + ruby-dev \ + bundler \ + git \ + curl \ + rsyslog \ + procps \ + build-essential \ + && rm -rf /var/lib/apt/lists/* # Create non-root user -RUN addgroup -g 1000 -S $APP_USER && \ - adduser -u 1000 -S $APP_USER -G $APP_USER -D +RUN addgroup --gid 1000 --system $APP_USER && \ + adduser --uid 1000 --ingroup $APP_USER --system $APP_USER + +ENV GEM_HOME /usr/local/bundle +ENV BUNDLE_APP_CONFIG $GEM_HOME +ENV PATH $GEM_HOME/bin:$PATH ADD litmus_paper.gemspec /home/$APP_USER/ ADD lib/litmus_paper/version.rb /home/$APP_USER/lib/litmus_paper/version.rb From 8b4331f0cd196d27045022bea6c01da9f4e1b7fc Mon Sep 17 00:00:00 2001 From: Max Fierke Date: Tue, 7 Jan 2020 16:17:39 -0600 Subject: [PATCH 3/3] Fix port inconsistency in Docker image's litmus config --- docker/litmus.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/litmus.conf b/docker/litmus.conf index b41644e..65a6af2 100644 --- a/docker/litmus.conf +++ b/docker/litmus.conf @@ -1,4 +1,4 @@ -port 9292 +port 9293 data_directory '/tmp/litmus_paper' cache_location '/tmp/litmus_paper_cache' cache_ttl -1