Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
This allows to run the blog application within a docker container.
  • Loading branch information
dsager authored and nicolas-fricke committed Oct 11, 2019
1 parent b1479f1 commit fe860ca
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ruby:latest

# Create and switch to a user called app
RUN useradd --create-home --shell /bin/bash blog

WORKDIR /home/blog

# copy gemfile separately to cache step before more frequent code changes :)
COPY Gemfile Gemfile.lock /home/blog/
RUN bundle install

ADD . /home/blog
RUN chown --recursive blog:blog /home/blog

USER blog

EXPOSE 4567

ENTRYPOINT ["bundle","exec"]
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,52 @@ Have a look at this blog hosted on Heroku: https://google-doc-blog.herokuapp.com
* You need a running `ruby` installation >= version 2.3
* Make sure to have the `bundler` gem installed

## Usage
, or

* You need a running docker installation >= version 19.3

## Usage (local)

1. Run `bundle install` to install all required dependencies
1. Run `bundle exec ruby bin/setup.rb` and follow the instructions to set up your environment
1. Execute `bundle exec rackup -p 4567 config.ru` to start the server
1. You should be able to open the webapp via `http://localhost:4567` in your browser

## Usage (docker)

First, build the image
```
docker build --tag google-doc-blog:latest ./
```

Then, run the setup script in a container
```
docker run --rm \
--interactive \
--volume $PWD/config:/home/blog/config \
google-doc-blog:latest \
ruby bin/setup.rb
```

Finally, start the web server in a container
```
docker run --rm \
--publish 4567:4567 \
--volume $PWD:/home/blog \
google-doc-blog:latest \
rackup --port 4567 --host 0.0.0.0 config.ru
```

## Running the tests

Execute `bundle exec rspec` to run the entire test suite.
With docker, run
```
docker run --rm \
--volume $PWD:/home/blog \
google-doc-blog:latest \
rspec
```

## Built With

Expand Down
3 changes: 3 additions & 0 deletions bin/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require_relative '../app/config'
require_relative '../app/google_drive_connector'

# Don't buffer the output to avoid broken IO in docker container...
$stdout.sync = true

puts 'This script will guide you through the required setup steps setup the '\
'blog. Please follow these steps:'

Expand Down

0 comments on commit fe860ca

Please sign in to comment.