From 4a8bd8ee7d1579686f0f0ddf0c7cacb960050f61 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Tue, 10 Apr 2018 01:08:38 +0000 Subject: [PATCH 1/8] Update ensl.org for docker version Create docker version - Remove rubyracer, use nodejs - Add Makefile and fig.yml examples - Update to v2 circle.yml sample - Create Dockerfile - Do not use nested folders in tmp for puma --- .dockerignore | 1 + Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ Gemfile | 6 ++++-- Makefile | 28 ++++++++++++++++++++++++++++ circle.yml | 4 ---- config/database.yml | 2 +- config/puma.rb | 16 ++++++++-------- fig.yml | 9 +++++++++ 8 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile delete mode 100644 circle.yml create mode 100644 fig.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e1b6af5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM ruby:2.2 + +ENV RAILS_ENV production + +# Add 'web' user which will run the application +RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos "" + +RUN apt-get update && apt-get -y upgrade +RUN apt-get -y install mysql-client libmysqlclient-dev memcached nodejs + +# Separate Gemfile ADD so that `bundle install` can be cached more effectively + +ADD Gemfile /var/www/ +ADD Gemfile.lock /var/www/ +RUN chown -R web:web /var/www &&\ + mkdir -p /var/bundle &&\ + chown -R web:web /var/bundle + +RUN bundle config github.https true +RUN su -c "cd /var/www && bundle install --path /var/bundle" -s /bin/bash -l web + +# Add application source +ADD . /var/www +RUN chown -R web:web /var/www + +USER web + +# Precompile assets + +WORKDIR /var/www +COPY .env /var/www/ +RUN bundle install --path /var/bundle +RUN bundle exec rake assets:precompile + +# When using bash +USER root + +CMD ["bundle", "exec", "puma", "-C /var/www/config/puma.rb"] diff --git a/Gemfile b/Gemfile index 978b2d0..0ce571a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'http://rubygems.org' -ruby '2.2.2' +ruby '2.2.10' +#ruby '2.2.2' gem 'dotenv-rails', '~> 0.10.0' gem 'rails', '~> 3.2.22' @@ -8,6 +9,7 @@ gem 'mysql2', '~> 0.3.17' gem 'dalli', '~> 2.7.0' gem 'puma', '~> 2.11.1' +gem 'i18n-js' gem 'exceptional', '~> 2.0.33' gem 'oj', '~> 2.5.5' gem 'faraday', '~> 0.9.0' @@ -27,7 +29,7 @@ gem 'test-unit', '~> 3.1.3' gem 'google-api-client', '~> 0.10.3' # Please install nodejs locally. -gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' +#gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' gem 'sprockets', '~> 2.2.1' gem 'coffee-rails', '~> 3.2.2' diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..08c8123 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +PROJECT ?= abevoelker/example_rails_docker_ci +TAG ?= latest + +ifdef REGISTRY + IMAGE=$(REGISTRY)/$(PROJECT):$(TAG) +else + IMAGE=$(PROJECT):$(TAG) +endif + +all: + @echo "Available targets:" + @echo " * build - build a Docker image for $(IMAGE)" + @echo " * pull - pull $(IMAGE)" + @echo " * push - push $(IMAGE)" + @echo " * test - build and test $(IMAGE)" + +build: Dockerfile + docker build -t $(IMAGE) . + +pull: + docker pull $(IMAGE) || true + +push: + docker push $(IMAGE) + +test: build + fig run web ./env/test.sh ./test.sh + diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 4a2665c..0000000 --- a/circle.yml +++ /dev/null @@ -1,4 +0,0 @@ -database: - override: - - mv config/database.circle.yml config/database.yml - - bundle exec rake db:create db:schema:load --trace diff --git a/config/database.yml b/config/database.yml index b91e757..b2dfeb0 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,7 +1,7 @@ base: &db adapter: mysql2 encoding: utf8 - host: localhost + host: <%= ENV['MYSQL_HOST'] || 'localhost' %> database: <%= ENV['MYSQL_DATABASE'] %> username: <%= ENV['MYSQL_USERNAME'] %> password: <%= ENV['MYSQL_PASSWORD'] %> diff --git a/config/puma.rb b/config/puma.rb index d5b690d..98409b2 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -2,24 +2,24 @@ require "dotenv" Dotenv.load base_path = (ENV['DEPLOY_PATH'] || Dir.pwd) -current_path = "#{base_path}/current" -shared_path = "#{base_path}/shared" -stderr_path = "#{shared_path}/log/puma.stderr.log" -stdout_path = "#{shared_path}/log/puma.stdout.log" +#current_path = "#{base_path}/current" +#shared_path = "#{base_path}/shared" +stderr_path = "#{base_path}/lpuma.stderr.log" +stdout_path = "#{base_path}/lpuma.stdout.log" tag 'ENSL' preload_app! daemonize true -directory current_path -pidfile "#{shared_path}/tmp/pids/puma.pid" -state_path "#{shared_path}/tmp/pids/puma.state" +directory base_path +pidfile "#{base_path}/tmp/puma.pid" +state_path "#{base_path}/tmp/puma.state" stdout_redirect stdout_path, stderr_path environment ENV['RACK_ENV'] || 'production' rackup DefaultRackup -bind "unix://#{shared_path}/tmp/sockets/puma.sock" +bind "unix://#{base_path}/tmp/puma.sock" port Integer(ENV['PUMA_PORT'] || 4000) worker_timeout Integer(ENV['PUMA_TIMEOUT'] || 30) diff --git a/fig.yml b/fig.yml new file mode 100644 index 0000000..314632f --- /dev/null +++ b/fig.yml @@ -0,0 +1,9 @@ +web: + image: ensl/ensl.org + links: + - mysql + - redis +mysql: + image: mysql +redis: + image: redis From 3984ad2442f2feca43174165f21ff840f7248bde Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sat, 14 Apr 2018 13:02:58 +0000 Subject: [PATCH 2/8] Fix docker image Fix bunch of things with docker and add entry.sh --- .gitignore | 1 + Dockerfile | 13 +++++++++---- config/application.rb | 1 + config/database.yml | 2 +- config/environments/production.rb | 5 ++++- entry.sh | 6 ++++++ fig.yml | 12 +++++++----- 7 files changed, 29 insertions(+), 11 deletions(-) create mode 100755 entry.sh diff --git a/.gitignore b/.gitignore index c9d3f82..b782149 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /log/* /tmp/* /spec/tmp/* +/env/* .ruby-version .ruby-gemset .env diff --git a/Dockerfile b/Dockerfile index e1b6af5..ea536ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,10 +29,15 @@ USER web WORKDIR /var/www COPY .env /var/www/ -RUN bundle install --path /var/bundle -RUN bundle exec rake assets:precompile +RUN bundle install --path /var/bundle --jobs 4 +#RUN bundle exec rake assets:precompile -# When using bash USER root -CMD ["bundle", "exec", "puma", "-C /var/www/config/puma.rb"] +RUN apt-get install -y memcached +RUN service memcached start + +#USER root + +USER web +CMD ["/var/www/entry.sh"] diff --git a/config/application.rb b/config/application.rb index aaa2b35..1ce42b6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,7 @@ module Ensl # Additional assets config.assets.precompile += ["themes/*/theme.css", "themes/*/errors.css"] + config.assets.initialize_on_precompile = false # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += Dir["#{config.root}/app/services/**/", "#{config.root}/app/models/concerns/"] diff --git a/config/database.yml b/config/database.yml index b2dfeb0..bb0011b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,7 +1,7 @@ base: &db adapter: mysql2 encoding: utf8 - host: <%= ENV['MYSQL_HOST'] || 'localhost' %> + host: <%= ENV['MYSQL_HOST'] %> database: <%= ENV['MYSQL_DATABASE'] %> username: <%= ENV['MYSQL_USERNAME'] %> password: <%= ENV['MYSQL_PASSWORD'] %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 6cdc6d3..8b5edb8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,4 +64,7 @@ Ensl::Application.configure do # Custom Session Store config to allow gathers.staging.ensl.org config.session_store :cookie_store, key: "_ENSL_session_key", expire_after: 30.days.to_i, domain: ".ensl.org" -end \ No newline at end of file + +# config.cache_store = :dalli_store, 'cache', 'cache-2.example.com:11211:2', +# { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true } +end diff --git a/entry.sh b/entry.sh new file mode 100755 index 0000000..1523ba4 --- /dev/null +++ b/entry.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +env|grep -i MYSQL +cd /var/www +bundle exec rake assets:precompile +bundle exec puma -C config/puma.rb diff --git a/fig.yml b/fig.yml index 314632f..4f008fa 100644 --- a/fig.yml +++ b/fig.yml @@ -1,9 +1,11 @@ web: - image: ensl/ensl.org + image: ensl links: - mysql - - redis +# - redis mysql: - image: mysql -redis: - image: redis + image: mysql/mysql-server + volumes: + - /srv/ensl/mysql:/var/lib/mysql +#redis: +# image: redis From e3275b34ceb595eebd9a66dbbb076d9a01516c28 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sun, 15 Apr 2018 11:17:59 +0000 Subject: [PATCH 3/8] Update docker version Update fig.yml to work Update puma to not daemonize to work Update dockerfile too This version should work now. --- Dockerfile | 1 + config/puma.rb | 2 +- fig.yml | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea536ed..eb9b3b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ RUN bundle install --path /var/bundle --jobs 4 USER root +# FIXME: move this to docker image RUN apt-get install -y memcached RUN service memcached start diff --git a/config/puma.rb b/config/puma.rb index 98409b2..ca304e2 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -10,7 +10,7 @@ stdout_path = "#{base_path}/lpuma.stdout.log" tag 'ENSL' preload_app! -daemonize true +daemonize false directory base_path pidfile "#{base_path}/tmp/puma.pid" state_path "#{base_path}/tmp/puma.state" diff --git a/fig.yml b/fig.yml index 4f008fa..a178931 100644 --- a/fig.yml +++ b/fig.yml @@ -1,11 +1,14 @@ web: image: ensl + volumes: + - "/srv/ensl/public:/var/www/public" + ports: "4000:4000" links: - mysql # - redis mysql: - image: mysql/mysql-server + image: mysql/mysql-server:5.7 volumes: - - /srv/ensl/mysql:/var/lib/mysql + - "/srv/ensl/mysql:/var/lib/mysql" #redis: # image: redis From fe66edf712a245b1844e475a4ee267133ceffb73 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sun, 15 Apr 2018 12:51:22 +0000 Subject: [PATCH 4/8] Update docker version for CI Get old circleci.yml entry.sh env Add test.sh for testing Update Makefile for correct docker path ADd env/test.sh --- .env.example | 30 ++++++++++++++++++++++-------- .gitignore | 3 ++- Makefile | 2 +- circle.yml | 4 ++++ entry.sh | 3 ++- env/test.sh | 25 +++++++++++++++++++++++++ fig.yml | 3 ++- test.sh | 17 +++++++++++++++++ 8 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 circle.yml create mode 100755 env/test.sh create mode 100644 test.sh diff --git a/.env.example b/.env.example index d3b2c45..49a8759 100644 --- a/.env.example +++ b/.env.example @@ -1,19 +1,33 @@ -RACK_ENV= -RAILS_ENV= -APP_SECRET= +RACK_ENV=production +RAILS_ENV=production +APP_SECRET=randomstringhere -DEPLOY_PATH= +DEPLOY_PATH=/var/www -PUMA_WORKERS=1 +PUMA_WORKERS=5 PUMA_MIN_THREADS=1 PUMA_MAX_THREADS=16 PUMA_PORT=4000 PUMA_TIMEOUT=30 +# Docker adds mysql to hosts +MYSQL_HOST=mysql + +# This is used by both rails + mysql MYSQL_DATABASE=ensl -MYSQL_USERNAME= -MYSQL_PASSWORD= -MYSQL_CONNECTION_POOL=8 + +# Add to allow docker image to connect +MYSQL_ROOT_HOST=% + +# FIXME: Use root since normal user does not work. atm. +MYSQL_ROOT_PASSWORD=randomstringhere + +# These variables are for ensl +MYSQL_USERNAME=root +MYSQL_PASSWORD=randomstringhere + +# More MySQL vars +MYSQL_CONNECTION_POOL=32 NEW_RELIC_APP_NAME=ENSL NEW_RELIC_LICENSE_KEY= diff --git a/.gitignore b/.gitignore index b782149..0f649c3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ /log/* /tmp/* /spec/tmp/* -/env/* +/env/production.sh +/env/development.sh .ruby-version .ruby-gemset .env diff --git a/Makefile b/Makefile index 08c8123..2ce0741 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PROJECT ?= abevoelker/example_rails_docker_ci +PROJECT ?= ensl/ensl.org TAG ?= latest ifdef REGISTRY diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..4a2665c --- /dev/null +++ b/circle.yml @@ -0,0 +1,4 @@ +database: + override: + - mv config/database.circle.yml config/database.yml + - bundle exec rake db:create db:schema:load --trace diff --git a/entry.sh b/entry.sh index 1523ba4..50b1908 100755 --- a/entry.sh +++ b/entry.sh @@ -1,6 +1,7 @@ #!/bin/bash -env|grep -i MYSQL +env cd /var/www +source .env bundle exec rake assets:precompile bundle exec puma -C config/puma.rb diff --git a/env/test.sh b/env/test.sh new file mode 100755 index 0000000..897d48f --- /dev/null +++ b/env/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +export RACK_ENV=test +export RAILS_ENV=test +export APP_SECRET=e0cdcb729c4b21d5259e957a2ffc13a3 + +export DEPLOY_PATH=/var/www + +export PUMA_WORKERS=1 +export PUMA_MIN_THREADS=1 +export PUMA_MAX_THREADS=16 +export PUMA_PORT=3000 +export PUMA_TIMEOUT=30 + +#export MYSQL_HOST="${MYSQL_PORT_3306_TCP_ADDR:-localhost}" +export MYSQL_DATABASE=ensl +export MYSQL_USER=root +export MYSQL_HOST="mysql" +export MYSQL_USERNAME=root +export MYSQL_ROOT_PASSWORD=test +export MYSQL_PASSWORD=test +export MYSQL_ROOT_HOST=172.% +export MYSQL_CONNECTION_POOL=32 + +exec "$@" diff --git a/fig.yml b/fig.yml index a178931..8250920 100644 --- a/fig.yml +++ b/fig.yml @@ -2,7 +2,8 @@ web: image: ensl volumes: - "/srv/ensl/public:/var/www/public" - ports: "4000:4000" + ports: + - "4000:4000" links: - mysql # - redis diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..e8fe1ed --- /dev/null +++ b/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +# Undo the `bundle --deployment --without development test` +# settings baked into the prod-ready Docker image's .bundle/config +bundle config --delete without +bundle config --delete frozen + +# Install gems in development and test groups +bundle + +# Ensure database exists and has latest migrations +bundle exec rake db:create +bundle exec rake db:migrate + +# Run tests +bundle exec rake From 398984623580009087bbeff95bfbc30e6c43946c Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sun, 15 Apr 2018 12:59:57 +0000 Subject: [PATCH 5/8] Update dockerfile Remove .env reference, clean up --- Dockerfile | 20 +++++--------------- test.sh | 0 2 files changed, 5 insertions(+), 15 deletions(-) mode change 100644 => 100755 test.sh diff --git a/Dockerfile b/Dockerfile index eb9b3b6..3b742fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos " RUN apt-get update && apt-get -y upgrade RUN apt-get -y install mysql-client libmysqlclient-dev memcached nodejs +RUN service memcached start # Separate Gemfile ADD so that `bundle install` can be cached more effectively @@ -16,29 +17,18 @@ RUN chown -R web:web /var/www &&\ mkdir -p /var/bundle &&\ chown -R web:web /var/bundle -RUN bundle config github.https true -RUN su -c "cd /var/www && bundle install --path /var/bundle" -s /bin/bash -l web +RUN su -c "bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4" -s /bin/bash -l web # Add application source ADD . /var/www RUN chown -R web:web /var/www -USER web - # Precompile assets - -WORKDIR /var/www -COPY .env /var/www/ -RUN bundle install --path /var/bundle --jobs 4 +#WORKDIR /var/www #RUN bundle exec rake assets:precompile -USER root - -# FIXME: move this to docker image -RUN apt-get install -y memcached -RUN service memcached start - -#USER root +# for debug +# USER root USER web CMD ["/var/www/entry.sh"] diff --git a/test.sh b/test.sh old mode 100644 new mode 100755 From 6b2f644352ca364c05effb3011074e742ca2425e Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 23 Apr 2018 15:29:07 +0000 Subject: [PATCH 6/8] Update docker version With docker-compose and mariadb --- .dockerignore | 1 + .gitignore | 4 ++++ Dockerfile | 7 ++++--- Makefile | 5 +++-- docker-compose.yml | 29 +++++++++++++++++++++++++++++ entry.sh | 7 ------- ext/mysql.conf.d/opt.cnf | 31 +++++++++++++++++++++++++++++++ fig.yml | 15 --------------- script/entry.sh | 8 ++++++++ test.sh => script/test.sh | 0 10 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 docker-compose.yml delete mode 100755 entry.sh create mode 100644 ext/mysql.conf.d/opt.cnf delete mode 100644 fig.yml create mode 100755 script/entry.sh rename test.sh => script/test.sh (100%) diff --git a/.dockerignore b/.dockerignore index 9414382..1585cd9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ Dockerfile +db_data diff --git a/.gitignore b/.gitignore index 0f649c3..ee8b136 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,10 @@ *.rbc *.sassc +# Database and files +db_data/* +!db_data/.placeholder + # OS X .DS_Store diff --git a/Dockerfile b/Dockerfile index 3b742fa..86cebd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,12 @@ ADD . /var/www RUN chown -R web:web /var/www # Precompile assets -#WORKDIR /var/www -#RUN bundle exec rake assets:precompile +WORKDIR /var/www +USER web +RUN bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4 +RUN bundle exec rake assets:precompile && mv /var/www/public/assets /var/www/assets_tmp # for debug # USER root -USER web CMD ["/var/www/entry.sh"] diff --git a/Makefile b/Makefile index 2ce0741..a9fc489 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ -PROJECT ?= ensl/ensl.org -TAG ?= latest +REGISTRY ?= ensl +PROJECT ?= ensl.org +TAG ?= latest ifdef REGISTRY IMAGE=$(REGISTRY)/$(PROJECT):$(TAG) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..24e42db --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: "3" + +services: + web: + image: ensl/ensl.org:latest +# volumes: +# - "/srv/ensl/ensl.org/public:/var/www/public" + ports: + - "4000:4000" + depends_on: + - db + - memcached + # - redis + db: + image: mariadb:latest + volumes: + - "/srv/ensl/ensl.org/db_data:/var/lib/mysql" +# - "/srv/ensl/ensl.org/ext/mysql.conf.d:/etc/mysql/conf.d" + environment: + - MYSQL_DATABASE + - MYSQL_USER + - MYSQL_USERNAME + - MYSQL_PASSWORD + - MYSQL_ROOT_PASSWORD +# - MYSQL_ROOT_HOST + memcached: + image: memcached:latest + #redis: + # image: redis diff --git a/entry.sh b/entry.sh deleted file mode 100755 index 50b1908..0000000 --- a/entry.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -env -cd /var/www -source .env -bundle exec rake assets:precompile -bundle exec puma -C config/puma.rb diff --git a/ext/mysql.conf.d/opt.cnf b/ext/mysql.conf.d/opt.cnf new file mode 100644 index 0000000..7042c5e --- /dev/null +++ b/ext/mysql.conf.d/opt.cnf @@ -0,0 +1,31 @@ +[mysqld] + +skip-host-cache +skip-name-resolve + +key_buffer = 150M +max_allowed_packet = 20M +thread_stack = 196K +thread_cache_size = 16 + +max_connections = 96 +table_cache = 2000 +table_definition_cache = 800 +thread_concurrency = 128 + +query_cache_limit = 30M +query_cache_size = 150M +open_files_limit = 1800 +join_buffer_size = 1M +sort_buffer_size = 1M +read_buffer_size = 128K +tmp_table_size = 500M +max_heap_table_size = 500M + +innodb_buffer_pool_size = 1280M +innodb_flush_log_at_trx_commit = 1 +innodb_thread_concurrency = 16 +innodb_flush_method = O_DIRECT +innodb_additional_mem_pool_size = 20M +innodb_file_per_table = 1 +transaction-isolation = READ-COMMITTED diff --git a/fig.yml b/fig.yml deleted file mode 100644 index 8250920..0000000 --- a/fig.yml +++ /dev/null @@ -1,15 +0,0 @@ -web: - image: ensl - volumes: - - "/srv/ensl/public:/var/www/public" - ports: - - "4000:4000" - links: - - mysql -# - redis -mysql: - image: mysql/mysql-server:5.7 - volumes: - - "/srv/ensl/mysql:/var/lib/mysql" -#redis: -# image: redis diff --git a/script/entry.sh b/script/entry.sh new file mode 100755 index 0000000..ea8f5c7 --- /dev/null +++ b/script/entry.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +env +cd /var/www +source /var/www/.env +rm -rf /var/www/public/assets +mv /var/www/assets_tmp /var/www/public/ +bundle exec puma -C config/puma.rb diff --git a/test.sh b/script/test.sh similarity index 100% rename from test.sh rename to script/test.sh From 5096be9ff31a3831f644f783a52dfe8606001845 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 23 Apr 2018 21:57:01 +0000 Subject: [PATCH 7/8] Fix Dockerfile Add entry.sh --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 86cebd7..5494ba5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,4 +32,4 @@ RUN bundle exec rake assets:precompile && mv /var/www/public/assets /var/www/ass # for debug # USER root -CMD ["/var/www/entry.sh"] +CMD ["/var/www/scripts/entry.sh"] From 22fc8cb50bdbc2658170d40ae30a7ba1ffcd834b Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Wed, 25 Apr 2018 16:41:22 +0000 Subject: [PATCH 8/8] Update to a working version - Use assets workaround to work around the volume issue with docker - Add assets to gitignore - Fix dalli hostname - Update docker-compose to new paths for volumes - Fix MariaDB issue with optimization opts --- .gitignore | 1 + Dockerfile | 11 ++++++----- config/environments/production.rb | 2 +- docker-compose.yml | 8 ++++---- ext/mysql.conf.d/opt.cnf | 2 +- script/entry.sh | 7 +++++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index ee8b136..30f40f0 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ db_data/* /public/files/* /public/local /public/uploads +/public/assets # RubyMine /.idea diff --git a/Dockerfile b/Dockerfile index 5494ba5..af6db94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,13 +23,14 @@ RUN su -c "bundle config github.https true; cd /var/www && bundle install --path ADD . /var/www RUN chown -R web:web /var/www -# Precompile assets WORKDIR /var/www USER web + RUN bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4 -RUN bundle exec rake assets:precompile && mv /var/www/public/assets /var/www/assets_tmp +RUN bundle exec rake assets:precompile -# for debug -# USER root +# This is a temporary solution to fix assets issue +RUN mv /var/www/public/assets /home/web/assets -CMD ["/var/www/scripts/entry.sh"] +USER root +CMD ["/var/www/script/entry.sh"] diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b5edb8..692d211 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,7 +37,7 @@ Ensl::Application.configure do # config.logger = SyslogLogger.new # Use a different cache store in production - config.cache_store = :dalli_store + config.cache_store = :dalli_store, 'memcached:11211', 'localhost' # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/docker-compose.yml b/docker-compose.yml index 24e42db..b78ad50 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,8 @@ version: "3" services: web: image: ensl/ensl.org:latest -# volumes: -# - "/srv/ensl/ensl.org/public:/var/www/public" + volumes: + - "./public:/var/www/public" ports: - "4000:4000" depends_on: @@ -14,8 +14,8 @@ services: db: image: mariadb:latest volumes: - - "/srv/ensl/ensl.org/db_data:/var/lib/mysql" -# - "/srv/ensl/ensl.org/ext/mysql.conf.d:/etc/mysql/conf.d" + - "./db_data:/var/lib/mysql" + - "./ext/mysql.conf.d:/etc/mysql/conf.d" environment: - MYSQL_DATABASE - MYSQL_USER diff --git a/ext/mysql.conf.d/opt.cnf b/ext/mysql.conf.d/opt.cnf index 7042c5e..a9545ea 100644 --- a/ext/mysql.conf.d/opt.cnf +++ b/ext/mysql.conf.d/opt.cnf @@ -26,6 +26,6 @@ innodb_buffer_pool_size = 1280M innodb_flush_log_at_trx_commit = 1 innodb_thread_concurrency = 16 innodb_flush_method = O_DIRECT -innodb_additional_mem_pool_size = 20M +#innodb_additional_mem_pool_size = 20M innodb_file_per_table = 1 transaction-isolation = READ-COMMITTED diff --git a/script/entry.sh b/script/entry.sh index ea8f5c7..06580cd 100755 --- a/script/entry.sh +++ b/script/entry.sh @@ -4,5 +4,8 @@ env cd /var/www source /var/www/.env rm -rf /var/www/public/assets -mv /var/www/assets_tmp /var/www/public/ -bundle exec puma -C config/puma.rb +mv /home/web/assets /var/www/public/ +chown -R web:web /var/www/public + +#bundle exec rake assets:precompile +su -c "cd /var/www && bundle exec puma -C config/puma.rb" -s /bin/bash -l web