Skip to content

Deploying Open Food Network

Introduction

Open Food Network (OFN) is an open-source e-commerce platform designed specifically for local food systems. It enables farmers, producers, food hubs, buying groups, and cooperatives to create online shopfronts and sell directly to consumers, cutting out intermediaries and keeping money within local communities.

Developed by a global community of volunteers and supported by the Open Food Foundation, OFN operates in over 20 countries, connecting thousands of food enterprises with their communities. The platform is built with Ruby on Rails and provides comprehensive features for managing products, orders, inventory, and payments.

Key features of Open Food Network include:

  • Multi-Enterprise Support: Host multiple producers, hubs, and shops on a single platform
  • Flexible Shop Types: Support for farm shops, buying groups, food hubs, and farmers markets
  • Order Cycles: Time-limited ordering windows that match production and delivery schedules
  • Inventory Management: Per-enterprise inventory control with variant support
  • Payment Integration: Stripe, PayPal, and manual payment options
  • Reports and Analytics: Sales, packing, and delivery reports for enterprise management
  • Customer Management: Customer accounts, groups, and subscription ordering
  • White-Label Options: Customizable branding for each enterprise
  • Mobile Responsive: Works seamlessly on desktop and mobile devices

This guide walks through deploying Open Food Network on Klutch.sh using Docker.

Why Deploy Open Food Network on Klutch.sh

Deploying Open Food Network on Klutch.sh supports local food system initiatives:

Community Infrastructure: Provide reliable e-commerce infrastructure for local food producers without requiring them to manage servers.

Persistent Storage: Store product catalogs, order history, and enterprise data with persistent volumes.

HTTPS by Default: Secure transactions and customer data with automatic SSL certificates.

Scalable Resources: Handle increased traffic during order cycles and peak seasons.

Custom Domains: Use a regional or community-specific domain for your food network.

Prerequisites

Before deploying Open Food Network on Klutch.sh, ensure you have:

  • A Klutch.sh account
  • A GitHub account with a repository for your deployment
  • A PostgreSQL database instance
  • SMTP credentials for transactional emails
  • Payment gateway accounts (Stripe, PayPal)

Deploying Open Food Network on Klutch.sh

    Set Up PostgreSQL Database

    Deploy a PostgreSQL database on Klutch.sh or use an external database service. Note your database credentials.

    Create Your Dockerfile

    Create a Dockerfile in your repository:

    FROM ruby:3.1-slim
    # Install dependencies
    RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    nodejs \
    npm \
    git \
    imagemagick \
    libvips-dev \
    && rm -rf /var/lib/apt/lists/*
    # Install Yarn
    RUN npm install -g yarn
    # Clone OFN repository
    WORKDIR /app
    RUN git clone https://github.com/openfoodfoundation/openfoodnetwork.git .
    # Install Ruby dependencies
    RUN bundle install --without development test
    # Install JavaScript dependencies
    RUN yarn install
    # Precompile assets
    RUN bundle exec rails assets:precompile
    EXPOSE 3000
    CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

    Configure Environment

    Create necessary environment variables for database connection, payment gateways, and email configuration.

    Push to GitHub

    Commit and push your Dockerfile to your GitHub repository.

    Create a New Project on Klutch.sh

    Navigate to the Klutch.sh dashboard and create a new project.

    Create and Configure the App

    Create a new app and connect it to your GitHub repository.

    Configure HTTP Traffic

    Set the traffic type to HTTP with an internal port of 3000.

    Set Environment Variables

    Configure required environment variables:

    VariableDescription
    DATABASE_URLPostgreSQL connection string
    SECRET_KEY_BASERails secret key
    SMTP_HOSTEmail server hostname
    STRIPE_API_KEYStripe payment key
    SITE_URLYour deployment URL

    Attach Persistent Volumes

    Add persistent storage:

    Mount PathRecommended SizePurpose
    /app/public/system20 GBUploaded images and files
    /app/storage10 GBActive Storage files

    Deploy Your Application

    Click Deploy to build and launch your Open Food Network instance.

    Run Database Migrations

    After deployment, run database migrations to set up the schema.

    Create Admin Account

    Access the Rails console or use seed data to create your initial admin account.

Additional Resources