Skip to content

Instantly share code, notes, and snippets.

@fcat
Created October 17, 2013 16:08
Show Gist options
  • Save fcat/7027665 to your computer and use it in GitHub Desktop.
Save fcat/7027665 to your computer and use it in GitHub Desktop.
Gemnasium Workshop @dotrb 2013: Hands-On Part 1

Hands-on part 1: install the app with docker

Part 1 of the Gemnasium workshop at dotRB2013.

Install

Go to gemnasium/dotrb2013-docker and install the gemnasium/dotrb2013 Rails app using docker.

  1. make sure you have docker running, see dotrb2013-docker requirements
  2. install dotrb2013-docker
  3. create a GitHub application, see dotrb2013 for the how-to
  4. create a .env file with your host IP and GitHub client credentials
  5. run make pull and get the docker images (please wait)
  6. run ./bin/postgresql-start and ./bin/rails-start

You should then be able to:

  • visit the root URL of the Rails app
  • sign in using your GitHub account
  • add a pull request URL
  • see the pull resquest metadata after reloading the page (async job)
  • connect to the admin interface and explore the data model

Warning! Admin sessions seem to conflict with normal user sessions.

Warning! Don't forget that rails-start and postgresql-start scripts from dotrb2013-docker create new containers each time you call them!

Save your database

  1. play with the Rails app to fill the database
  2. commit the postgresql container to my-postgreql
  3. create even more data
  4. stop the postgresql container
  5. start a new postgresql container from your my-postgresql image

Commands

  • docker commit
  • docker run
  • docker start

Tips

  • modify the bin/postgresql-start script and change the name of the docker image
  • docker commit needs some specs to re-run the image, use -run='{"Cmd": ["/start", "postgres"], "PortSpecs": ["5432"]}'

Warnings

  • your image name must contain "postgresql", see bin/postgresql-info script

Configure the mailer

  1. create a mailtrap account
  2. create an inbox on mailtrap for the rails app
  3. run the rails container in "console mode"
  4. try your mailer
  5. commit the container to my-rails image

To try your mailer:

  1. add a pull request that has been already merged
  2. connect to the /admin interface and reset the merged_at date
  3. visit /admin/resque, "schedule" tab
  4. enqueue now: update all pull requests
  5. enqueue now: send emails

Obviously, the mailer config should come from somewhere: the repo, some environment variables, some configuration server, etc.

Tips

  • modify the bin/rails-start script and change the name of the docker image
  • when running the container in "console mode", run /rails/start-production as root to get your app running

Retrieve the logs

  • run the rails app
  • do something wrong, call a route that does not exist
  • copy the log file from the container to the host OS (container is still running)
  • production logs live in /rails/log/production.log inside the container

Commands

  • docker cp

Tips

  • docker cp 1234:/xyz . to copy /xyz from the container 1234 to the host operating system

Use your own tools

We can edit the source code of the Rails app using vim inside the container. Or we can push the code using git. But this is not really convenient when working on the source code. Every developer wants her/his own development tools!

  • copy the /rails directory from your container to the host operating system
  • edit the rails-start script and modify docker run command line: make a mount
  • edit the source code on the host OS
  • run the rails container with rails-start
  • you should be able to see your modifications

Tips

  • docker run -v /tmp:/root myImage in order to mount /tmp from the host machine as /root within the image

Postgesql everywhere

The rails app uses sqlite for both development and test environments. But we could use our "postgresql" container everywhere!

  • go into the rails container
  • update the config.yml to match production config everywhere

It's easy to rollback:

  • to an empty database for our test suite
  • to a well-know dataset for our dev environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment