Skip to content

Instantly share code, notes, and snippets.

@tomstuart
Last active January 2, 2016 01:28
Show Gist options
  • Save tomstuart/8230069 to your computer and use it in GitHub Desktop.
Save tomstuart/8230069 to your computer and use it in GitHub Desktop.
Running a basic Ruby app with Fig on OS X

You must already have pip (brew install python), Vagrant (from the OS X installer, not the gem) and VirtualBox installed.

First, install Docker:

$ curl https://raw.github.com/noplay/docker-osx/master/docker > /usr/local/bin/docker
$ chmod +x /usr/local/bin/docker
$ docker version

Then install Fig:

$ sudo pip install fig

Make a directory:

$ mkdir figtest
$ cd figtest

Inside this directory, create app.rb:

require 'redis'
require 'sinatra'

redis = Redis.new host: ENV['FIGTEST_REDIS_1_PORT_6379_TCP_ADDR'], port: ENV['FIGTEST_REDIS_1_PORT_6379_TCP_PORT']

get '/' do
  redis.incr('hits')
  "Hello World! I have been seen #{redis.get('hits')} times."
end

Make a Gemfile containing the Ruby dependencies:

source 'https://rubygems.org/'

gem 'redis'
gem 'sinatra'

Then create a Dockerfile to explain how to build a Docker image:

FROM stackbrew/ubuntu:13.10
RUN apt-get -qq update
RUN apt-get install -y ruby
RUN gem install --no-rdoc --no-ri bundler
ADD . /code
WORKDIR /code
RUN bundle install
EXPOSE 4567
CMD bundle exec ruby app.rb -o 0.0.0.0

Then define the set of services with fig.yml:

web:
  build: .
  ports:
   - 4567:4567
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: orchardup/redis

Finally, run fig up:

$ fig up
Pulling image orchardup/redis...
Building web...
Starting figtest_redis_1...
Starting figtest_web_1...
figtest_redis_1 | [7] 03 Jan 00:11:08.751 # Server started, Redis version 2.8.3
figtest_web_1 | == Sinatra/1.4.4 has taken the stage on 4567 for development with backup from WEBrick

You should now be able to reach the app on http://localdocker:4567/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment