From be36a1411c41376ab2eb774541578c5d596c45e0 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 10 Feb 2020 15:01:12 +0530 Subject: [PATCH 01/26] feat(bench update): allow pull-only update on specified apps * renamed method pull_all_apps to pull_apps * allow specifying a list of applications to be updated with: bench update --pull --apps frappe,erpnext * if no applications are specified, all apps present inside apps.txt will be pulled Signed-off-by: Chinmay D. Pai --- bench/app.py | 7 ++++--- bench/commands/update.py | 35 ++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/bench/app.py b/bench/app.py index ea5d2a22..8321a577 100755 --- a/bench/app.py +++ b/bench/app.py @@ -197,13 +197,14 @@ def remove_app(app, bench_path='.'): if get_config(bench_path).get('restart_systemd_on_update'): restart_systemd_processes(bench_path=bench_path) -def pull_all_apps(bench_path='.', reset=False): +def pull_apps(apps=None, bench_path='.', reset=False): '''Check all apps if there no local changes, pull''' rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else '' + apps = apps or get_apps(bench_path=bench_path) # chech for local changes if not reset: - for app in get_apps(bench_path=bench_path): + for app in apps: excluded_apps = get_excluded_apps() if app in excluded_apps: print("Skipping reset for app {}".format(app)) @@ -227,7 +228,7 @@ Here are your choices: sys.exit(1) excluded_apps = get_excluded_apps() - for app in get_apps(bench_path=bench_path): + for app in apps: if app in excluded_apps: print("Skipping pull for app {}".format(app)) continue diff --git a/bench/commands/update.py b/bench/commands/update.py index 82f857ba..e9093fd7 100755 --- a/bench/commands/update.py +++ b/bench/commands/update.py @@ -1,8 +1,9 @@ import click +import re import sys import os from bench.config.common_site_config import get_config, update_config -from bench.app import pull_all_apps, is_version_upgrade, validate_branch +from bench.app import pull_apps, is_version_upgrade, validate_branch from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update, update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, restart_supervisor_processes, restart_systemd_processes, is_bench_directory) @@ -12,6 +13,7 @@ from six.moves import reload_module @click.command('update') @click.option('--pull', is_flag=True, help="Pull changes in all the apps in bench") +@click.option('--apps', type=str) @click.option('--patch', is_flag=True, help="Run migrations for all sites in the bench") @click.option('--build', is_flag=True, help="Build JS and CSS artifacts for the bench") @click.option('--bench', is_flag=True, help="Update bench") @@ -22,7 +24,7 @@ from six.moves import reload_module @click.option('--no-backup', is_flag=True) @click.option('--force', is_flag=True) @click.option('--reset', is_flag=True, help="Hard resets git branch's to their new states overriding any changes and overriding rebase on pull") -def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, force=False, reset=False): +def update(pull=False, apps=None, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, force=False, reset=False): "Update bench" if not is_bench_directory(): @@ -39,16 +41,20 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar patches.run(bench_path='.') conf = get_config(".") + if apps and not pull: + apps = [] + if bench and conf.get('update_bench_on_update'): update_bench(bench_repo=True, requirements=False) restart_update({ - 'pull': pull, - 'patch': patch, - 'build': build, - 'requirements': requirements, - 'no-backup': no_backup, - 'restart-supervisor': restart_supervisor, - 'reset': reset + 'pull': pull, + 'apps': apps, + 'patch': patch, + 'build': build, + 'requirements': requirements, + 'no-backup': no_backup, + 'restart-supervisor': restart_supervisor, + 'reset': reset }) if conf.get('release_bench'): @@ -65,9 +71,9 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar print("This would take significant time to migrate and might break custom apps.") click.confirm('Do you want to continue?', abort=True) - _update(pull, patch, build, bench, auto, restart_supervisor, restart_systemd, requirements, no_backup, force=force, reset=reset) + _update(pull, apps, patch, build, bench, auto, restart_supervisor, restart_systemd, requirements, no_backup, force=force, reset=reset) -def _update(pull=False, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False, +def _update(pull=False, apps=None, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, bench_path='.', force=False, reset=False): conf = get_config(bench_path=bench_path) version_upgrade = is_version_upgrade(bench_path=bench_path) @@ -84,8 +90,11 @@ def _update(pull=False, patch=False, build=False, update_bench=False, auto=False print('Backing up sites...') backup_all_sites(bench_path=bench_path) + if apps: + apps = [app for app in re.split(",| ", apps) if app] + if pull: - pull_all_apps(bench_path=bench_path, reset=reset) + pull_apps(apps=apps, bench_path=bench_path, reset=reset) if requirements: update_requirements(bench_path=bench_path) @@ -121,7 +130,7 @@ def _update(pull=False, patch=False, build=False, update_bench=False, auto=False @click.command('retry-upgrade') @click.option('--version', default=5) def retry_upgrade(version): - pull_all_apps() + pull_apps() patch_sites() build_assets() post_upgrade(version-1, version) From b98c7ed27eeb5dd61abb1d0fe8e9eea156cdbc4f Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 23 Mar 2020 20:59:58 +0530 Subject: [PATCH 02/26] refactor: bench readme * restructure the readme * add docker installation * cite stuff Signed-off-by: Chinmay D. Pai --- README.md | 301 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 195 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index 294520d8..63e2c322 100755 --- a/README.md +++ b/README.md @@ -1,131 +1,211 @@
-

bench

+

Bench

