Improve Docker setup (PR #497)

This commit is contained in:
wvengen 2017-10-01 13:57:36 +02:00 committed by GitHub
parent 01950b48a1
commit 0363f2dadc
13 changed files with 236 additions and 108 deletions

View file

@ -1,8 +1,67 @@
Deployment
=========
# Deployment
Setup
-----
## Docker
_This section is a work in progress._
### Build
To build the docker image, run:
docker build --tag foodsoft:dev --rm .
There is also an [official production docker image](https://hub.docker.com/r/foodcoops/foodsoft/),
which will let you avoid this step.
### 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:dev
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:dev 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:dev ./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).
## Capistrano
### Setup
1. Initialise your [Capistrano](http://capistranorb.com/) setup
@ -16,8 +75,7 @@ Setup
2. Adapt your configuration in `config/deploy.rb` and `config/deploy/*.rb`
Deploy
------
### Deploy
On your first deploy you should run (choose either staging or production)

View file

@ -141,18 +141,7 @@ explained here.
Edit `app_config.yml` to suit your needs or just keep the defaults for now.
4. **Secret token**
The user session are stored in cookies. Do avoid misusing the cookies and
its sensitive information, rails will encrypt it with a token. So copy the
config file
cp config/initializers/secret_token.rb.SAMPLE config/initializers/secret_token.rb
and modify the token!! You can run `bundle exec rake secret`
5. **Create database (schema) and load defaults**
4. **Create database (schema) and load defaults**
rake db:setup
@ -160,7 +149,7 @@ explained here.
password 'secret'.
6. (optional) Get **background jobs** done
5. (optional) Get **background jobs** done
Time intensive tasks may block the web request. To run these in a separate
task, you can install Redis and enable Resque:
@ -173,7 +162,7 @@ explained here.
`resque-web`.
7. (optional) **View mails in browser** instead in your logs
6. (optional) **View mails in browser** instead in your logs
We use mailcatcher in development mode to view all delivered mails in a
browser interface. Just install mailcatcher with gem install mailcatcher

View file

@ -1,13 +1,9 @@
Running foodsoft in production
Running Foodsoft in production
==============================
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),
or mail some of us directly at
[developers@foodcoop.nl](mailto:developers@foodcoop.nl) or foodsoft (at)
foodcoops.net.
[foodsoft-discuss](http://foodsoft.51229.x6.nabble.com/foodsoft-discuss-f5.html).
* [Passenger](https://www.phusionpassenger.com/) may be convenient.
* Redis is required for production by default.
Please see our wiki page: [Deployment notes](https://github.com/foodcoops/foodsoft/wiki/Deployment-notes).