|
| 1 | +# Platform Integration - Ruby Web app example |
| 2 | + |
| 3 | +This example shows how to wrap a web application written in Ruby in a Docker container using the community-provided |
| 4 | +[Ruby docker base image](https://hub.docker.com/_/ruby/) and hence should give you a basic overview of how to |
| 5 | +wrap a software application in a docker image based on the existing public language stack images. |
| 6 | + |
| 7 | +The `docker-compose.yml` and `Dockerfile` include comments on what is happening. |
| 8 | + |
| 9 | +## What does it do? |
| 10 | + |
| 11 | +The app directory contains an example ruby app that acts as a caching proxy: It fetches data from another HTTP |
| 12 | +api, caching the response for 30 seconds inside redis because our remote API is slow - for the sake of this demo |
| 13 | +we are using a special HTTP service that intentionally responds very slowly. |
| 14 | + |
| 15 | +## Running it |
| 16 | + |
| 17 | +On your local checkout of this repository, open this directory in your terminal, then launch: |
| 18 | + |
| 19 | + docker-compose up |
| 20 | + |
| 21 | +This should build the app image, pull the redis image and launch both. |
| 22 | + |
| 23 | +You can now `curl localhost`. The first request should take around two seconds since the response is not cached in |
| 24 | +redis yet, subsequent requests should be screaming fast thanks to the cached response stored in our redis container. |
| 25 | +After 30 seconds the cache expires and will be fetched from the upstream server again. |
| 26 | + |
| 27 | +## Stopping it |
| 28 | + |
| 29 | +You can hit `ctrl+c` in your terminal to stop the running services, then you can remove the local containers: |
| 30 | + |
| 31 | + docker-compose rm -f |
| 32 | + |
| 33 | +## Development flow |
| 34 | + |
| 35 | +Running `docker-compose build` will re-build your image as you are putting together your Dockerfile. |
| 36 | + |
| 37 | +Once the image is built, you can also execute the unit tests for the app inside a docker container using: |
| 38 | + |
| 39 | + docker run -i -t --rm examplerubywebapp_app bundle exec rspec spec.rb |
| 40 | + |
| 41 | +This can also be helpful for setting up continuous integration for your image repository. On a CI server, on each |
| 42 | +push to your source code repository you could: |
| 43 | + |
| 44 | + 1. Build the image using `docker build --pull -t myrepo/myapp:latest .` |
| 45 | + 2. Run your test suite inside the container to verify it works: `docker run -i -t --rm myrepo/myapp:latest bundle exec rspec spec.rb` |
| 46 | + 3. Push the image to your registry repo on success: `docker push myrepo/myapp:latest` |
0 commit comments