Intro
This guide will help you set up a development environment for OFN on Ubuntu 22.04 LTS or Ubuntu 20.04 LTS.
Step 1. Install Ruby, Node.js, Yarn, and rbenv
This section is based on instructions here (22.04) and here (20.04). Those instructions include a section on configuring git. That is optional, but may be useful to you. Rails does not need to be installed now. It is installed by a setup script in a later step.
The version of Ruby used in OFN is shown here. At the time of writing it is 3.2.9. If it has changed, the commands below starting with rbenv will need to be adjusted (and this guide updated).
The version of Node is shown here. It's recommended to install nodenv to ensure you have the matching version. Here is a great script to install it: Installing nodenv on Ubuntu. Alternatively you can install as per below. We are using imagemagick and libvips for image processing.
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn imagemagick libvips
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 3.2.9
rbenv global 3.2.9
gem install bundler
rbenv rehash
Alternatively, you may use single version manager (asdf)
If you want to use the single version manager like asdf to manage both ruby and node versions, you may follow these steps:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.18.0
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
echo '. "$HOME/.asdf/internal/completions/asdf.bash"' >> ~/.bashrc
source ~/.bashrc
asdf --version
# Add Plugins
asdf plugin add ruby
asdf plugin add nodejs
asdf install ruby <version in .ruby-version>
asdf install nodejs <version in .node-version>
ruby -v
node -v
npm install -g yarn
So now ruby, node and yarn are installed via asdf version manager. Last step we need to do is to add a config to support rbenv and nodeenv version files with asdf. For that we need to make sure ${HOME}/.asdfrc should have legacy_version_file = yes present in it.
Step 2. Install PostgreSQL and Redis
This will install PostgreSQL, the database that OFN uses, and Redis, which is used for caching. It also installs a supporting library for PostgreSQL.
sudo apt install postgresql redis-server libpq-dev
Step 3. Clone the OFN codebase and set it up
As per the Getting Started document, fork the OFN repo then enter the following to clone it and set up the database superuser.
cd
git clone https://github.com/YOUR_GITHUB_USERNAME_HERE/openfoodnetwork
cd openfoodnetwork
git remote add upstream https://github.com/openfoodfoundation/openfoodnetwork
git fetch upstream master
sudo -u postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'"
Step 4. Run the setup script and final steps
The next step is to run the setup script:
script/setup
Check the console output for error messages. Here are hints how to fix them. Then run the script again.
Unable to connect to server: could not connect to server: Connection refused : Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?- Look for the port number in the message and make sure that the same port is set in the
postgresql.conffile. You should find the file in/etc/postgresql/<version>/main. - Restart PostgreSQL by running
sudo service postgresql restart
- Look for the port number in the message and make sure that the same port is set in the
Error: EACCES: permission denied, access '<SOME_PATH>'- Maybe the best way is to run the script as sudo, I haven't tried that. For me the steps below worked - probably not recommended.
- You can check the access rights with
ls -la '<SOME_PATH>'. - Change ownership to your user with
sudo chown -R <$USER> <SOME_PATH>.
The script above does not install foreman, which is used to start the dev server. Install it with
gem install foreman
Exit your shell and reopen it for the setting to take effect. You can then run the dev server with
foreman start
Step 5. Install Chromium and driver
Chrome or Chromium is used for UI testing. This is automated using a driver. Install them with
sudo apt install -y chromium-browser
sudo apt install -y chromium-chromedriver
Step 6. Prepare the Database for Testing
Tests, both unit and integration, are based on RSpec. To run the test suite, first prepare the test database:
bundle exec rake db:test:prepare
For more details on testing, please check that section of the GETTING_STARTED guide.
Home
Development environment setup
- Pipeline development process
- Bug severity
- Feature template (epic)
- Internationalisation (i18n)
- Dependency updates
Development
- Developer Guidelines
- The process of review, test, merge and deploy
- Making a great commit
- Making a great pull request
- Code Conventions
- Database migrations
- Testing and Rspec Tips
- Testing GitHub Actions Locally with act
- Automated Testing Gotchas
- Rubocop
- Angular and OFN
- Feature toggles
- Stimulus and Turbo
Testing
- Testing process
- OFN Testing Documentation (Handbooks)
- Continuous Integration
- Parallelized test suite with knapsack
- Karma
Releasing
Specific features
Data and APIs
- API documentation
- Authentication
- Integration & API
- Data migration
- Data model diagram (ERD)
- Stripe
- DFC Guide
Instance-specific configuration
External services
Design