foodsoft/doc/SETUP_DEVELOPMENT.md

184 lines
6.6 KiB
Markdown
Raw Normal View History

# 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 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).
2015-05-02 14:26:15 +02:00
**System requirements**:
2014-06-16 16:53:52 +02:00
[RVM](https://rvm.io/rvm/install),
2015-11-14 16:26:34 +01:00
[Ruby 2+](https://www.ruby-lang.org/en/downloads/),
2014-06-16 16:53:52 +02:00
[Bundler](http://bundler.io/),
[MySQL](http://mysql.com/)/[PostgreSQL](http://www.postgresql.org/)/[SQLite](http://sqlite.org/).
**Optional**:
[Redis](http://redis.io/).
### Getting started
0. Clone the repository from GitHub:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
git clone https://github.com/foodcoops/foodsoft.git
2014-06-01 00:46:43 +02:00
This brings up the bleeding-edge development version, which might contain some
unfinished parts. If you want to be safe, choose the last release:
`git checkout $(git tag -l | grep ^v | sort -rn | head -n1)`
2015-11-14 16:26:34 +01:00
1. Install RVM and Ruby 2+ (if you have not done so before):
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
\curl -L https://get.rvm.io | bash
source ~/.rvm/scripts/rvm
rvm install 2.0
We try to keep Foodsoft compatible with Ruby 2.0 as well as any later versions,
so if you use this and don't want to use RVM, that might actually work.
2014-06-16 16:53:52 +02:00
2. Install system dependencies.
For Debian/Ubuntu, that's
[libv8-dev](https://packages.debian.org/stable/libv8-dev)
[libmysqlclient-dev](https://packages.debian.org/stable/libmysqlclient-dev)
[libxml2-dev](https://packages.debian.org/stable/libxml2-dev)
[libxslt1-dev](https://packages.debian.org/stable/libxslt1-dev)
[libffi-dev](https://packages.debian.org/stable/libffi-dev)
2016-05-06 16:00:55 +02:00
[libreadline-dev](https://packages.debian.org/stable/libreadline-dev)
[libmagic-dev](https://packages.debian.org/stable/libmagic-dev)
[libqtwebkit-dev](https://packages.debian.org/stable/libqtwebkit-dev):
2014-06-16 16:53:52 +02:00
2014-06-18 13:26:22 +02:00
# Debian/Ubuntu
sudo apt-get install libv8-dev libmysqlclient-dev libxml2-dev libxslt1-dev libffi-dev libreadline-dev libmagic-dev libqtwebkit-dev
2014-06-16 16:53:52 +02:00
For CentOS/Redhat you need
[v8](https://apps.fedoraproject.org/packages/v8)
[community-mysql-devel](https://apps.fedoraproject.org/packages/community-mysql-devel)
[libxml2-devel](https://apps.fedoraproject.org/packages/libxml2-devel)
[libxslt-devel](https://apps.fedoraproject.org/packages/libxslt-devel)
[libffi-devel](https://apps.fedoraproject.org/packages/libffi-devel)
2016-05-06 16:00:55 +02:00
[readline-devel](https://apps.fedoraproject.org/packages/readline-devel)
[file-devel](https://apps.fedoraproject.org/packages/file-devel)
[qtwebkit-devel](https://apps.fedoraproject.org/packages/qtwebkit-devel):
2014-06-16 16:53:52 +02:00
2014-06-18 13:26:22 +02:00
# CentOS/Redhat
sudo yum install v8 community-mysql-devel libxml2-devel libxslt-devel libffi-devel readline-devel file-devel qtwebkit-devel
2014-06-16 16:53:52 +02:00
3. Install Ruby dependencies:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
bundle install
2014-06-16 16:53:52 +02:00
4. Setup your development environment:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
rake foodsoft:setup_development
2014-06-01 00:46:43 +02:00
This will interactively prompt with several questions relating to your
required environment.
2015-08-10 19:20:33 +02:00
**Important**: After selecting your database type, `rake` will create the file `config/database.yml`,
which then then be edited with working `username` and `password` credentials for the database. These fields
2015-08-10 19:22:24 +02:00
must be added for *development* AND (temporary) *test* databases. Then continue with confirmation in rake dialogue.
2015-08-10 19:20:33 +02:00
2014-06-16 16:53:52 +02:00
5. Start rails by running:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
bundle exec rails s
2014-06-16 16:53:52 +02:00
6. Open your favorite browser and open the web application at:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
http://localhost:3000/
2014-06-01 00:46:43 +02:00
You might want to watch a
[kitten video](https://www.youtube.com/watch?v=9Iq5yCoHp4o)
while it's loading.
2014-06-16 16:53:52 +02:00
7. Login using the default credentials: `admin/secret`
2014-06-16 16:53:52 +02:00
8. Change the admin password, just in case.
2014-06-16 16:53:52 +02:00
9. Have phun!
### 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
explained here.
2013-11-07 20:22:56 +01:00
1. **Configure database**
Create the database configuration from the default:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
cp config/database.yml.SQLite_SAMPLE config/database.yml
2014-06-01 00:46:43 +02:00
If you are fine with using a file-based sqlite database you are all set.
2014-06-01 00:46:43 +02:00
The sqlite files (`development/test/production`) will reside in the `db`
directory. Otherwise you would want to copy one of the other
2014-06-01 00:46:43 +02:00
`database.yml.*_SAMPLE` files and edit `database.yml` to suit your needs.
2. **Configure development environment**
Again, you need to create your own copy of the default configuration:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
cp config/environments/development.rb.SAMPLE config/environments/development.rb
Edit development.rb to specify your settings (at least the ActionMailer SMTP
settings). If you just leave the file as is, emails will not work but
everything else should be okay.
3. **Foodsoft settings**
You need to create your own copy of the foodsoft configuration settings:
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
cp config/app_config.yml.SAMPLE config/app_config.yml
2014-06-01 00:46:43 +02:00
Edit `app_config.yml` to suit your needs or just keep the defaults for now.
2017-10-01 13:57:36 +02:00
4. **Create database (schema) and load defaults**
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
rake db:setup
2014-06-01 00:46:43 +02:00
With this, you also get a ready to go user with username 'admin' and
password 'secret'.
2017-10-01 13:57:36 +02:00
5. (optional) Get **background jobs** done
2014-06-01 00:46:43 +02:00
Time intensive tasks may block the web request. To run these in a separate
task, you can install Redis and enable Resque:
2014-06-01 00:46:43 +02:00
* Comment `Resque.inline = true` in `config/environments/development.rb`
* Install [Redis](http://redis.io/) (Ubuntu package `redis-server`)
* Run the worker: `rake resque:work QUEUE=foodsoft_notifier`
2014-06-01 00:46:43 +02:00
To have look on the current queue, failed jobs etc start the resque server with
`resque-web`.
2017-10-01 13:57:36 +02:00
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
and start the service with
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
mailcatcher
2014-06-01 00:46:43 +02:00
From now on you have a smtp server listening on 1025. To see the emails go to
2014-06-01 00:46:43 +02:00
2014-06-18 13:26:22 +02:00
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.