Efficiently Manage Your Empress Apps Using the Bench Command-Line Tool

Introduction

Welcome to our comprehensive guide on Bench, the command-line tool for managing Empress apps and sites. Bench is an indispensable tool for developers, particularly when it comes to the creation, management, and deployment of Empress applications. This guide will provide an in-depth exploration of Bench, highlighting its core functionalities and demonstrating how to effectively integrate it into your development process.

Getting Started with Bench

To commence, it’s essential to install Bench on your local system. After installation, you should be able to run commands that start with bench.

To test your installation, you can run the following command:

$ bench --version
5.1.0

Creating the frappe-bench Directory

The next step is to create a project folder, which we’ll denote as frappe-bench, to house our apps and sites. Use the following command:

$ bench init frappe-bench

This command will create a directory named frappe-bench in your current working directory. It performs the following actions:

  1. Creates a Python virtual environment under the env directory.
  2. Fetches and installs the frappe app as a Python package.
  3. Installs node modules of frappe.
  4. Builds static assets.

Understanding the Directory Structure

The frappe-bench directory follows a specific structure:

.
├── Procfile
├── apps
│   └── frappe
├── config
│   ├── pids
│   ├── redis_cache.conf
│   ├── redis\_queue.conf
│   └── redis\_socketio.conf
├── env
│   ├── bin
│   ├── include
│   ├── lib
│   └── share
├── logs
│   ├── backup.log
│   └── bench.log
└── sites
    ├── apps.txt
    ├── assets
    └── common\_site\_config.json

The key components of this structure are:

  • env: This is your Python virtual environment.
  • config: This directory contains configuration files for Redis and Nginx.
  • logs: This directory stores log files for every process (web, worker).
  • sites: This directory contains all your sites.
  • apps: This directory houses all your Empress apps.
  • Procfile: This file contains a list of processes that run in development.

Starting the Bench Server

After setting up the frappe-bench directory, you can start the Empress web server using the following commands:

$ cd frappe-bench
$ bench start

This will initialize several processes including a Python web server based on Gunicorn, Redis servers for caching, job queuing and socketio pub-sub, background workers, a Node server for Socket.IO, and another Node server for compiling JS/CSS files.

The web server will start listening on port 8000. However, at this point, we don’t have any sites to serve yet. The next step is to create an application and a site that will host this app.

Remember to keep the terminal running bench start open. If you need to run additional bench commands, open a new terminal and navigate into the frappe-bench directory.

Congratulations! You have successfully set up Bench and started the Empress server. In the next steps of this guide, we will learn how to create a Empress app and integrate it with the server.

Stay tuned for the next part of the guide where we will delve into app creation and site management with Bench!