Skip to content

Commit

Permalink
Basic Docker containerization for development
Browse files Browse the repository at this point in the history
This setup uses docker-compose and the official ruby, postgres,
elasticsearch, and redis images. The README describes how to set up a
development environment, this replaces the old Vagrant setup.
  • Loading branch information
blinry committed May 28, 2018
1 parent 9cd9103 commit 7c87b52
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
.gitignore

Dockerfile
docker-compose.yml

*.txt
*.md

tmp
log
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Use the the official Ruby image as a base
FROM ruby:2.4.1

# Install runtime dependencies
# Node.js is used for JavaScript compression via the uglifier gem
RUN apt-get update -qq && apt-get install -y nodejs

WORKDIR /voctoweb

# Install required gems
COPY Gemfile Gemfile.lock /voctoweb/
RUN gem install bundler && bundle install
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,27 @@ Update view counts of events viewed in the last 30 minutes
/api/events/update_view_counts


#### Setup Development-Server
```
# for ubuntu and debian one might want to install vagrant from upstream
# (https://www.vagrantup.com/downloads.html), because of a packaging bug:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818237
$ sudo apt-get install vagrant virtualbox
## Set up development environment

$ vagrant plugin install vagrant-hostsupdater
$ vagrant up
$ vagrant ssh -c 'cd /vagrant && ./bin/update-data'
A convenient way to set up an environment for developing voctoweb is [Docker](https://www.docker.com).

http://media.ccc.vm:3000/ <- Frontend
http://media.ccc.vm:3000/admin/ <- Backend
Backend-Login:
Username: admin@example.org
Password: media123
First, install Docker and [Docker Compose](https://docs.docker.com/compose/) – you will probably find them in your distribution's package manager.

Then, clone this repository, make it your working directory, and run the following commands:

```
cp config/database.yml.docker config/database.yml
cp config/settings.yml.template config/settings.yml
docker-compose build
docker-compose run voctoweb rake db:setup
docker-compose run voctoweb bin/update-data
docker-compose up
```

You can now reach the voctoweb frontend at `http://localhost:3000`. The backend is at `http://localhost:3000/admin/`, with the default username `admin@example.org` and the password `media123`. You can stop the running containers using *Ctrl-C*. To start them again, just run `docker-compose up`.

The whole application directory is mounted into the containers, so all changes you make to the files are reflected inside the application automatically. To run commands inside the voctoweb container, run `docker-compose run voctoweb $COMMAND`. If you ever need to rebuild the containers (because of new dependencies, for example), run the `docker-compose build` command again.

## Install for Production

### Ruby Version
Expand Down
21 changes: 21 additions & 0 deletions config/database.yml.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default: &default
adapter: postgresql
encoding: utf8
username: postgres
password:
host: postgres

development:
<<: *default
database: voctoweb

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: voctoweb_test

production:
<<: *default
database: voctoweb_live
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '2'
services:
voctoweb:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/voctoweb
ports:
- 3000:3000
environment:
- ELASTICSEARCH_URL=elasticsearch:9200
- REDIS_URL=redis://redis:6379/1
depends_on:
- sidekiq
- postgres
- elasticsearch
sidekiq:
build: .
command: bundle exec sidekiq
volumes:
- .:/voctoweb
environment:
- REDIS_URL=redis://redis:6379/1
depends_on:
- postgres
- redis
postgres:
image: postgres:alpine
elasticsearch:
image: elasticsearch:alpine
redis:
image: redis:alpine

0 comments on commit 7c87b52

Please sign in to comment.