Skip to content

Commit

Permalink
Merge pull request columbusrb#21 from tvon/docker
Browse files Browse the repository at this point in the history
Docker updates
  • Loading branch information
belongstorachel committed Jan 20, 2017
2 parents 2e48b3d + d1038fa commit c4b5d0d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 37 deletions.
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM ruby:2.2.0
RUN apt-get update -qq
RUN apt-get install -y build-essential nodejs npm nodejs-legacy libpq-dev vim curl patch gawk g++ gcc make libc6-dev patch libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
FROM ruby:2.2.1

RUN npm install -g phantomjs
RUN mkdir /myapp
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client libssl-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
WORKDIR /app
COPY Gemfile* ./
RUN bundle install
COPY . /app/

EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

ADD . /myapp
WORKDIR /myapp
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
## Columbus Ruby Brigade Website

### About

TODO: Add some information about CRB

### How to Join

TODO: Add steps on how to join

### Contributing
TODO: Add contributing information.

To start the app and database, you can use the helper script:

```
script/docker-start
```

Once that is up and running, you can execute `rake` and `rails` commands (or anything else) via `script/docker-run`, e.g.:

```
script/docker-run rails console
```

or

```
script/docker-run rake -T
```

View in your browser at [http://localhost:3000/](http://localhost:3000/)

You can also use docker-compose directly:

```
docker-compose build
docker-compose up -d postgres
docker-compose run --rm app rake db:setup
docker-compose up -d app
docker-compose logs -f
```

To run commands in the context of the container, e.g., `rails console`:

```
docker-compose run --rm app rails console
```

9 changes: 0 additions & 9 deletions bin/start

This file was deleted.

8 changes: 4 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# gem 'sqlite3'
development: &default
adapter: postgresql
database: <%= ENV['DB_NAME'] || 'crb_dev_duex' %>
username: <%= ENV['DB_USERNAME'] || 'postgres' %>
password: <%= ENV['DB_PASSWORD'] %>
host: <%= ENV['DB_HOST'] || 'localhost' %>
encoding: unicode
database: crb_dev_duex
pool: 5
username: postgres
password:
host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
Expand Down
37 changes: 24 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
db:
image: postgres
ports:
- 5432
web:
build: .
command: bundle exec thin start
volumes:
- .:/myapp
ports:
- "3000:3000"
links:
- db
version: '2'

services:
app:
build: .
container_name: columbusrb.com-app
volumes:
- ".:/app"
ports:
- "3000:3000"
links:
- postgres
environment:
DB_NAME: crb_dev_duex
DB_USERNAME: postgres
DB_PASSWORD: password
DB_HOST: postgres

postgres:
image: postgres:9.6
container_name: columbusrb.com-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
5 changes: 5 additions & 0 deletions script/docker-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

docker-compose run --rm app $@
21 changes: 21 additions & 0 deletions script/docker-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail

docker-compose build && \
docker-compose create postgres && \
docker-compose up -d postgres && \
# Sometimes postgres isn't ready by the time the app starts, so take a cat nap.
sleep 2 && \
docker-compose run --rm app bundle exec rake db:create db:setup && \
docker-compose up -d app && \
docker-compose logs -f || \
docker-compose down # If something fails, make sure the containers are stopped.

function trap_exit() {
# Allow ctrl-c to stop the script, and also stop the containers.
docker-compose down
exit 2
}

trap "trap_exit" 2

0 comments on commit c4b5d0d

Please sign in to comment.