-bench is a command-line utility that helps you to install apps, manage multiple sites and update Frappe / ERPNext apps on */nix (macOS, Ubuntu, Debian, CentOS, etc) for development and production. +Bench is a command-line utility that helps you to install, update, and manage multiple sites for Frappe/ERPNext applications on *nix systems[^nix] for development and production. +## Table of Contents -> **Note**: If you are looking for easier ways to get started and evaluate ERPNext, [download the Virtual Machine](https://erpnext.com/download) or take [a free trial on erpnext.com](https://erpnext.com/pricing). - ---- - -# Table of Contents - - - [bench CLI](#bench-cli) - - [Usage](#usage) - - [Installation](#installation) - - [Custom Bench commands](#custom-bench-commands) - - [Easy Install Script](#easy-install-script) - - [Release Bench](#release-bench) + - [Installation](#installation) + - [Docker Installation](#docker-installation) + - [Development Setup](#docker-installation-for-development) + - [Production Setup](#docker-installation-for-production) + - [Easy Install Script](#easy-install-script) + - [Manual Installation](#manual-installation) + - [Usage](#usage) + - [Custom Bench commands](#custom-bench-commands) + - [Bench Manager](#bench-manager) - [Guides](#guides) - [Resources](#resources) - [License](#license) ---- -# bench CLI - -Bench is a command line tool that helps you install, setup, manage multiple sites and apps based on Frappe Framework. - ---- - -## Usage - -* Create a new bench - - bench init [bench-name] - -* Add a site under current bench - - bench new-site [site-name] - - **Optional**: If the database for the site does not reside on localhost or listens on a custom port, you can use the flags `--db-host` to set a custom host and/or `--db-port` to set a custom port. - - bench new-site [site-name] --db-host [custom-db-host-ip] --db-port [custom-db-port] - -* Add apps to bench - - bench get-app [app-name] [app-link] - -* Install apps on a particular site - - bench --site [site-name] install-app [app-name] - -* Start bench (only for development) - - bench start - -* Show bench help - - bench --help - -_Note:_ Apart from `bench init`, all other bench commands have to be run having the respective bench directory as the working directory. _(`bench update` may also be run, but it's behaviour is covered in depth in the docs)_ - -For more in depth information on commands and usage follow [here](https://github.com/frappe/bench/blob/master/docs/commands_and_usage.md). As for a consolidated list of bench commands, go through [this page](https://github.com/frappe/bench/blob/master/docs/bench_usage.md). - ---- ## Installation -To do this install, you must have basic information on how Linux works and should be able to use the command-line. bench will also create nginx and supervisor config files, setup backups and much more. If you are using on a VPS make sure it has >= 1Gb of RAM or has swap setup properly. +A typical bench setup provides two types of environments -- Development and Production. - git clone https://github.com/frappe/bench ~/.bench - pip3 install --user -e ~/.bench +The setup for each of these installations can be achieved in multiple ways: -As bench is a python application, its installation really depends on `python` + `pip` + `git`. The Frappe Framework, however has various other system dependencies like `nodejs`, `yarn`, `redis` and a database system like `mariadb` or `postgres`. Go through the [installation requirements](https://github.com/frappe/bench/blob/master/docs/installation.md) for an updated list. + - [Docker Installation](#docker-installation) + - [Easy Install Script](#easy-install-script) + - [Manual Installation](#manual-installation) -If you have questions, please ask them on the [forum](https://discuss.erpnext.com/c/bench) under the "Install / Update" category. +We recommend using either the Docker Installation or the Easy Install Script to setup a Production Environment. For Development, you may choose either of the three methods to setup an instance. + +Otherwise, if you are looking to evaluate ERPNext, you can also download the [Virtual Machine Image](https://erpnext.com/download) or register for [a free trial on erpnext.com](https://erpnext.com/pricing). + + +### Docker Installation + +A Frappe/ERPNext instance can be setup and replicated easily using Docker[^docker]. The officially supported Docker installation can be used to setup either of both Development and Production environments. + +To setup either of the environments, you will need to clone the official docker repository: + +```sh +$ git clone https://github.com/frappe/frappe_docker.git +$ cd frappe_docker +``` + +A quick setup guide for both the envionments can be found below. For more details, check out the [Frappe/ERPNext Docker Repository](https://github.com/frappe/frappe_docker). + +#### Docker Installation for Development + +To setup a development environment for Docker, follow the [Frappe/ERPNext Docker for Development Guide](https://github.com/frappe/frappe_docker/blob/develop/development/README.md). + +#### Docker Installation for Production + +Copy the `env-example` file to `.env` + +```sh +$ cp installation/env-example installation/.env +``` + +Make a directory for handling sites: + +```sh +$ mkdir installation/sites +``` + +Optionally, you may also setup an NGINX Proxy for SSL Certificates[^nginx-ssl] with auto-renewal for your Production instance. We recommend this for instances being accessed over the internet. For this to work, the DNS needs to be configured correctly so that LetsEncrypt[^letsencrypt] can verify the domain. To setup the proxy, run the following commands: + +```sh +$ git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.git +$ cd docker-compose-letsencrypt-nginx-proxy-companion +$ cp .env.sample .env +$ ./start.sh +``` + +**Note:** The Production setup does not contain, require, or use bench. For a list of substitute commands, check out the [Frappe/ERPNext Docker Site Operations](https://github.com/frappe/frappe_docker/#site-operations). + + +### Easy Install Script + +The Easy Install script should get you going with a Frappe/ERPNext setup with minimal manual intervention and effort. Since there are a lot of configurations being automatically setup, we recommend executing this script on a fresh server. + +**Note:** This script works only on GNU/Linux based server distributions, and has been designed and tested to work on Ubuntu 16.04+, CentOS 7+, and Debian-based systems. + +#### Prerequisites + +You need to install the following packages for the script to run: + + - ##### Ubuntu and Debian-based Distributions: + + ```sh + $ apt install python3-minimal build-essential python3-setuptools + ``` + + - ##### CentOS and other RPM Distributions: + + ```sh + $ dnf groupinstall "Development Tools" + $ dnf install python3 + ``` + +#### Setup + +Download the Easy Install script and execute it: + +```sh +$ wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py +$ python3 install.py --production +``` + +The script should then prompt you for the MySQL root password and an Administrator password for the Frappe/ERPNext instance, which will then be saved under `$HOME/passwords.txt` of the user used to setup the instance. This script will then install the required stack, setup bench and a default ERPNext instance. + +When the setup is complete, you will be able to access the system at `http://`, wherein you can use the administrator password to login. + +#### Troubleshooting + +In case the setup fails, the log file is saved under `/tmp/logs/install_bench.log`. You may then: + + - Create an Issue in this repository with the log file attached. + - Search for an existing issue or post the log file on the [Frappe/ERPNext Discuss Forum](https://discuss.erpnext.com/c/bench) with the tag `installation_problem` under "Install/Update" category. + +For more information and advanced setup instructions, check out the [Easy Install Documentation](https://github.com/frappe/bench/blob/master/docs/easy_install.md). + + +### Manual Installation + +Although not recommended, some might want to manually setup a bench instance locally for development. To quickly get started on installing bench the hard way, you can follow [Installing Bench and Frappe](https://frappe.io/docs/user/en/installation). + +For more extensive distribution-dependent documentation, check out the following guides: + + - [Hitchhiker's Guide to Installing Frappe on Linux](https://github.com/frappe/frappe/wiki/The-Hitchhiker%27s-Guide-to-Installing-Frappe-on-Linux) + - [Hitchhiker's Guide to Installing Frappe on MacOS](https://github.com/frappe/frappe/wiki/The-Hitchhiker%27s-Guide-to-Installing-Frappe-on-Mac-OS-X) + + +## Basic Usage + +**Note:** Apart from `bench init`, all other bench commands are expected to be run in the respective bench directory. + + * Create a new bench: + + ```sh + $ bench init [bench-name] + ``` + + * Add a site under current bench: + + ```sh + $ bench new-site [site-name] + ``` + - **Optional**: If the database for the site does not reside on localhost or listens on a custom port, you can use the flags `--db-host` to set a custom host and/or `--db-port` to set a custom port. + + ```sh + $ bench new-site [site-name] --db-host [custom-db-host-ip] --db-port [custom-db-port] + ``` + + * Download and add applications to bench: + + ```sh + $ bench get-app [app-name] [app-link] + ``` + + * Install apps on a particular site + + ```sh + $ bench --site [site-name] install-app [app-name] + ``` + + * Start bench (only for development) + + ```sh + $ bench start + ``` + + * Show bench help: + + ```sh + $ bench help + ``` + + +For more in-depth information on commands and their usage, follow [Commands and Usage](https://github.com/frappe/bench/blob/master/docs/commands_and_usage.md). As for a consolidated list of bench commands, check out [Bench Usage](https://github.com/frappe/bench/blob/master/docs/bench_usage.md). ---- ## Custom Bench Commands -Want to utilize a bench command you've added in your custom Frappe application? [This](https://github.com/frappe/bench/blob/master/docs/bench_custom_cmd.md) guide might be of some help. +If you wish to extend the capabilities of bench with your own custom Frappe Application, you may follow [Adding Custom Bench Commands](https://github.com/frappe/bench/blob/master/docs/bench_custom_cmd.md). ---- -# Easy Install Script +## Bench Manager -- This is an opinionated setup so it is best to setup on a blank server. -- Works on Ubuntu 16.04+, CentOS 7+, Debian 8+ -- You may have to install Python 3 and other essentials by running `apt-get install python3-minimal build-essential python3-setuptools` -- This script will install the pre-requisites, install bench and setup an ERPNext site `(site1.local under frappe-bench)` -- Passwords for Frappe Administrator and MariaDB (root) will be asked and saved under `~/passwoords.txt` -- MariaDB (root) password may be `password` on a fresh server -- You can then login as **Administrator** with the Administrator password -- The log file is saved under `/tmp/logs/install_bench.log` in case you run into any issues during the install. -- If you find any problems, post them on the forum: [https://discuss.erpnext.com](https://discuss.erpnext.com/c/bench) with the `installation_problem` under "Install / Update" category. +[Bench Manager](https://github.com/frappe/bench_manager) is a GUI frontend for Bench with the same functionalties. You can install it by executing the following command: - wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py - python3 install.py --production +```sh +$ bench setup manager +``` -Follow [Easy Install Docs](https://github.com/frappe/bench/blob/master/docs/easy_install.md) for more information. + - **Note:** This will create a new site to setup Bench Manager, if you want to set it up on an existing site, run the following commands: ---- + ```sh + $ bench get-app https://github.com/frappe/bench_manager.git + $ bench --site install-app bench_manager + ``` -# Release Bench -Releases can be made for [Frappe](https://github.com/frappe/frappe) apps using bench. More information about this process can be found [here](https://github.com/frappe/bench/blob/master/docs/releasing_frappe_apps.md). - ---- - -# Bench Manager (GUI for Bench) - -[Bench Manager](https://github.com/frappe/bench_manager) is a graphical user interface to emulate the functionalities of Frappe Bench. Like the command line utility it helps you install apps, manage multiple sites, update apps and much more. Install just by executing the following command in the respective bench directory. - - bench setup manager - ---- - -# Docker - -- For official images and resources [Frappe Docker](https://github.com/frappe/frappe_docker) -- Production Installation [README](https://github.com/frappe/frappe_docker/blob/develop/README.md) -- Developer Setup [README](https://github.com/frappe/frappe_docker/blob/develop/development/README.md) - ---- - -# Guides +## Guides - [Configuring HTTPS](https://frappe.io/docs/user/en/bench/guides/configuring-https.html) - [Using Let's Encrypt to setup HTTPS](https://frappe.io/docs/user/en/bench/guides/lets-encrypt-ssl-setup.html) @@ -136,16 +216,25 @@ Releases can be made for [Frappe](https://github.com/frappe/frappe) apps using b - [Setup Multitenancy](https://frappe.io/docs/user/en/bench/guides/setup-multitenancy.html) - [Stopping Production](https://github.com/frappe/bench/wiki/Stopping-Production-and-starting-Development) ---- +For an exhaustive list of guides, check out [Bench Guides](https://frappe.io/docs/user/en/bench/guides). -# Resources -- [Background Services](https://frappe.io/docs/user/en/bench/resources/background-services.html) +## Resources + - [Bench Commands Cheat Sheet](https://frappe.io/docs/user/en/bench/resources/bench-commands-cheatsheet.html) +- [Background Services](https://frappe.io/docs/user/en/bench/resources/background-services.html) - [Bench Procfile](https://frappe.io/docs/user/en/bench/resources/bench-procfile.html) ---- +For an exhaustive list of resources, check out [Bench Resources](https://frappe.io/docs/user/en/bench/resources). -# License -bench is licensed under [GNU GPLv3](LICENSE) +## License + +This repository has been released under the [GNU GPLv3 License](LICENSE). + +###### Footnotes: + +[^nix]: [*nix and unix-like systems](https://en.wikipedia.org/wiki/Unix-like) +[^docker]: [Docker Website](https://docker.com) +[^nginx-ssl]: [Web Proxy using Docker, NGINX and Let's Encrypt](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion) +[^letsencrypt]: [LetsEncrypt Website](https://letsencrypt.org) From e1fcbf4f5c6a94d64376ee6c5d7a0bd9c90f41a6 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 23 Mar 2020 21:01:50 +0530 Subject: [PATCH 03/26] chore: rename license.md to license do not render markdown for license Signed-off-by: Chinmay D. Pai --- LICENSE.md => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE.md => LICENSE (100%) diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE From 0abf074ca44a45a596f34794cfebe0f8c198f632 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Mon, 23 Mar 2020 21:04:14 +0530 Subject: [PATCH 04/26] chore: use em dash instead of double hyphens --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63e2c322..9f55774c 100755 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Bench is a command-line utility that helps you to install, update, and manage mu ## Installation -A typical bench setup provides two types of environments -- Development and Production. +A typical bench setup provides two types of environments — Development and Production. The setup for each of these installations can be achieved in multiple ways: From 4489759ab19bcf756096b397b8e142ccb51223be Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 23 Mar 2020 21:12:43 +0530 Subject: [PATCH 05/26] chore: replace footnotes with inline links github markdown does not render footnotes for some reason... Signed-off-by: Chinmay D. Pai --- README.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9f55774c..8bce99e8 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Bench

