diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..245c045 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +db_data +box diff --git a/Dockerfile b/Dockerfile index d44f516..c1caa4b 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,8 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \ nodejs \ npm \ postgresql-client \ + libxml2-dev \ + libxslt-dev \ && rm -rf /var/lib/apt/lists/* # Define where the application will live inside the image @@ -24,13 +25,17 @@ 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 +ADD . $app -#RUN bundle install --deployment +COPY script/start.sh /start.sh -#RUN rails db:migrate +ENTRYPOINT ["bash","/start.sh"] -CMD bundle install --deployment && rails db:migrate && rails s +CMD rails s -b 0.0.0.0 diff --git a/README.md b/README.md index 9d9e18b..5e1c37b 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,36 @@ # Rails Dev A simple rails image for rails development -## Sample docker-compose.yml -``` -version: '3' - -services: +## Setup +Modify the docker-compose.yml paths to point at your rails app. +Be sure the .env.local file is also correctly targeted. - rails: - # depends_on: - # - db - image: renocollective/rails - volumes: - - ./:/var/www/app - ports: - - "3000:3000" - restart: always - # environment: +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 +# 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'] +POSTGRES_HOST=db +POSTGRES_DB=member_portal +POSTGRES_USER=member_portal +POSTGRES_PASSWORD=somereallygreatpasswordthatsbetterthanthisone ``` + +## Usage +* 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 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``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..39b8371 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +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 + build: ./ + volumes: + - ../member-portal/:/app + - ./box:/box + ports: + - "3000:3000" + restart: always + env_file: + - ../member-portal/.env.local + + box: + image: busybox + volumes: + - ./box:/box + +volumes: + box: diff --git a/script/start.sh b/script/start.sh new file mode 100755 index 0000000..1d9bce1 --- /dev/null +++ b/script/start.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +if [ -f /app/tmp/pids/server.pid ]; then + rm /app/tmp/pids/server.pid +fi + +bundle check || bundle install + +exec bundle exec "$@"