From e3d923ec8c8c3c03bf9517c5f46aca084e4e233f Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 20:49:19 -0800 Subject: [PATCH 01/10] set up startup script for ruby docker --- Dockerfile | 18 +++++++++++------- script/start.sh | 5 +++++ 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100755 script/start.sh diff --git a/Dockerfile b/Dockerfile index d44f516..ff874e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM ruby:2.3.1 - # Install essential linux packages RUN apt-get update -qq && apt-get install -y --no-install-recommends \ bash \ @@ -9,6 +8,9 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \ nodejs \ npm \ postgresql-client \ + libxml2-dev \ + libxslt-dev \ + libiconv-dev \ && rm -rf /var/lib/apt/lists/* # Define where the application will live inside the image @@ -24,13 +26,15 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \ # Install bundler RUN gem install bundler -# Use the Gemfiles as Docker cache markers and run bundle install before copy over app src -#COPY Gemfile Gemfile -#COPY Gemfile.lock Gemfile.lock +ENV app /app + +RUN mkdir $app +WORKDIR $app +ENV BUNDLE_PATH /box -#RUN bundle install --deployment +ADD . $app -#RUN rails db:migrate +COPY script/start.sh /start.sh -CMD bundle install --deployment && rails db:migrate && rails s +CMD rails s -b 0.0.0.0 diff --git a/script/start.sh b/script/start.sh new file mode 100755 index 0000000..dcd18c2 --- /dev/null +++ b/script/start.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +bundle check || bundle install + +bundle exec rails s -b 0.0.0.0 From c7b7707a2fc7d5b651875a4ca89aa4f880a0acfc Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 23:06:28 -0800 Subject: [PATCH 02/10] startup script now used as entrypoint and removes leftover rails PID file --- Dockerfile | 3 ++- script/start.sh | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff874e6..06831cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \ postgresql-client \ libxml2-dev \ libxslt-dev \ - libiconv-dev \ && rm -rf /var/lib/apt/lists/* # Define where the application will live inside the image @@ -37,4 +36,6 @@ ADD . $app COPY script/start.sh /start.sh +ENTRYPOINT ["/start.sh"] + CMD rails s -b 0.0.0.0 diff --git a/script/start.sh b/script/start.sh index dcd18c2..1d9bce1 100755 --- a/script/start.sh +++ b/script/start.sh @@ -1,5 +1,10 @@ -#!/bin/bash +#!/bin/sh +set -e + +if [ -f /app/tmp/pids/server.pid ]; then + rm /app/tmp/pids/server.pid +fi bundle check || bundle install -bundle exec rails s -b 0.0.0.0 +exec bundle exec "$@" From bd015dc5cb96913af3d796dd8d9359f0ee9bb96b Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 23:10:31 -0800 Subject: [PATCH 03/10] updates to readme --- README.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9d9e18b..d3665d1 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,35 @@ version: '3' services: - rails: - # depends_on: - # - db - image: renocollective/rails - volumes: - - ./:/var/www/app - ports: - - "3000:3000" - restart: always - # environment: + db: + image: postgres:10.1 + volumes: + - ./db_data:/var/lib/postgresql/data + ports: + - "3309:3306" + restart: always + env_file: + - ./.env.local + + rails: + depends_on: + - db + links: + - db + #image: renocollective/rails + build: ../member-portal-docker + volumes: + - ./:/app + - box:/box + ports: + - "3000:3000" + restart: always + env_file: + - ./.env.local + + box: + image: busybox + volumes: + - box:/box ``` From 1a37ec9659092d73ba6b1db772bd9093e7cac394 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 23:27:24 -0800 Subject: [PATCH 04/10] Made this project a little more self contained by moving the docker-compose file here. Also gitignored the db_data dir. Also added to the readme --- .gitignore | 1 + README.md | 55 ++++++++++++++++------------------------------ docker-compose.yml | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 36 deletions(-) create mode 100644 .gitignore create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17186c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +db_data diff --git a/README.md b/README.md index d3665d1..eb08de3 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,24 @@ # Rails Dev A simple rails image for rails development -## Sample docker-compose.yml -``` -version: '3' +## Usage +Modify the docker-compose.yml paths to point at your rails app. +Be sure the .env.local file is also correctly targeted. -services: +Sample .env.local file contents: +```# dotenv .env file for environment variables +# +# each developer should make their own .env.local file using this .env file +# as a guide +# +# .env.local files are not checked into the remote repo +# +# reference these attributes in code like this: +# config.fog_directory = ENV['S3_BUCKET'] - db: - image: postgres:10.1 - volumes: - - ./db_data:/var/lib/postgresql/data - ports: - - "3309:3306" - restart: always - env_file: - - ./.env.local - - rails: - depends_on: - - db - links: - - db - #image: renocollective/rails - build: ../member-portal-docker - volumes: - - ./:/app - - box:/box - ports: - - "3000:3000" - restart: always - env_file: - - ./.env.local - - box: - image: busybox - volumes: - - box:/box - -``` +S3_BUCKET=bogus-key-for-example +POSTGRES_HOST=db +POSTGRES_DB=member_portal +POSTGRES_USER=member_portal +POSTGRES_PASSWORD=somereallygreatpasswordthatsbetterthanthisone +SECRET_KEY_BASE=insecure-secret_key_base``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1743a86 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,46 @@ +version: '3' + +services: + db: + image: postgres:10.1 + volumes: + - ./db_data:/var/lib/postgresql/data + ports: + - "3309:3306" + restart: always + env_file: + - ../member-portal/.env.local + + # adminer: + # depends_on: + # - db + # links: + # - db + # image: adminer + # restart: always + # ports: + # - 8088:8080 + + rails: + depends_on: + - db + links: + - db + #image: renocollective/rails + build: ./ + volumes: + - ../member-portal/:/app + - ../member-portal/box:/box + ports: + - "3000:3000" + restart: always + env_file: + - ../member-portal/.env.local + + box: + image: busybox + volumes: + - ../member-portal/box:/box + +volumes: + box: From da4cb0cc44b7429294897974144ba5bc1455a8a8 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 23:34:25 -0800 Subject: [PATCH 05/10] moved box dir to root and gitignored it. --- .gitignore | 1 + docker-compose.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 17186c7..245c045 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ db_data +box diff --git a/docker-compose.yml b/docker-compose.yml index 1743a86..1d4ddf9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: build: ./ volumes: - ../member-portal/:/app - - ../member-portal/box:/box + - ./box:/box ports: - "3000:3000" restart: always @@ -40,7 +40,7 @@ services: box: image: busybox volumes: - - ../member-portal/box:/box + - ./box:/box volumes: box: From 200db8d9a4ff4c81c819428c62e29fc30fed2650 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2018 23:45:05 -0800 Subject: [PATCH 06/10] docker readme updates --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb08de3..c99a44a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Rails Dev A simple rails image for rails development -## Usage +## Setup Modify the docker-compose.yml paths to point at your rails app. Be sure the .env.local file is also correctly targeted. @@ -21,4 +21,11 @@ POSTGRES_HOST=db POSTGRES_DB=member_portal POSTGRES_USER=member_portal POSTGRES_PASSWORD=somereallygreatpasswordthatsbetterthanthisone -SECRET_KEY_BASE=insecure-secret_key_base``` +SECRET_KEY_BASE=insecure-secret_key_base +``` + +## Usage +* To run rails in docker +* ```docker-compose up``` or ```docker-compose up -d``` to not show console output. +* DB Migrate: (can be run without rebooting container, just open a new terminal) +* ```docker-compose run --rm rails rails db:migrate RAILS_ENV=development``` From d4cf37cb40c88c9d9cb883499667f872e2f02b9d Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 7 Feb 2018 14:46:29 -0800 Subject: [PATCH 07/10] Added testing options to readme. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c99a44a..d8e63b2 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,8 @@ SECRET_KEY_BASE=insecure-secret_key_base * To run rails in docker * ```docker-compose up``` or ```docker-compose up -d``` to not show console output. * DB Migrate: (can be run without rebooting container, just open a new terminal) -* ```docker-compose run --rm rails rails db:migrate RAILS_ENV=development``` +* ```docker-compose run --rm -e "RAILS_ENV=development" rails rails db:migrate``` +* Tests: +* ```docker-compose run --rm -e "RAILS_ENV=test" rails rake test``` +* Tests with DEBUG log level: +* ```docker-compose run --rm -e "RAILS_ENV=test" -e"LOG_LEVEL=DEBUG" rails rake test``` From 7da458ea8efb59129115387f7c7f4608e6c13739 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 7 Feb 2018 16:14:38 -0800 Subject: [PATCH 08/10] Update Readme, how to run rubocop, and a couple other details added. --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d8e63b2..5e1c37b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ A simple rails image for rails development Modify the docker-compose.yml paths to point at your rails app. Be sure the .env.local file is also correctly targeted. -Sample .env.local file contents: +Sample .env.local file contents (needs at least these variables for this docker +s, others may setup, others may be necessary for your rails app): ```# dotenv .env file for environment variables # # each developer should make their own .env.local file using this .env file @@ -16,20 +17,20 @@ Sample .env.local file contents: # reference these attributes in code like this: # config.fog_directory = ENV['S3_BUCKET'] -S3_BUCKET=bogus-key-for-example POSTGRES_HOST=db POSTGRES_DB=member_portal POSTGRES_USER=member_portal POSTGRES_PASSWORD=somereallygreatpasswordthatsbetterthanthisone -SECRET_KEY_BASE=insecure-secret_key_base ``` ## Usage -* To run rails in docker +* To run rails in docker. Be sure you're in the right directory with docker-compose.yml * ```docker-compose up``` or ```docker-compose up -d``` to not show console output. * DB Migrate: (can be run without rebooting container, just open a new terminal) -* ```docker-compose run --rm -e "RAILS_ENV=development" rails rails db:migrate``` +* ```docker-compose run --rm rails rails db:migrate``` * Tests: * ```docker-compose run --rm -e "RAILS_ENV=test" rails rake test``` * Tests with DEBUG log level: * ```docker-compose run --rm -e "RAILS_ENV=test" -e"LOG_LEVEL=DEBUG" rails rake test``` +* Run rubocop: +* ```docker-compose run --rm rails bundle exec rubocop``` From d4e526f747dfde44862b61c96c30ecb879b8ba60 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 7 Feb 2018 16:15:23 -0800 Subject: [PATCH 09/10] Run entrypoint startup script with bash. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 06831cc..c1caa4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,6 @@ ADD . $app COPY script/start.sh /start.sh -ENTRYPOINT ["/start.sh"] +ENTRYPOINT ["bash","/start.sh"] CMD rails s -b 0.0.0.0 From 68b467de64605452b384823601686cb1804c04bc Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 7 Feb 2018 16:15:38 -0800 Subject: [PATCH 10/10] remove commented out line. --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1d4ddf9..39b8371 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,7 +26,6 @@ services: - db links: - db - #image: renocollective/rails build: ./ volumes: - ../member-portal/:/app