Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Dockerfile docker-compose file and bootstrap script #245

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ config/database.local.yml
.env
docker-compose.yml
.DS_Store
bundle_cache
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ruby:2.3

RUN apt-get update && apt-get install -y nodejs fontconfig

ENV PHANTOM_JS phantomjs-2.1.1-linux-x86_64

RUN curl https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 -O -L
RUN tar xvjf $PHANTOM_JS.tar.bz2
RUN mv $PHANTOM_JS /usr/local/share
RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin

WORKDIR /usr/src/app

CMD rails s -b 0.0.0.0 -p 3000 Puma
59 changes: 40 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,71 @@ Katana is a Ruby on Rails application and it needs:

## Running the application

In the future we might provide some easy ways to run Testributor (Docker image,
AMI etc) but for now you will have to create and run all components on your own.
Here is the walkthrough:
### Using docker-compose

- Clone this project to a directory on your system. E.g.
This is the easiest way because all components are started automatically.
You can use this setup for development or as a base to create a production ready version.

1. Create a `.env` file with all needed environment variables as they are described
in the [Environment Variables section](#environment-variables).
The variables set in this file will also be available inside the containers (created in the next step).
1. Start all containers: `docker-compose -f development-docker-compose.yml up -d`

1. Open the application in your browser at `http://localhost:3000`

In order to simplify development you can use the bin/drun
to run commands inside the container that runs the rails server
(`drun` stands for dockerized-run or something like that).

Example usage:

```
git clone [email protected]:testributor/katana.git
bin/drun bin/rails c # Starts the rails console inside the container
bin/drun rake db:migrate # Runs migrations
bin/drun bash # Starts a bash session inside the container
bin/drun bin/rake test # Runs the test suite inside the container
```

### Database preparation

### Bare metal way

You can use this method if you don't want to use docker containers, want to
install each component in a different machine or do any kind of custom setup.
Here are the steps required to get Testributor up and running:

#### Fetch the code

Clone this project to a directory on your system. E.g.

`git clone [email protected]:testributor/katana.git`

#### Database preparation

- Move to the cloned project's directory: `cd katana`
- Copy `config/database.local.sample.yml` file to `config/database.local.yml`:

```
cp config/database.local.sample.yml config/database.local.yml
```
```cp config/database.local.sample.yml config/database.local.yml```

- Edit the file and change the database details to match a PostgreSQL database
which you want to use.
- Unless the database is already created, run `rake db:create` to create it now.
- Run `rake db:setup` to load the schema and prepare the database.

### Run Socketidio
#### Run Socketidio

Follow the instructions on [Socketidio README](https://github.com/testributor/socketidio)
in order to run socketidio (by default on port 9000).

### Start a background Sidekiq worker
#### Start a background Sidekiq worker

For the application to work you need to have at least one running Sidekiq worker.
From withing the katana project directory run the following command to start one:

```
bundle exec sidekiq -c 3 -q mailers -q default -q low

```

### Environment variables
#### Environment variables

Testributor uses some environment variables for configuration and you will not
be able to start the application unless they are defined. These are:
Expand All @@ -80,13 +105,9 @@ be able to start the application unless they are defined. These are:
default value is "http://localhost:9000" and you don't need to define this
variable if this is correct for your system.

### Start the application

While in the katana project directory start the Rails server:
#### Start the application

```
bin/rails s
```
While in the katana project directory start the Rails server: `bin/rails s`

## Contributing

Expand Down
3 changes: 3 additions & 0 deletions bin/drun
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker exec -it $(docker ps | grep testributor-development-katana | awk '{print $1}') $@
8 changes: 5 additions & 3 deletions config/database.local.sample.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
default: &default
adapter: postgresql
encoding: utf8
host: 'localhost'
username: 'user'
password: 'password'
host: postgres
port: 5432
username: testributor
password: testributor
pool: 5

development:
<<: *default
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# if you're sharing your code publicly.

development:
secret_key_base: fde23d0cadf4ef88f132afc3aa52c1beb01c0d4dd05ee5d6d39e4227853730bcba8b9ce96f95067e80a21c71f12e7fdfda3d2096ce0c27821d7383f44b70da94
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

test:
secret_key_base: 81b0f71065b4733b20069d2d25e2fad98de98776151bf50fb6d24bdb288014d97996674a9a173a22df2967d03063aa3b5a7b6ddcffebb1ee3bee5121f0460164
Expand Down
48 changes: 48 additions & 0 deletions development-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "2"
services:
web:
image: testributor:development
command: "./script/bootstrap_development.sh"
container_name: testributor-development-katana
volumes:
- .:/usr/src/app
# Avoid downloading all gems from scratch by mounting the directory
# on the host. See also bootstrap_development.sh script.
- ./bundle_cache:/vendor/bundle
depends_on:
- postgres
- redis
links:
- postgres
- redis
- socketidio
environment:
RAILS_ENV: development
SECRET_KEY_BASE: e9744e038fb87c6bfb52d5aa0f2f1a865fbd242a6ce162cb6e5cae9e5e90c558c32f369d3d68ea0ae5325916fb55507a164011964edc4ac2bf1a31a0573efe73
REDIS_URL: redis://redis:6379
env_file:
- .env
ports:
- "3000:3000"
postgres:
image: postgres:9.4
container_name: testributor-development-postgres
environment:
POSTGRES_USER: testributor
POSTGRES_PASSWORD: testributor
expose:
- "5432"
redis:
image: redis:3.0
container_name: testributor-development-redis
expose:
- "6379"
socketidio:
image: jimmykarily/socketidio:0.0.2
container_name: testributor-development-socketidio
expose:
- "9000"
links:
- redis
environment:
REDIS_URL: redis://redis:6379
7 changes: 7 additions & 0 deletions script/bootstrap_development.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

gem install bundler
bundle check || bundle install --deployment --path /vendor/bundle --jobs 2 --retry 2
rake db:create
rake db:reset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean development data loss upon each container start?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true. Maybe we should skip the database setup and let the developer/user do this manually. What do you think?

rails s -b 0.0.0.0 -p 3000