Skip to content
Open
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
db_data
box
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
Expand All @@ -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
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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```
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
10 changes: 10 additions & 0 deletions script/start.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"