diff --git a/Dockerfile b/Dockerfile index da0df741..c005cc67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,16 @@ -FROM ruby:2.3-onbuild - +FROM ruby:2.3 RUN \ apt-get update \ - && apt-get install -y --no-install-recommends nodejs \ + && apt-get install -y --no-install-recommends netcat nodejs \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ +RUN bundle install + +COPY . /usr/src/app diff --git a/README.md b/README.md index ebd6586e..0a9a8e55 100644 --- a/README.md +++ b/README.md @@ -108,21 +108,19 @@ Finally you can boot the rails app: ```bash rails s ``` -#### Docker Compose +#### Docker -If you're familiar with [Docker](https://docs.docker.com/engine/) and [Docker Compose](https://docs.docker.com/compose/), the included `docker-compose.yml` configuration allows you to spin up the application locally. +You can use Docker to run Octobox in development. -First, launch an instance of PostgreSQL and wait for it to fully initialize: +First, [install Docker](https://docs.docker.com/engine/installation/). If you've got run macOS or Windows, Docker for Mac/Windows makes this really easy. + +Then, run: ```bash -docker-compose up database +GITHUB_CLIENT_ID=yourclientid GITHUB_CLIENT_SECRET=yourclientsecret docker-compose up --build ``` -Once the PostgreSQL initialization process is complete, launch the application using another terminal session: - -```bash -GITHUB_CLIENT_ID=yourclientid GITHUB_CLIENT_SECRET=yourclientsecret docker-compose up app -``` +Octobox will be running on [http://localhost:3000](http://localhost:3000). **Note**: You can add `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` to a `.env` file instead of supplying them directly on the command-line. diff --git a/bin/docker-start b/bin/docker-start new file mode 100755 index 00000000..641ecdfc --- /dev/null +++ b/bin/docker-start @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +while ! nc -z database.service.octobox.internal 5432; do + echo "Waiting for database to be available..." + sleep 1 +done + +bundle exec rake db:migrate +rm -rf tmp/pids + +exec rails s -b 0.0.0.0 diff --git a/docker-compose.yml b/docker-compose.yml index dd182c18..a977cdfa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: - POSTGRES_PASSWORD=development app: - image: github-inbox + image: octobox build: context: ./ dockerfile: Dockerfile @@ -23,4 +23,4 @@ services: - OCTOBOX_DATABASE_USER=postgres - OCTOBOX_DATABASE_PASSWORD=development - OCTOBOX_DATABASE_HOST=database.service.octobox.internal - command: sh -c 'bundle exec rake db:migrate && rm -rf tmp/pids && rails s -b 0.0.0.0' + command: bin/docker-start