Skip to content

Instantly share code, notes, and snippets.

@tomstuart
Last active January 2, 2016 01:28

Revisions

  1. tomstuart created this gist Jan 3, 2014.
    88 changes: 88 additions & 0 deletions figtest.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    You must already have `pip` (`brew install python`), Vagrant (from the [OS X installer](http://www.vagrantup.com/downloads.html), not the gem) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads) installed.

    First, install Docker:

    ```bash
    $ 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:

    ```bash
    $ sudo pip install fig
    ```

    Make a directory:

    ```bash
    $ mkdir figtest
    $ cd figtest
    ```

    Inside this directory, create `app.rb`:

    ```ruby
    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:

    ```ruby
    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`:

    ```yaml
    web:
    build: .
    ports:
    - 4567:4567
    volumes:
    - .:/code
    links:
    - redis
    redis:
    image: orchardup/redis
    ```
    Finally, run `fig up`:

    ```bash
    $ 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/](http://localdocker:4567/).