From c8985c6f387ae57d9569f34cd8dac6613b95174c Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Tue, 26 Jul 2016 10:38:00 -0500 Subject: [PATCH] Docker config --- .tmux.conf | 5 + Dockerfile | 42 ++++++++ Gemfile | 39 +++++++ Gemfile.lock | 268 ++++++++++++++++++++++++++++++++++++++++++++++++ Guardfile | 43 ++++++++ start-dev.sh | 12 +++ start-docker.sh | 21 ++++ start-server.sh | 10 ++ 8 files changed, 440 insertions(+) create mode 100644 .tmux.conf create mode 100644 Dockerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100755 start-dev.sh create mode 100755 start-docker.sh create mode 100755 start-server.sh diff --git a/.tmux.conf b/.tmux.conf new file mode 100644 index 0000000..2b3df9b --- /dev/null +++ b/.tmux.conf @@ -0,0 +1,5 @@ +set -g mode-mouse on +set -g mouse-resize-pane on +set -g mouse-select-pane on +set -g mouse-select-window on +set -g history-limit 30000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c8429bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM mysql:5.7 +MAINTAINER Mark Moser + +WORKDIR ~/ + +ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes +ENV MYSQL_ROOT_PASSWORD= +ENV BUILD_PACKAGES="build-essential libmysqlclient-dev openssl graphviz nodejs curl wget zlib1g-dev tmux" + +RUN apt-get update \ + && apt-get install --fix-missing -y $BUILD_PACKAGES \ + && /usr/sbin/mysqld --initialize --user=mysql \ + && echo 'gem: --no-document' >> ~/.gemrc \ + && cp ~/.gemrc /etc/gemrc \ + && chmod uog+r /etc/gemrc \ + && mkdir -p /usr/app \ + && ln -s /usr/bin/nodejs /usr/bin/node \ + && echo "alias ll='ls -Ahl'" >> /root/.bashrc \ + && echo "alias la='ls -ahl'" >> /root/.bashrc + +# install current Ruby +RUN curl -L --progress https://github.com/postmodern/ruby-install/archive/v0.6.0.tar.gz | tar xz \ + && cd ruby-install-0.6.0 \ + && make install \ + && cd ../ \ + && ruby-install --system ruby \ + && gem install bundler + +COPY .tmux.conf /root/ +COPY Gemfile* /root/ +RUN cd /root \ + && bundle install \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +EXPOSE 3000 3306 +WORKDIR /usr/app +CMD ["mysqld"] + +# ./start-docker.sh +# ./start-server.sh +# rails server -b 0.0.0.0 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1a5f53f --- /dev/null +++ b/Gemfile @@ -0,0 +1,39 @@ +source 'https://rubygems.org' + +gem 'figaro', '~> 1.1.1' +gem 'bcrypt', '~> 3.1.7' +gem 'mysql2', '>= 0.3.18', '< 0.5' +gem 'rails', '~> 5.0.0' + +gem 'autoprefixer-rails' +gem 'jbuilder', '~> 2.5' +gem 'jquery-rails' +gem 'json', '~> 2.0.1' +gem 'puma', '~> 3.0' +gem 'sass-rails', '~> 5.0' +gem 'turbolinks', '~> 5' +gem 'uglifier', '>= 1.3.0' + +group :development, :test do + gem 'awesome_print' + gem 'binding_of_caller' + gem 'byebug', platform: :mri + gem 'guard' + gem 'guard-livereload' + gem 'guard-minitest' + gem 'guard-rubocop' + gem 'guard-shell' + gem 'listen', '~> 3.0.5' + gem 'minitest-reporters' + gem 'pry-byebug' + gem 'pry-rails' + gem 'rack-livereload' + gem 'rails-erd' + gem 'rubocop' + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' + gem 'web-console' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..dc3cacd --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,268 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.0) + actionpack (= 5.0.0) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0) + actionpack (= 5.0.0) + actionview (= 5.0.0) + activejob (= 5.0.0) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.0) + actionview (= 5.0.0) + activesupport (= 5.0.0) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.0) + activesupport (= 5.0.0) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.0) + activesupport (= 5.0.0) + globalid (>= 0.3.6) + activemodel (5.0.0) + activesupport (= 5.0.0) + activerecord (5.0.0) + activemodel (= 5.0.0) + activesupport (= 5.0.0) + arel (~> 7.0) + activesupport (5.0.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + ansi (1.5.0) + arel (7.0.0) + ast (2.3.0) + autoprefixer-rails (6.3.7) + execjs + awesome_print (1.7.0) + bcrypt (3.1.11) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.2) + byebug (9.0.5) + choice (0.2.0) + coderay (1.1.1) + concurrent-ruby (1.0.2) + debug_inspector (0.0.2) + em-websocket (0.5.1) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0.6.0) + erubis (2.7.0) + eventmachine (1.2.0.1) + execjs (2.7.0) + ffi (1.9.14) + figaro (1.1.1) + thor (~> 0.14) + formatador (0.2.5) + globalid (0.3.6) + activesupport (>= 4.1.0) + guard (2.14.0) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-livereload (2.5.2) + em-websocket (~> 0.5) + guard (~> 2.8) + guard-compat (~> 1.0) + multi_json (~> 1.8) + guard-minitest (2.4.5) + guard-compat (~> 1.2) + minitest (>= 3.0) + guard-rubocop (1.2.0) + guard (~> 2.0) + rubocop (~> 0.20) + guard-shell (0.7.1) + guard (>= 2.0.0) + guard-compat (~> 1.0) + http_parser.rb (0.6.0) + i18n (0.7.0) + jbuilder (2.5.0) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.1.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.0.1) + listen (3.0.8) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + loofah (2.0.3) + nokogiri (>= 1.5.9) + lumberjack (1.0.10) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.0) + minitest-reporters (1.1.10) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + multi_json (1.12.1) + mysql2 (0.4.4) + nenv (0.3.0) + nio4r (1.2.1) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + notiffany (0.1.0) + nenv (~> 0.1) + shellany (~> 0.0) + parser (2.3.1.2) + ast (~> 2.2) + pkg-config (1.1.7) + powerpack (0.1.1) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.4.0) + byebug (~> 9.0) + pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) + puma (3.4.0) + rack (2.0.1) + rack-livereload (0.3.16) + rack + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.0) + actioncable (= 5.0.0) + actionmailer (= 5.0.0) + actionpack (= 5.0.0) + actionview (= 5.0.0) + activejob (= 5.0.0) + activemodel (= 5.0.0) + activerecord (= 5.0.0) + activesupport (= 5.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.0) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6.0) + rails-erd (1.4.7) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.0) + actionpack (= 5.0.0) + activesupport (= 5.0.0) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rainbow (2.1.0) + rake (11.2.2) + rb-fsevent (0.9.7) + rb-inotify (0.9.7) + ffi (>= 0.5.0) + rubocop (0.41.2) + parser (>= 2.3.1.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-graphviz (1.2.2) + ruby-progressbar (1.8.1) + sass (3.4.22) + sass-rails (5.0.5) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + shellany (0.0.1) + slop (3.6.0) + spring (1.7.2) + spring-watcher-listen (2.0.0) + listen (>= 2.7, < 4.0) + spring (~> 1.2) + sprockets (3.6.3) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.1.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.19.1) + thread_safe (0.3.5) + tilt (2.0.5) + turbolinks (5.0.0) + turbolinks-source (~> 5) + turbolinks-source (5.0.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (3.0.0) + execjs (>= 0.3.0, < 3) + unicode-display_width (1.1.0) + web-console (3.3.1) + actionview (>= 5.0) + activemodel (>= 5.0) + debug_inspector + railties (>= 5.0) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + autoprefixer-rails + awesome_print + bcrypt (~> 3.1.7) + binding_of_caller + byebug + figaro (~> 1.1.1) + guard + guard-livereload + guard-minitest + guard-rubocop + guard-shell + jbuilder (~> 2.5) + jquery-rails + json (~> 2.0.1) + listen (~> 3.0.5) + minitest-reporters + mysql2 (>= 0.3.18, < 0.5) + pry-byebug + pry-rails + puma (~> 3.0) + rack-livereload + rails (~> 5.0.0) + rails-erd + rubocop + sass-rails (~> 5.0) + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console + +BUNDLED WITH + 1.12.5 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..8273564 --- /dev/null +++ b/Guardfile @@ -0,0 +1,43 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +guard :minitest do + watch(%r{^test/test_helper\.rb$}) { 'test' } + watch(%r{^test/(.*)\/?(.*)_test\.rb$}) + watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" } + watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/lib/#{m[1]}#{m[2]}_test.rb" } +end + +guard 'livereload' do + watch(%r{app/assets/.+\.(scss|css|js)}) + watch(%r{app/views/.+\.(erb|haml|slim)$}) + watch(%r{app/controllers/.+\.rb}) + watch(%r{app/helpers/.+\.rb}) + watch(%r{public/.+\.(css|js|html)}) + watch(%r{config/locales/.+\.yml}) + + # Rails Assets Pipeline + watch(%r{(app|vendor)(/assets/\w+/(.+\.(scss|css|js|html|png|jpg))).*}) do |m| + "/assets/#{m[3]}" + end +end + +guard :rubocop do + watch(/.+\.rb$/) + watch(/Rakefile/) + watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } +end diff --git a/start-dev.sh b/start-dev.sh new file mode 100755 index 0000000..838e310 --- /dev/null +++ b/start-dev.sh @@ -0,0 +1,12 @@ +cd /usr/app +bundle + +service mysql start +rails db:setup +rails db:migrate +rails db:fixtures:load + +tmux new-session -d -s 'rails-dev' 'rails s -b 0.0.0.0' +tmux split-window -p 80 -v guard +tmux split-window -p 25 -v +tmux attach -t rails-dev diff --git a/start-docker.sh b/start-docker.sh new file mode 100755 index 0000000..b3d8687 --- /dev/null +++ b/start-docker.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +IMAGE=deb-rails-dev +CONTAINER=`basename ${PWD}` + +if [ "$(docker images -q $IMAGE:latest 2> /dev/null)" == "" ]; then + docker build -t $IMAGE . +fi + +STATUS=$(docker inspect --format="{{ .State.Running }}" $CONTAINER 2> /dev/null) + +if [ $? -eq 1 ]; then + docker run --name $CONTAINER -it -p 3000:3000 -p 3306:3306 -v ${PWD}:/usr/app $IMAGE /bin/bash + exit +fi + +if [ "$STATUS"=="false" ]; then + docker start $CONTAINER +fi + +docker attach $CONTAINER diff --git a/start-server.sh b/start-server.sh new file mode 100755 index 0000000..7f6d270 --- /dev/null +++ b/start-server.sh @@ -0,0 +1,10 @@ +cd /usr/app +bundle + +service mysql start +rails db:setup +rails db:migrate +rails db:fixtures:load + +rails s -b 0.0.0.0 +