Skip to content

Commit

Permalink
Fix setup for development with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Oct 30, 2017
1 parent 9d588f7 commit d01901c
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 190 deletions.
39 changes: 39 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM ruby:2.3

WORKDIR /usr/src/app

# Install dependencies
RUN deps='libmagic-dev xvfb qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x' && \
apt-get update && \
apt-get install --no-install-recommends -y $deps && \
rm -Rf /var/lib/apt/lists/* /var/cache/apt/*

ENV PORT=3000 \
SMTP_SERVER_PORT=2525 \
RAILS_ENV=development \
RAILS_LOG_TO_STDOUT=true \
RAILS_SERVE_STATIC_FILES=true \
\
BUNDLE_PATH=/home/app/bundle \
BUNDLE_APP_CONFIG=/home/app/bundle/config

# Run app and all commands as user 'app'. This avoids changing permissions
# for files in mounted volume. Symlink for similarity with production image.
RUN adduser --gecos GECOS --disabled-password --shell /bin/bash app && \
mkdir -p /home/app/src && ln -s /home/app/src /usr/src/app
USER app

# Copy files needed for installing gem dependencies, and install them.
COPY Gemfile Gemfile.lock ./
COPY plugins ./plugins
RUN bundle config build.nokogiri "--use-system-libraries" && \
bundle install -j 4

# Copy the application code
COPY . ./

EXPOSE 3000

# cleanup, and by default start web process from Procfile
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["./proc-start", "web"]
2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Xvfb $DISPLAY -nolisten tcp &
XVFB_PID=$!

# Start tests
rspec
rspec $@

# Cleanup
kill $XVFB_PID
60 changes: 0 additions & 60 deletions doc/DEPLOYMENT.md

This file was deleted.

30 changes: 18 additions & 12 deletions doc/SETUP_DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Getting foodsoft running for development
========================================
# Getting Foodsoft running for development

Gratulations, if you read this file locally, you have successfully cloned the
foodsoft project from the git repository. Now you are only a few steps away
from trying it out and then jumping into development.

This document describes how to setup Foodsoft for development on your local system.
Alternatively, you [run Foodsoft using Docker](SETUP_DOCKER.md). Or if you just want to
run Foodsoft without changing its code, the
[Turnkey Linux Foodsoft appliance](http://www.turnkeylinux.org/foodsoft) may be useful.

This document describes how to setup Foodsoft for development within your local
system. Another option is to use [docker for development](SETUP_DEVELOPMENT_DOCKER.md).
If instead you just want to run Foodsoft without changing its code, please refer to
[hosting](https://foodcoops.github.io/foodsoft-hosting/) or
[deployment](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes).

**System requirements**:
[RVM](https://rvm.io/rvm/install),
Expand All @@ -20,8 +19,7 @@ run Foodsoft without changing its code, the
**Optional**:
[Redis](http://redis.io/).

Getting started
---------------
### Getting started

0. Clone the repository from GitHub:

Expand Down Expand Up @@ -100,9 +98,7 @@ Getting started
9. Have phun!



Manual configuration
--------------------
### Manual configuration

The rake task `foodsoft:setup_development` helps you to setup foodsoft.
If you want to have more control, you can do these steps manually as
Expand Down Expand Up @@ -173,3 +169,13 @@ explained here.
From now on you have a smtp server listening on 1025. To see the emails go to

http://localhost:1080


## Docker

To avoid having to go through setting up all dependencies, you can also run Foodsoft
within a docker image. While the default [`Dockerfile`](../Dockerfile) is setup for production,
[`Dockerfile.dev`](../Dockerfile.dev) is meant for development. Even better, you can
use docker-compose (using [`docker-compose.dev.yml`](../docker-compose.dev.yml)) to
setup the whole stack at once.

82 changes: 82 additions & 0 deletions doc/SETUP_DEVELOPMENT_DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Foodsoft on Docker

This document explains setting up Foodsoft with Docker for development.
system. Another option is to run it [within an existing system](SETUP_DEVELOPMENT.md).
If instead you just want to run Foodsoft without changing its code, please refer to
[hosting](https://foodcoops.github.io/foodsoft-hosting/) or
[deployment](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes).


## Requirements

* Docker (=> 1.9.1)
* Docker Compose (=> 1.4)
* 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

Then setup foodsoft development (this will take some time, containers needs
to be pulled from docker registry and a lot dependencies needs to be installed)

docker-compose -f docker-compose-dev.yml run web rake foodsoft:setup_development

Do not enable mailcatcher, because this is already included as a docker image.

To avoid having to pass the `-f` argument all the time, it is recommended to setup
an alias, e.g. by adding the following line to your ~/.bashrc

alias docker-compose-dev='docker-compose -f docker-compose-dev.yml'

then reload it by executing `. ~/.bashrc`. Following commands assume this is setup.


## Usage

Start containers (in foreground, stop them with `Ctrl-C`)

docker-compose-dev up

Run a rails/rake command

docker-compose-dev run --rm web rake db:migrate

Open a rails console

docker-compose-dev run --rm web rails c

Setup the test database

docker-compose-dev run --rm web rake db:setup RAILS_ENV=test DATABASE_URL=mysql2://root:secret@mariadb/test

Run the tests

docker-compose-dev run --rm web ./bin/test

Jump in a running container for debugging.

docker exec -ti foodsoft_web_1 bash


## Notes

### Receiving mails

Go to [http://localhost:1080](http://localhost:1080)

### Gemfile updates

As the gem bundle is stored in a volume, you can run

docker-compose-dev run web bundle install
docker-compose-dev restart web worker

Do this each time you update your `Gemfile`.

### Database configuration

To make this easier we use the environment variable `DATABASE_URL`
(and `TEST_DATABASE_URL` when using the testing script).
66 changes: 0 additions & 66 deletions doc/SETUP_DOCKER.md

This file was deleted.

67 changes: 60 additions & 7 deletions doc/SETUP_PRODUCTION.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
Running Foodsoft in production
==============================
# Deployment

As you might have noticed, documentation is scarce and insufficient. If you
intend to deploy foodsoft in production, we would love to guide you through the
process. You can contact the mailing list
[foodsoft-discuss](http://foodsoft.51229.x6.nabble.com/foodsoft-discuss-f5.html).
The recommended way to run Foodsoft in production is using docker. Alternative options are
discussed [in the wiki](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes). If you
have any questions, please contact the mailing list [foodsoft-discuss](http://foodsoft.51229.x6.nabble.com/foodsoft-discuss-f5.html).

## Docker

_This section is a work in progress._

### Build

You can use the [official production docker image](https://hub.docker.com/r/foodcoops/foodsoft/).
If you want to build the image yourself instead, run:

docker build --tag foodsoft:latest --rm .

### Run (basic)

You'll need to set at least the following environment variables:

* `SECRET_KEY_BASE` - random string of 30+ characters, try `rake secret`
* `DATABASE_URL` - pointing to your MySQL installation (`mysql2://user:pass@mysql.host/foodsoftdb?encoding=utf8`)
* `REDIS_URL` - pointing to your Redis instance (`redis://redis.host:6379`)

You'll also need to supply the Foodsoft configuration file, for example by
mounting it as a volume. Copy `config/app_config.yml.SAMPLE` to `config/app_config.yml`
and customize the settings.

Then run the webserver, exposing port 3000 on the current host:

docker run --name foodsoft_web -p 3000 \
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL -e RAILS_FORCE_SSL=false \
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \
foodsoft:latest

This should get you started. But first you'll need to populate the database:

docker run --name foodsoft_setup --rm \
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL \
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \
foodsoft:latest bundle exec rake db:setup

To run the worker (recommended!), supply a different command
(see [Procfile](../Procfile) for other types):

docker run --name foodsoft_worker \
-e SECRET_KEY_BASE -e DATABASE_URL -e REDIS_URL \
-v `pwd`/config/app_config.yml:/usr/src/app/config/app_config.yml:ro \
foodsoft:latest ./proc-start worker

To also run the cronjobs, start the previous command but substituting
`mail` with `cron`. That should give you the ingredients for a production-setup.
With the help of a front-end webserver doing ssl, of course.


### Run (docker-compose)

In practice, you'd probably want to use docker-compose. If you know Docker well enough,
you'll have no problem to set this up. For inspiration, look at the
[foodcoops.net production setup](https://github.com/foodcoops/foodcoops.net).

Please see our wiki page: [Deployment notes](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes).
Loading

0 comments on commit d01901c

Please sign in to comment.