Added Dockersupport. See README_DOCKER.md for further instructions.

This commit is contained in:
Benjamin Meichsner 2015-04-26 15:20:05 +02:00
parent 8fca19a2a1
commit 83dd18eaa7
6 changed files with 133 additions and 1 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
.git
.idea
.sass-cache
log
public/assets
public/system
tmp/*
vendor/bundle
coverage
*.sql*

40
Dockerfile Normal file
View File

@ -0,0 +1,40 @@
FROM ruby:2.1-slim
RUN apt-get update && \
apt-get install --no-install-recommends -y \
mysql-client \
git \
make \
gcc \
g++ \
patch \
libsqlite3-dev \
libv8-dev \
libmysqlclient-dev \
libxml2-dev \
libxslt1-dev \
libffi-dev \
libreadline-dev \
xvfb \
iceweasel && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean
ENV WORKDIR /usr/src/app
RUN mkdir -p $WORKDIR
WORKDIR $WORKDIR
# Copy plugins before the rest to allow bundler loading gemspecs
# TODO: Move plugins to gems and add them to Gemfile instead
COPY plugins $WORKDIR/plugins
COPY Gemfile $WORKDIR/
COPY Gemfile.lock $WORKDIR/
RUN bundle install --jobs 4
COPY . $WORKDIR
EXPOSE 3000
CMD ["rails", "server"]

68
README_DOCKER.md Normal file
View File

@ -0,0 +1,68 @@
# Foodsoft on Docker
This document explains setup and using docker the foodsoft with docker.
## Requirements
* Docker (=> 1.5)
* Docker Compose (=> 1.1)
* Nothing more, no ruby, mysql, redis etc!
For installing instructions see https://docs.docker.com/installation/.
Docker runs on every modern linux kernel, but also with a little help on MacOS
and Windows!
## Setup
Create docker volume for mysql data:
mkdir -p ~/.docker-volumes/foodsoft/mysql
Setup foodsoft development data: (This will take some time, containers needs
to be pulled from docker registry and a lot dependencies needs to be installed.)
docker-compose run app rake foodsoft:setup_development
TODO: Right know this is not gonna work because of the new database
configuration via ENV variable. See Notes below.
## Usage
Start containers (in foreground, stop them with `CTRL-C`)
docker-compose up
Run a rails/rake command
docker-compose run app rake db:migrate
Open a rails console
docker-compose run app rails c
Run the tests
docker-compose run app ./bin/test
Jump in a running container for debugging.
docker exec -ti foodsoft_app_1 bash
## Notes
### Gemfile updates
This is bit tricky, as the gemfiles are stored in the container and so we have
to rebuild the container each time we change the Gemfile. To avoid installing
all the gems from scratch we can use this workaround:
```bash
docker-compose run app bundle update rails # Update Gemfile.lock file
docker ps -a # Look for the last exited container and grab the Container ID
docker commit -m "Updated rails" <Container ID> foodsoft_app
```
### Database configuration
TO make thins easier we use the ENV Variable DATABASE_URL. But to make this
work, the shouldn't be any config/database.yml file!

12
bin/test Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
# Set test variables
export DATABASE_URL=mysql2://root:secret@mysql/test
export RAILS_ENV=test
# Start virtuals X environment to allow integration testing via firefox/iceweasel
export DISPLAY=:99
Xvfb :99 &
# Start tests
rspec

View File

@ -39,7 +39,7 @@ Foodsoft::Application.configure do
# Mailcatcher config, start mailcatcher from console with 'mailcatcher'
# Mailcatcher can be installed by gem install mailcatcher
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
config.action_mailer.smtp_settings = { address: "mailcatcher", port: 1025 }
# Run resque tasks as part of the main app (not recommended for production)
Resque.inline = true

View File

@ -0,0 +1,2 @@
# Initializer to configure resque daemon
Resque.redis = ENV.fetch("REDIS_URL", "redis://localhost:6379")