Skip to content

Commit

Permalink
docker development setup
Browse files Browse the repository at this point in the history
  • Loading branch information
biwek committed Jul 4, 2018
1 parent f7d348c commit 7faf460
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
.gitignore

Dockerfile
docker-compose.yml
.dockerignore

log/*
tmp/*
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POSTGRES_USER=abhinavnepal
POSTGRES_PASSWORD=helloworld
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# specific to each app instance
/config/database.yml

# avoid secrets in source control
/config/secrets.yml

# Ignore bundler config.
/.bundle

Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ruby:2.3.1

# install system libraries
RUN apt-get update -yqq \
&& apt-get install -yqq build-essential libpq-dev nodejs qt5-default \
&& apt-get -q clean \
&& rm -rf /var/lib/apt/lists

# install path setup
ENV INSTALL_PATH /abhinav-nepal
RUN mkdir -p $INSTALL_PATH

# install gems
COPY Gemfile* ./
RUN bundle install
COPY . .

CMD script/start
12 changes: 6 additions & 6 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
default: &default
adapter: postgresql
encoding: unicode
host: db
username: <%= ENV["POSTGRES_USER"] %>
password: <%= ENV["POSTGRES_PASSWORD"] %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
encoding: unicode
database: abhinav_dev
pool: 5
host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: abhinav_test

production:
<<: *default
host: <%= ENV["POSTGRES_HOST"] %>
database: abhinav_prod
6 changes: 6 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# By default, puma was putting the pidfile in the rails app `tmp` directory.
# This was leading to the pid file existing when creating a new container, thus
# making puma fail to start saying that there was already a server running.
# Since we're running in containers we've set the pid file to be in the `/tmp`
# directory that will start clean with every container run.
pidfile "/tmp/puma.pid"

# Specifies the `environment` that Puma will run in.
#
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "2"

services:
db:
image: postgres:9.6-alpine
volumes:
- db-data:/var/lib/postgresql/db-data
ports:
- "5432:5432"
env_file:
- .env
app:
build: .
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
env_file:
- .env

volumes:
db-data:
16 changes: 16 additions & 0 deletions script/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -e

if [[ -a /tmp/puma.pid ]]; then
rm /tmp/puma.pid
fi

if [[ $RAILS_ENV == "production" ]]; then
rake assets:precompile
rake db:migrate
mkdir -p /usr/share/nginx/html
cp -R public/* /usr/share/nginx/html
mkdir -p /etc/nginx/conf.d/
cp site.conf /etc/nginx/conf.d/default.conf
fi

rails server -b 0.0.0.0 -P /tmp/puma.pid

0 comments on commit 7faf460

Please sign in to comment.