Skip to content

Commit

Permalink
Dockerize the demo_web_app
Browse files Browse the repository at this point in the history
[refs #28500babc311]
  • Loading branch information
jfahrer committed Mar 11, 2018
1 parent 86934f2 commit 0edb9c9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
@@ -0,0 +1,21 @@
FROM ruby:2.4.3

RUN apt-get update && apt-get install -y postgresql-client

WORKDIR /tmp
COPY Gemfile* ./
RUN bundle install

WORKDIR /app
COPY . .

ARG WAIT_FOR_POSTGRES=false
ARG PREPARE_DATABASE=false

ENV WAIT_FOR_POSTGRES=$WAIT_FOR_POSTGRES PREPARE_DATABASE=$PREPARE_DATABASE
ENV POSTGRES_HOST=localhost POSTGRES_USER=web_app POSTGRES_PASSWORD=

EXPOSE 9292

ENTRYPOINT ["/app/bin/docker-entrypoint.sh"]
CMD ["bundle", "exec", "rackup", "-o", "0.0.0.0"]
11 changes: 11 additions & 0 deletions bin/docker-entrypoint.sh
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
if [ "$WAIT_FOR_POSTGRES" == "true" ]; then
echo Waiting for postgres to start...
while ! pg_isready -h $POSTGRES_HOST > /dev/null; do
sleep 0.5; done
echo ..done
fi
if [ "$PREPARE_DATABASE" == "true" ]; then
bundle exec rake db:create db:migrate
fi
exec "$@"
10 changes: 10 additions & 0 deletions docker-compose.override.yml
@@ -0,0 +1,10 @@
version: '3.3'

services:
app:
build:
context: .
volumes:
- ./:/app
ports:
- 9292:9292
15 changes: 15 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,15 @@
version: '3.3'

services:
app:
image: jfahrer/demo_web_app:latest
environment:
- POSTGRES_HOST=pg
- POSTGRES_USER=web_app
- POSTGRES_PASSWORD=secret

pg:
image: postgres:9.6.6-alpine
environment:
- POSTGRES_USER=web_app
- POSTGRES_PASSWORD=secret
10 changes: 10 additions & 0 deletions scripts/setup-env.sh
@@ -0,0 +1,10 @@
#!/bin/bash
docker-compose down

docker-compose up -d pg

echo "Setting up the development database"
docker-compose run --rm -e WAIT_FOR_POSTGRES=true app bundle exec rake db:create db:migrate

echo "Setting up the test database"
docker-compose run --rm -e RACK_ENV=test app bundle exec rake db:create db:migrate

0 comments on commit 0edb9c9

Please sign in to comment.