6.6 KiB
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. If instead you just want to run Foodsoft without changing its code, please refer to hosting or deployment.
System requirements: rbenv, Ruby 2.7+, Bundler, MySQL / SQLite, Redis (optional).
Getting started
-
Clone the repository from GitHub:
git clone https://github.com/foodcoops/foodsoft.git
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)
Note: When developing on Windows you might run into issues with shell scripts because of Git auto-crlf. Have a look how to avoid that in the Docker Development Setup instructions.
-
Install developement packages. For Debian/Ubuntu:
sudo apt install default-libmysqlclient-dev libmagic-dev libxml2-dev libxslt-dev
-
Install and setup rbenv and Bundler. For Debian/Ubuntu:
sudo apt install rbenv
For other distributions have a look at the rbenv documentation.
Add the following line to your
.bashrc
:eval "$(rbenv init -)"
Install ruby-build:
mkdir -p "$(rbenv root)"/plugins git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Change to the Foodsoft directory and install the recommended Ruby version:
rbenv install "$(cat .ruby-version)"
Now you can install Bundler:
rbenv exec gem install bundler
-
Install system dependencies.
For Debian/Ubuntu, that's:
sudo apt install libv8-dev default-libmysqlclient-dev libxml2-dev libxslt1-dev libffi-dev libreadline-dev libmagic-dev
For CentOS/Redhat you need:
sudo yum install v8 community-mysql-devel libxml2-devel libxslt-devel libffi-devel readline-devel file-devel
-
Install Ruby dependencies:
rbenv exec bundle install
-
Setup your development environment:
rbenv exec rails foodsoft:setup_development
This will interactively prompt with several questions relating to your required environment.
Important: After selecting your database type,
rails
will create the fileconfig/database.yml
, which then then be edited with workingusername
andpassword
credentials for the database. These fields must be added for development AND (temporary) test databases. Then continue with confirmation in rails dialogue. -
Start rails by running:
rbenv exec rails s
-
Open your favorite browser and open the web browser at:
http://localhost:3000/
You might want to watch a kitten video while it's loading.
-
Login using the default credentials:
admin/secret
-
Change the admin password, just in case.
-
Have phun!
For running integration tests, you also need the Chromium/Chrome web browser.
On Debian that would be apt-get install chromium
, on Ubuntu
sudo apt-get install chromium-browser
.
Manual configuration
The rails 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.
-
Configure database
Create the database configuration from the default:
cp config/database.yml.SQLite_SAMPLE config/database.yml
If you are fine with using a file-based sqlite database you are all set. The sqlite files (
development/test/production
) will reside in thedb
directory. Otherwise you would want to copy one of the otherdatabase.yml.*_SAMPLE
files and editdatabase.yml
to suit your needs. -
Configure development environment
Again, you need to create your own copy of the default configuration:
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.
-
Foodsoft settings
You need to create your own copy of the foodsoft configuration settings:
cp config/app_config.yml.SAMPLE config/app_config.yml
Edit
app_config.yml
to suit your needs or just keep the defaults for now. -
Create database (schema) and load defaults
rbenv exec rails db:setup
With this, you also get a ready to go user with username 'admin' and password 'secret'.
-
(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:
-
Comment
Resque.inline = true
inconfig/environments/development.rb
-
Install Redis (Debian/Ubuntu package
redis-server
) -
Run the worker:
rbenv exec rails resque:work QUEUE=*
To have look on the current queue, failed jobs etc start the resque server with
resque-web
. -
-
(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
rbenv exec gem install mailcatcher
and start the service with:mailcatcher
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
is setup for production,
Dockerfile-dev
is meant for development. Even better, you can
use docker-compose (using docker-compose-dev.yml
) to
setup the whole stack at once.
See Setup Development Docker for a detailed description.