-Bench is a command-line utility that helps you to install, update, and manage multiple sites for Frappe/ERPNext applications on *nix systems[^nix] for development and production. +Bench is a command-line utility that helps you to install, update, and manage multiple sites for Frappe/ERPNext applications on [*nix systems](https://en.wikipedia.org/wiki/Unix-like) for development and production. ## Table of Contents @@ -38,7 +38,7 @@ Otherwise, if you are looking to evaluate ERPNext, you can also download the [Vi ### Docker Installation -A Frappe/ERPNext instance can be setup and replicated easily using Docker[^docker]. The officially supported Docker installation can be used to setup either of both Development and Production environments. +A Frappe/ERPNext instance can be setup and replicated easily using [Docker](https://docker.com). The officially supported Docker installation can be used to setup either of both Development and Production environments. To setup either of the environments, you will need to clone the official docker repository: @@ -67,7 +67,7 @@ Make a directory for handling sites: $ mkdir installation/sites ``` -Optionally, you may also setup an NGINX Proxy for SSL Certificates[^nginx-ssl] with auto-renewal for your Production instance. We recommend this for instances being accessed over the internet. For this to work, the DNS needs to be configured correctly so that LetsEncrypt[^letsencrypt] can verify the domain. To setup the proxy, run the following commands: +Optionally, you may also setup an [NGINX Proxy for SSL Certificates](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion) with auto-renewal for your Production instance. We recommend this for instances being accessed over the internet. For this to work, the DNS needs to be configured correctly so that [LetsEncrypt](https://letsencrypt.org) can verify the domain. To setup the proxy, run the following commands: ```sh $ git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.git @@ -231,10 +231,3 @@ For an exhaustive list of resources, check out [Bench Resources](https://frappe. ## License This repository has been released under the [GNU GPLv3 License](LICENSE). - -###### Footnotes: - -[^nix]: [*nix and unix-like systems](https://en.wikipedia.org/wiki/Unix-like) -[^docker]: [Docker Website](https://docker.com) -[^nginx-ssl]: [Web Proxy using Docker, NGINX and Let's Encrypt](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion) -[^letsencrypt]: [LetsEncrypt Website](https://letsencrypt.org) From cab88313116c48f4531c8e6bdea30cc27832a8dd Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 24 Mar 2020 10:43:47 +0530 Subject: [PATCH 06/26] bumped to version 5.0.0 --- bench/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/__init__.py b/bench/__init__.py index e120c37b..1f0c5aac 100644 --- a/bench/__init__.py +++ b/bench/__init__.py @@ -1,6 +1,6 @@ from jinja2 import Environment, PackageLoader -__version__ = "4.1.0" +__version__ = "5.0.0" env = Environment(loader=PackageLoader('bench.config')) From c260488886d50100d4a765b875d8fb686b518f51 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 30 Mar 2020 12:27:27 +0530 Subject: [PATCH 07/26] chore: add complete docker installation to readme Signed-off-by: Chinmay D. Pai --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 8bce99e8..45f85645 100755 --- a/README.md +++ b/README.md @@ -76,6 +76,31 @@ $ cp .env.sample .env $ ./start.sh ``` +To get the Production instance running, run the following command: + +```sh +$ docker-compose \ + --project-name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/docker-compose-networks.yml \ + --project-directory installation up -d +``` + +Make sure to replace `` with whatever you wish to call it. This should get the instance running through docker. Now, to create a new site on the instance you may run: + +```sh +docker exec -it \ + -e "SITE_NAME=$SITE_NAME" \ + -e "DB_ROOT_USER=$DB_ROOT_USER" \ + -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \ + -e "ADMIN_PASSWORD=$ADMIN_PASSWORD" \ + -e "INSTALL_APPS=erpnext" \ # optional, if you want to install any other apps + _erpnext-python_1 docker-entrypoint.sh new +``` + +Once this is done, you may access the instance at `$SITE_NAME`. + **Note:** The Production setup does not contain, require, or use bench. For a list of substitute commands, check out the [Frappe/ERPNext Docker Site Operations](https://github.com/frappe/frappe_docker/#site-operations). From 62f666c481cda9b9032fa42bc8ae31ae3bcf4224 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Apr 2020 15:19:13 +0530 Subject: [PATCH 08/26] feat: check for newer versions on PyPI --- bench/cli.py | 3 ++- bench/utils.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bench/cli.py b/bench/cli.py index f5891d0a..39b60954 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -1,6 +1,6 @@ import click import os, sys, logging, json, pwd, subprocess -from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench +from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench, check_latest_version from bench.app import get_apps from bench.config.common_site_config import get_config from bench.commands import bench_command @@ -42,6 +42,7 @@ def cli(): else: try: # NOTE: this is the main bench command + check_latest_version() bench_command() except PatchError: sys.exit(1) diff --git a/bench/utils.py b/bench/utils.py index 6fb985fc..ec49201f 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -21,6 +21,7 @@ from distutils.spawn import find_executable # imports - third party imports import click import requests +from semantic_version import Version from six import iteritems from six.moves.urllib.parse import urlparse @@ -80,6 +81,18 @@ def safe_decode(string, encoding = 'utf-8'): return string +def check_latest_version(): + pypi_request = requests.get("https://pypi.org/pypi/frappe-bench/json") + + if pypi_request.status_code == 200: + pypi_version_str = pypi_request.json().get('info').get('version') + pypi_version = Version(pypi_version_str) + local_version = Version(bench.__version__) + + if pypi_version > local_version: + log("A newer version of bench is available: {0} → {1}".format(local_version, pypi_version)) + + def get_frappe(bench_path='.'): frappe = get_env_cmd('frappe', bench_path=bench_path) if not os.path.exists(frappe): From 6ea7d75193e31561d047731ed6a8bb5022319759 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Apr 2020 16:10:38 +0530 Subject: [PATCH 09/26] fix: check for updates after command execution and handle requests Exceptions --- bench/cli.py | 4 ++-- bench/utils.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bench/cli.py b/bench/cli.py index 39b60954..c1c75bc5 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -1,3 +1,4 @@ +import atexit import click import os, sys, logging, json, pwd, subprocess from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench, check_latest_version @@ -41,8 +42,7 @@ def cli(): else: try: - # NOTE: this is the main bench command - check_latest_version() + atexit.register(check_latest_version) bench_command() except PatchError: sys.exit(1) diff --git a/bench/utils.py b/bench/utils.py index ec49201f..235d5df7 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -82,7 +82,12 @@ def safe_decode(string, encoding = 'utf-8'): def check_latest_version(): - pypi_request = requests.get("https://pypi.org/pypi/frappe-bench/json") + try: + pypi_request = requests.get("https://pypi.org/pypi/frappe-bench/json") + except Exception: + # Exceptions thrown are defined in requests.exceptions + # ignore checking on all Exceptions + return if pypi_request.status_code == 200: pypi_version_str = pypi_request.json().get('info').get('version') From 9b6155dcf31344981339a5256b661cb448e92379 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Apr 2020 17:00:20 +0530 Subject: [PATCH 10/26] fix: added python source code encoding --- bench/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bench/utils.py b/bench/utils.py index 235d5df7..3fa61d9c 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # imports - standard imports import errno import glob From 8a197eed3da7b8a974880062aac634476e915fc0 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Mon, 6 Apr 2020 17:51:10 +0530 Subject: [PATCH 11/26] chore: fix bench help Co-Authored-By: gavin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45f85645..8b6129ca 100755 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ For more extensive distribution-dependent documentation, check out the following * Show bench help: ```sh - $ bench help + $ bench --help ``` From 5f03d30df4d4596d981a79c117cc58cf83a5b16c Mon Sep 17 00:00:00 2001 From: gavin Date: Wed, 8 Apr 2020 18:54:45 +0530 Subject: [PATCH 12/26] chore: changed LOG to INFO --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 6fb985fc..e783a5af 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -61,7 +61,7 @@ def is_bench_directory(directory=os.path.curdir): def log(message, level=0): levels = { - 0: color.blue + 'LOG', # normal + 0: color.blue + 'INFO', # normal 1: color.green + 'SUCCESS', # success 2: color.red + 'ERROR', # fail 3: color.yellow + 'WARN' # warn/suggest From c0afa041c83af699c87d9915ef73c5749abbdb94 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sat, 11 Apr 2020 21:17:13 +0530 Subject: [PATCH 13/26] feat: bench apps commands caching Port of https://github.com/frappe/bench/pull/888 --- bench/commands/__init__.py | 6 ++++-- bench/commands/utils.py | 12 ++++++++++++ bench/utils.py | 39 +++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 090013c2..da4eb8c8 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -41,7 +41,8 @@ bench_command.add_command(switch_to_develop) from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root, set_mariadb_host, set_default_site, download_translations, backup_site, backup_all_sites, release, renew_lets_encrypt, - disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host, find_benches, migrate_env) + disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host, find_benches, migrate_env, + generate_command_cache, clear_command_cache) bench_command.add_command(start) bench_command.add_command(restart) bench_command.add_command(set_nginx_port) @@ -63,7 +64,8 @@ bench_command.add_command(bench_src) bench_command.add_command(prepare_beta_release) bench_command.add_command(find_benches) bench_command.add_command(migrate_env) - +bench_command.add_command(generate_command_cache) +bench_command.add_command(clear_command_cache) from bench.commands.setup import setup bench_command.add_command(setup) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 822086a7..fcb11512 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -180,3 +180,15 @@ def find_benches(location): def migrate_env(python, backup=True): from bench.utils import migrate_env migrate_env(python=python, backup=backup) + + +@click.command('generate-command-cache', help="Caches Frappe Framework commands") +def generate_command_cache(bench_path='.'): + from bench.utils import generate_command_cache + return generate_command_cache(bench_path=bench_path) + + +@click.command('clear-command-cache', help="Clears Frappe Framework cached commands") +def clear_command_cache(bench_path='.'): + from bench.utils import clear_command_cache + return clear_command_cache(bench_path=bench_path) diff --git a/bench/utils.py b/bench/utils.py index 897acb64..33a9a6cb 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -39,7 +39,7 @@ class CommandFailedError(Exception): pass logger = logging.getLogger(__name__) - +bench_cache_file = '.bench.cmd' folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids') sudoers_file = '/etc/sudoers.d/frappe' @@ -187,6 +187,8 @@ def update(pull=False, patch=False, build=False, requirements=False, backup=True patches.run(bench_path=bench_path) conf = get_config(bench_path) + clear_command_cache(bench_path='.') + if conf.get('release_bench'): print('Release bench detected, cannot update!') sys.exit(1) @@ -1137,3 +1139,38 @@ def find_parent_bench(path): # NOTE: the os.path.split assumes that given path is absolute parent_dir = os.path.split(path)[0] return find_parent_bench(parent_dir) + + +def generate_command_cache(bench_path='.'): + """ + Caches all available commands (even custom apps) via Frappe + Default caching behaviour: generated the first time any command (for a specific bench directory) + """ + + python = get_env_cmd('python', bench_path=bench_path) + sites_path = os.path.join(bench_path, 'sites') + + if os.path.exists(bench_cache_file): + os.remove(bench_cache_file) + + try: + output = get_cmd_output("{0} -m frappe.utils.bench_helper get-frappe-commands".format(python), cwd=sites_path) + with open(bench_cache_file, 'w') as f: + json.dump(eval(output), f) + return json.loads(output) + + except subprocess.CalledProcessError as e: + if hasattr(e, "stderr"): + print(e.stderr.decode('utf-8')) + + +def clear_command_cache(bench_path='.'): + """ + Clears commands cached + Default invalidation behaviour: destroyed on each run of `bench update` + """ + + if os.path.exists(bench_cache_file): + os.remove(bench_cache_file) + else: + print("Bench command cache doesn't exist in this folder!") \ No newline at end of file From e39ae1e0b5699e41dd552f48707299ccda4e86e3 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sat, 11 Apr 2020 21:20:24 +0530 Subject: [PATCH 14/26] fix: better warning and cache handling --- bench/cli.py | 89 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/bench/cli.py b/bench/cli.py index c1c75bc5..723c596e 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -1,16 +1,27 @@ +# imports - standard imports import atexit +import json +import logging +import os +import pwd +import subprocess +import sys + +# imports - third party imports import click -import os, sys, logging, json, pwd, subprocess -from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench, check_latest_version + +# imports - module imports from bench.app import get_apps -from bench.config.common_site_config import get_config from bench.commands import bench_command +from bench.config.common_site_config import get_config +from bench.utils import PatchError, bench_cache_file, check_latest_version, drop_privileges, find_parent_bench, generate_command_cache, get_cmd_output, get_env_cmd, get_frappe, is_bench_directory, is_dist_editable, is_root, log logger = logging.getLogger('bench') from_command_line = False change_uid_msg = "You should not run this command as root" + def cli(): global from_command_line from_command_line = True @@ -20,46 +31,50 @@ def cli(): change_dir() change_uid() - if is_dist_editable("bench"): + if is_dist_editable("bench") and len(sys.argv) > 1 and sys.argv[1] != "src": log("bench is installed in editable mode!\n\nThis is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`\n", level=3) + if not is_bench_directory() and not cmd_requires_root() and len(sys.argv) > 1 and sys.argv[1] not in ("init", "find", "src"): + log("Command not being executed in bench directory", level=3) + if len(sys.argv) > 2 and sys.argv[1] == "frappe": return old_frappe_cli() - elif len(sys.argv) > 1 and sys.argv[1] in get_frappe_commands(): - return frappe_cmd() + elif len(sys.argv) > 1: + if sys.argv[1] in get_frappe_commands() + ["--site", "--verbose", "--force", "--profile"]: + return frappe_cmd() - elif len(sys.argv) > 1 and sys.argv[1] in ("--site", "--verbose", "--force", "--profile"): - return frappe_cmd() + elif sys.argv[1] == "--help": + print(click.Context(bench_command).get_help()) + print(get_frappe_help()) + return - elif len(sys.argv) > 1 and sys.argv[1]=="--help": - print(click.Context(bench_command).get_help()) - print(get_frappe_help()) - return + elif sys.argv[1] in get_apps(): + return app_cmd() - elif len(sys.argv) > 1 and sys.argv[1] in get_apps(): - return app_cmd() + if not (len(sys.argv) > 1 and sys.argv[1] == "src"): + atexit.register(check_latest_version) + + try: + bench_command() + except PatchError: + sys.exit(1) - else: - try: - atexit.register(check_latest_version) - bench_command() - except PatchError: - sys.exit(1) def check_uid(): if cmd_requires_root() and not is_root(): log('superuser privileges required for this command', level=3) sys.exit(1) + def cmd_requires_root(): if len(sys.argv) > 2 and sys.argv[2] in ('production', 'sudoers', 'supervisor', 'lets-encrypt', 'fonts', - 'print', 'firewall', 'ssh-port', 'role', 'fail2ban', 'wildcard-ssl'): + 'print', 'firewall', 'ssh-port', 'role', 'fail2ban', 'wildcard-ssl', 'install'): return True - if len(sys.argv) >= 2 and sys.argv[1] in ('patch', 'renew-lets-encrypt', 'disable-production', - 'install'): + if len(sys.argv) >= 2 and sys.argv[1] in ('patch', 'renew-lets-encrypt', 'disable-production'): return True + def change_dir(): if os.path.exists('config.json') or "init" in sys.argv: return @@ -70,6 +85,7 @@ def change_dir(): if os.path.exists(dir_path): os.chdir(dir_path) + def change_uid(): if is_root() and not cmd_requires_root(): frappe_user = get_config(".").get('frappe_user') @@ -80,35 +96,37 @@ def change_uid(): log(change_uid_msg, level=3) sys.exit(1) + def old_frappe_cli(bench_path='.'): f = get_frappe(bench_path=bench_path) os.chdir(os.path.join(bench_path, 'sites')) os.execv(f, [f] + sys.argv[2:]) + def app_cmd(bench_path='.'): f = get_env_cmd('python', bench_path=bench_path) os.chdir(os.path.join(bench_path, 'sites')) os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper'] + sys.argv[1:]) + def frappe_cmd(bench_path='.'): f = get_env_cmd('python', bench_path=bench_path) os.chdir(os.path.join(bench_path, 'sites')) os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper', 'frappe'] + sys.argv[1:]) -def get_frappe_commands(bench_path='.'): - python = get_env_cmd('python', bench_path=bench_path) - sites_path = os.path.join(bench_path, 'sites') - if not os.path.exists(sites_path): - log("Command not being executed in bench directory", level=3) - return [] - try: - output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path) - return json.loads(output) - except subprocess.CalledProcessError as e: - if hasattr(e, "stderr"): - print(e.stderr.decode('utf-8')) + +def get_frappe_commands(): + if not is_bench_directory(): return [] + if os.path.exists(bench_cache_file): + command_dump = open(bench_cache_file, 'r').read() or '[]' + return json.loads(command_dump) + + else: + return generate_command_cache() + + def get_frappe_help(bench_path='.'): python = get_env_cmd('python', bench_path=bench_path) sites_path = os.path.join(bench_path, 'sites') @@ -118,6 +136,7 @@ def get_frappe_help(bench_path='.'): except: return "" + def change_working_directory(): """Allows bench commands to be run from anywhere inside a bench directory""" cur_dir = os.path.abspath(".") From 7e7c3969a764faffe814e72a0940103c4bb69d67 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sat, 11 Apr 2020 21:21:07 +0530 Subject: [PATCH 15/26] fix: set translations download limit based on cpu cores --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 33a9a6cb..332bda2a 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -844,7 +844,7 @@ def update_translations_p(args): def download_translations_p(): - pool = multiprocessing.Pool(4) + pool = multiprocessing.Pool(multiprocessing.cpu_count()) langs = get_langs() apps = ('frappe', 'erpnext') From 2d436126fd4c1e187bbb9b2685f2b7575dfe19d4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sat, 11 Apr 2020 21:36:34 +0530 Subject: [PATCH 16/26] fix: help for bench install without sudo --- bench/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/cli.py b/bench/cli.py index 723c596e..a3235382 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -69,10 +69,12 @@ def check_uid(): def cmd_requires_root(): if len(sys.argv) > 2 and sys.argv[2] in ('production', 'sudoers', 'supervisor', 'lets-encrypt', 'fonts', - 'print', 'firewall', 'ssh-port', 'role', 'fail2ban', 'wildcard-ssl', 'install'): + 'print', 'firewall', 'ssh-port', 'role', 'fail2ban', 'wildcard-ssl'): return True if len(sys.argv) >= 2 and sys.argv[1] in ('patch', 'renew-lets-encrypt', 'disable-production'): return True + if len(sys.argv) > 2 and sys.argv[1] in ('install'): + return True def change_dir(): From 279073f1c0e3d1b4ee30ad81572b2b5c86ffce01 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 13 Apr 2020 13:02:51 +0530 Subject: [PATCH 17/26] style: fixed docstring and unused imports --- bench/cli.py | 1 - bench/utils.py | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bench/cli.py b/bench/cli.py index a3235382..628f2413 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -4,7 +4,6 @@ import json import logging import os import pwd -import subprocess import sys # imports - third party imports diff --git a/bench/utils.py b/bench/utils.py index 332bda2a..38786545 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -1142,8 +1142,7 @@ def find_parent_bench(path): def generate_command_cache(bench_path='.'): - """ - Caches all available commands (even custom apps) via Frappe + """Caches all available commands (even custom apps) via Frappe Default caching behaviour: generated the first time any command (for a specific bench directory) """ @@ -1165,8 +1164,7 @@ def generate_command_cache(bench_path='.'): def clear_command_cache(bench_path='.'): - """ - Clears commands cached + """Clears commands cached Default invalidation behaviour: destroyed on each run of `bench update` """ From 6dd01184462054c47de36884cf7e4ec735d50b44 Mon Sep 17 00:00:00 2001 From: Abhishek Kedar <44434910+AKedar21@users.noreply.github.com> Date: Tue, 14 Apr 2020 14:02:56 +0530 Subject: [PATCH 18/26] fix: typo cash to crash Fixed typo in "Open source..." sentence --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 897acb64..e4a6c08b 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -240,7 +240,7 @@ def update(pull=False, patch=False, build=False, requirements=False, backup=True conf.update({ "maintenance_mode": 0, "pause_scheduler": 0 }) update_config(conf, bench_path=bench_path) - print("_" * 80 + "\nBench: Deployment tool for Frappe and Frappe Applications (https://frappe.io/bench).\nOpen source depends on your contributions, so please contribute bug reports, patches, fixes or cash and be a part of the community") + print("_" * 80 + "\nBench: Deployment tool for Frappe and Frappe Applications (https://frappe.io/bench).\nOpen source depends on your contributions, so please contribute bug reports, patches, fixes or crash and be a part of the community") def copy_patches_txt(bench_path): From e1f1b0972dda9dc1ed8ca490bdf3966820d5cb92 Mon Sep 17 00:00:00 2001 From: gavin Date: Tue, 14 Apr 2020 15:21:30 +0530 Subject: [PATCH 19/26] docs: mellow-er contribution message post update --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index e4a6c08b..35c985ad 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -240,7 +240,7 @@ def update(pull=False, patch=False, build=False, requirements=False, backup=True conf.update({ "maintenance_mode": 0, "pause_scheduler": 0 }) update_config(conf, bench_path=bench_path) - print("_" * 80 + "\nBench: Deployment tool for Frappe and Frappe Applications (https://frappe.io/bench).\nOpen source depends on your contributions, so please contribute bug reports, patches, fixes or crash and be a part of the community") + print("_" * 80 + "\nBench: Deployment tool for Frappe and Frappe Applications (https://frappe.io/bench).\nOpen source depends on your contributions, so do give back by submitting bug reports, patches and fixes and be a part of the community :)") def copy_patches_txt(bench_path): From 90f951c6ec3465b780f24f08cd87c35631cfd0dd Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 15 Apr 2020 11:28:19 +0530 Subject: [PATCH 20/26] fix(backups): setup backups for bench sites Using python-crontab library instead of manual processing --- bench/utils.py | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 35c985ad..55ca544b 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -23,6 +23,7 @@ from distutils.spawn import find_executable # imports - third party imports import click +from crontab import CronTab import requests from semantic_version import Version from six import iteritems @@ -361,42 +362,27 @@ def get_sites(bench_path='.'): return sites -def get_bench_dir(bench_path='.'): - return os.path.abspath(bench_path) - - def setup_backups(bench_path='.'): + from bench.config.common_site_config import get_config logger.info('setting up backups') - bench_dir = get_bench_dir(bench_path=bench_path) + + bench_dir = os.path.abspath(bench_path) + user = get_config('.').get('frappe_user') + logfile = os.path.join(bench_dir, 'logs', 'backup.log') bench.set_frappe_version(bench_path=bench_path) + system_crontab = CronTab(user=user) if bench.FRAPPE_VERSION == 4: backup_command = "cd {sites_dir} && {frappe} --backup all".format(frappe=get_frappe(bench_path=bench_path),) else: backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0]) - add_to_crontab('0 */6 * * * {backup_command} >> {logfile} 2>&1'.format(backup_command=backup_command, - logfile=os.path.join(get_bench_dir(bench_path=bench_path), 'logs', 'backup.log'))) + job_command = "{backup_command} >> {logfile} 2>&1".format(backup_command=backup_command, logfile=logfile) - -def add_to_crontab(line): - current_crontab = read_crontab() - line = str.encode(line) - if not line in current_crontab: - cmd = ["crontab"] - if platform.system() == 'FreeBSD': - cmd = ["crontab", "-"] - s = subprocess.Popen(cmd, stdin=subprocess.PIPE) - s.stdin.write(current_crontab) - s.stdin.write(line + b'\n') - s.stdin.close() - - -def read_crontab(): - s = subprocess.Popen(["crontab", "-l"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - out = s.stdout.read() - s.stdout.close() - return out + if job_command not in str(system_crontab): + job = system_crontab.new(command=job_command, comment="bench auto backups set for every 6 hours") + job.hour.every(6) + system_crontab.write() def setup_sudoers(user): @@ -553,7 +539,6 @@ def restart_supervisor_processes(bench_path='.', web_workers=False): def restart_systemd_processes(bench_path='.', web_workers=False): - from .config.common_site_config import get_config bench_name = get_bench_name(bench_path) exec_cmd('sudo systemctl stop -- $(systemctl show -p Requires {bench_name}.target | cut -d= -f2)'.format(bench_name=bench_name)) exec_cmd('sudo systemctl start -- $(systemctl show -p Requires {bench_name}.target | cut -d= -f2)'.format(bench_name=bench_name)) From f28c3765d843d8118ab22e208857f98551e7ed3b Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 16 Apr 2020 14:17:29 +0530 Subject: [PATCH 21/26] fix(backup): make auto backup logs verbose --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 55ca544b..49e277c9 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -375,7 +375,7 @@ def setup_backups(bench_path='.'): if bench.FRAPPE_VERSION == 4: backup_command = "cd {sites_dir} && {frappe} --backup all".format(frappe=get_frappe(bench_path=bench_path),) else: - backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0]) + backup_command = "cd {bench_dir} && {bench} --verbose --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0]) job_command = "{backup_command} >> {logfile} 2>&1".format(backup_command=backup_command, logfile=logfile) From 6881c9338829c0a00ff1384f1bddfc77ea568cfd Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 17 Apr 2020 11:26:44 +0530 Subject: [PATCH 22/26] fix: bench path used for config --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 49e277c9..773beb01 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -367,7 +367,7 @@ def setup_backups(bench_path='.'): logger.info('setting up backups') bench_dir = os.path.abspath(bench_path) - user = get_config('.').get('frappe_user') + user = get_config(bench_path=bench_dir).get('frappe_user') logfile = os.path.join(bench_dir, 'logs', 'backup.log') bench.set_frappe_version(bench_path=bench_path) system_crontab = CronTab(user=user) From a7c52b4059e5f4d07b9dfce4ed65c52a8ed10c5d Mon Sep 17 00:00:00 2001 From: lasalesi Date: Fri, 17 Apr 2020 15:01:07 +0200 Subject: [PATCH 23/26] fix(playbooks): wkhtmltopdf checksum string for debian 9 (#969) * Update main.yml Correcting checksum string for Debian 9 * fix(playbook): yaml syntax for checksum in wkhtmltopdf Co-authored-by: gavin --- playbooks/roles/wkhtmltopdf/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/roles/wkhtmltopdf/tasks/main.yml b/playbooks/roles/wkhtmltopdf/tasks/main.yml index 16a6e99d..1656ffd2 100644 --- a/playbooks/roles/wkhtmltopdf/tasks/main.yml +++ b/playbooks/roles/wkhtmltopdf/tasks/main.yml @@ -72,7 +72,7 @@ get_url: url: https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_{{ "amd64" if ansible_architecture == "x86_64" else "i386"}}.deb dest: /tmp/wkhtmltox.deb - checksum: '{{ 1140b0ab02aa6e17346af2f14ed0de807376de475ba90e1db3975f112fbd20bb if ansible_architecture == "x86_64" else 5b2d15e738ac479e7a8ca6fd765f406c3684a48091813520f87878278d6dd22a }}' + checksum: "sha256:{{ '1140b0ab02aa6e17346af2f14ed0de807376de475ba90e1db3975f112fbd20bb' if ansible_architecture == 'x86_64' else '5b2d15e738ac479e7a8ca6fd765f406c3684a48091813520f87878278d6dd22a' }}" when: ansible_distribution == 'Debian' and ansible_distribution_major_version == '9' - name: download wkthmltox Debian 10 @@ -92,4 +92,4 @@ deb: /tmp/wkhtmltox.deb state: present when: ansible_os_family == 'Debian' -... \ No newline at end of file +... From cc45cbf8c2f71bbac67b49e93f6542e6b4c81cdf Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Sun, 19 Apr 2020 13:53:38 +0530 Subject: [PATCH 24/26] chore: set apps to None by default Signed-off-by: Chinmay D. Pai --- bench/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 598dd47e..84ce6e71 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -177,7 +177,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, copy_patches_txt(path) -def update(pull=False, apps=apps, patch=False, build=False, requirements=False, backup=True, force=False, reset=False, +def update(pull=False, apps=None, patch=False, build=False, requirements=False, backup=True, force=False, reset=False, restart_supervisor=False, restart_systemd=False): """command: bench update""" from bench import patches @@ -1162,4 +1162,4 @@ def clear_command_cache(bench_path='.'): if os.path.exists(bench_cache_file): os.remove(bench_cache_file) else: - print("Bench command cache doesn't exist in this folder!") \ No newline at end of file + print("Bench command cache doesn't exist in this folder!") From 03e512fdab3c6b8240a4f290a554f72c686585f5 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 4 May 2020 17:43:32 +0530 Subject: [PATCH 25/26] fix: get-app sets up node requirements --- bench/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/app.py b/bench/app.py index 48f8427e..d57fb9d3 100755 --- a/bench/app.py +++ b/bench/app.py @@ -177,8 +177,8 @@ def install_app(app, bench_path=".", verbose=False, no_cache=False, postprocess= app_path = os.path.join(bench_path, "apps", app) cache_flag = "--no-cache-dir" if no_cache else "" - exec_cmd("{pip} install {quiet} -U -e {app} {no_cache}".format(pip=pip_path, - quiet=quiet_flag, app=app_path, no_cache=cache_flag)) + exec_cmd("{pip} install {quiet} -U -e {app} {no_cache}".format(pip=pip_path, quiet=quiet_flag, app=app_path, no_cache=cache_flag)) + exec_cmd("yarn install", cwd=app_path) add_to_appstxt(app, bench_path=bench_path) if postprocess: From b3842d9b305da87d689bea379049beee3dd1cbbb Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 4 May 2020 17:44:46 +0530 Subject: [PATCH 26/26] fix: handle app not found under GH frappe erpnext orgs --- bench/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bench/app.py b/bench/app.py index d57fb9d3..7115ee32 100755 --- a/bench/app.py +++ b/bench/app.py @@ -111,6 +111,9 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal if git_url == data['name']: git_url = 'https://github.com/{org}/{app}'.format(org=org, app=git_url) break + else: + bench.utils.log("App {app} not found".format(app=git_url), level=2) + sys.exit(1) # Gets repo name from URL repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0] @@ -407,7 +410,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad if version_upgrade[0] and upgrade: update_requirements() update_node_packages() - reload_module(utils) + reload_module(bench.utils) backup_all_sites() patch_sites() build_assets()