diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f35093 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index d6520a9..5e971fc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/setup.rb b/bin/setup.rb index c558244..a8f2f5c 100755 --- a/bin/setup.rb +++ b/bin/setup.rb @@ -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:'