From bc8f53aaf507fecd65cc1424c50365be3d5d70a8 Mon Sep 17 00:00:00 2001 From: Henrik Nygren Date: Wed, 2 May 2018 16:54:48 +0300 Subject: [PATCH] Add docker compose for production deployments --- Dockerfile | 24 ++++++++++++++++++++++++ config/application.rb | 4 ++-- config/environments/production.rb | 2 +- docker-compose.yml | 11 +++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c72a1c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM xqdocker/ubuntu-ruby-2.0 + +RUN apt-get update && \ + apt-get install -y nodejs build-essential libpq-dev sqlite3 libsqlite3-dev --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* && \ + echo "user:x:1000:1000:user:/:/sbin/nologin" >> /etc/passwd + +WORKDIR /app + +COPY Gemfile Gemfile +COPY Gemfile.lock Gemfile.lock + +RUN bundle config build.nokogiri --use-system-libraries && \ + bundle install --jobs=3 --retry=3 + +COPY . /app + +EXPOSE 3000 + +RUN chown -R user /app + +USER user + +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/config/application.rb b/config/application.rb index e489116..bf1558c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,9 +4,9 @@ if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) + # Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) + Bundler.require(:default, :assets, Rails.env) end module Labtool diff --git a/config/environments/production.rb b/config/environments/production.rb index 95cd75c..3bb91d2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.compress = true diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d7e73ac --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.2" +services: + web: + build: . + command: rails s --binding 0.0.0.0 + ports: + - "3000:3000" + environment: + - RAILS_ENV=production + stdin_open: true + tty: true