Skip to content

Commit

Permalink
Merge branch 'develop' into bye_redis_socketio
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Aug 7, 2023
2 parents a172b14 + 77ebdbe commit 2a41815
Show file tree
Hide file tree
Showing 26 changed files with 639 additions and 702 deletions.
16 changes: 0 additions & 16 deletions .deepsource.toml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
push:
branches: [ develop ]

concurrency:
group: ci-develop-${{ github.event_name }}-${{ github.event.number }}
cancel-in-progress: true

permissions:
contents: read

Expand All @@ -15,6 +19,7 @@ jobs:
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10' ]

Expand Down Expand Up @@ -89,6 +94,7 @@ jobs:
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
python-version: [ '3.7', '3.10' ]

Expand All @@ -108,9 +114,17 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/setup-node@v3
if: ${{ matrix.python-version == '3.10' }}
with:
node-version: 18

- uses: actions/setup-node@v3
if: ${{ matrix.python-version == '3.7' }}
with:
node-version: 14

- run: |
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb;
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/easy-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Easy Install Test"

on:
pull_request:
workflow_dispatch:
push:
branches: [develop]

concurrency:
group: easy-install-develop-${{ github.event_name }}-${{ github.event.number }}
cancel-in-progress: true

permissions:
contents: read

jobs:
easy-install-setup:
runs-on: ubuntu-latest
timeout-minutes: 60

name: Easy Install Test
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: Perform production easy install
run: |
python3 ${GITHUB_WORKSPACE}/easy-install.py -p -n actions_test --email test@frappe.io
docker compose -p actions_test exec backend bench version --format json
docker compose -p actions_test exec backend bench --site site1.localhost list-apps --format json
result=$(curl -H "Host: site1.localhost" -sk https://127.0.0.1/api/method/ping | jq -r ."message")
if [[ "$result" == "pong" ]]; then echo "New instance works fine"; else exit 1; fi
docker compose -p actions_test down
docker volume prune -f
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 18
- uses: actions/setup-python@v4
with:
python-version: '3.x'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ repos:
- id: black
additional_dependencies: ['click==8.0.4']

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear',]
Expand Down
69 changes: 59 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ Bench is a command-line utility that helps you to install, update, and manage mu

## Table of Contents

- [Installation](#installation)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Containerized Installation](#containerized-installation)
- [Easy Install Script](#easy-install-script)
- [Setup](#setup)
- [Arguments](#arguments)
- [Troubleshooting](#troubleshooting)
- [Manual Installation](#manual-installation)
- [Usage](#basic-usage)
- [Custom Bench commands](#custom-bench-commands)
- [Bench Manager](#bench-manager)
- [Guides](#guides)
- [Resources](#resources)
- [Development](#development)
- [Releases](#releases)
- [License](#license)
- [Basic Usage](#basic-usage)
- [Custom Bench Commands](#custom-bench-commands)
- [Guides](#guides)
- [Resources](#resources)
- [Development](#development)
- [Releases](#releases)
- [License](#license)


## Installation
Expand All @@ -53,7 +57,7 @@ The setup for each of these installations can be achieved in multiple ways:
- [Containerized Installation](#containerized-installation)
- [Manual Installation](#manual-installation)

We recommend using either the Docker Installation to setup a Production Environment. For Development, you may choose either of the two methods to setup an instance.
We recommend using Docker Installation to setup a Production Environment. For Development, you may choose either of the two methods to setup an instance.

Otherwise, if you are looking to evaluate Frappe apps without hassle of hosting, you can try them [on frappecloud.com](https://frappecloud.com/).

Expand All @@ -71,6 +75,51 @@ $ cd frappe_docker

A quick setup guide for both the environments can be found below. For more details, check out the [Frappe/ERPNext Docker Repository](https://github.com/frappe/frappe_docker).

### Easy Install Script

The Easy Install script should get you going with a Frappe/ERPNext setup with minimal manual intervention and effort.

This script uses Docker with the [Frappe/ERPNext Docker Repository](https://github.com/frappe/frappe_docker) and can be used for both Development setup and Production setup.

#### Setup

Download the Easy Install script and execute it:

```sh
$ wget https://raw.githubusercontent.com/frappe/bench/develop/easy-install.py
$ python3 easy-install.py --prod --email your@email.tld
```

This script will install docker on your system and will fetch the required containers, setup bench and a default ERPNext instance.

The script will generate 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.
It will also generate a new compose file under `$HOME/<project-name>-compose.yml`.

When the setup is complete, you will be able to access the system at `http://<your-server-ip>`, wherein you can use the Administrator password to login.

#### Arguments

Here are the arguments for the easy-install script

```txt
usage: easy-install.py [-h] [-p] [-d] [-s SITENAME] [-n PROJECT] [--email EMAIL]
Install Frappe with Docker
options:
-h, --help show this help message and exit
-p, --prod Setup Production System
-d, --dev Setup Development System
-s SITENAME, --sitename SITENAME The Site Name for your production site
-n PROJECT, --project PROJECT Project Name
--email EMAIL Add email for the SSL.
```

#### Troubleshooting

In case the setup fails, the log file is saved under `$HOME/easy-install.log`. You may then

- Create an Issue in this repository with the log file attached.

### Manual Installation

Expand Down
22 changes: 12 additions & 10 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def get(self):

@step(title="Archiving App {repo}", success="App {repo} Archived")
def remove(self, no_backup: bool = False):
active_app_path = os.path.join("apps", self.name)
active_app_path = os.path.join("apps", self.app_name)

if no_backup:
if not os.path.islink(active_app_path):
Expand All @@ -209,7 +209,7 @@ def remove(self, no_backup: bool = False):
else:
archived_path = os.path.join("archived", "apps")
archived_name = get_available_folder_name(
f"{self.repo}-{date.today()}", archived_path
f"{self.app_name}-{date.today()}", archived_path
)
archived_app_path = os.path.join(archived_path, archived_name)

Expand All @@ -233,7 +233,7 @@ def install(

verbose = bench.cli.verbose or verbose
app_name = get_app_name(self.bench.name, self.app_name)
if not resolved and self.repo != "frappe" and not ignore_resolution:
if not resolved and self.app_name != "frappe" and not ignore_resolution:
click.secho(
f"Ignoring dependencies of {self.name}. To install dependencies use --resolve-deps",
fg="yellow",
Expand Down Expand Up @@ -262,7 +262,7 @@ def _get_dependencies(self):
from bench.utils.app import get_required_deps, required_apps_from_hooks

if self.on_disk:
required_deps = os.path.join(self.mount_path, self.repo, "hooks.py")
required_deps = os.path.join(self.mount_path, self.app_name, "hooks.py")
try:
return required_apps_from_hooks(required_deps, local=True)
except IndexError:
Expand Down Expand Up @@ -290,16 +290,16 @@ def make_resolution_plan(app: App, bench: "Bench"):
decide what apps and versions to install and in what order
"""
resolution = OrderedDict()
resolution[app.repo] = app
resolution[app.app_name] = app

for app_name in app._get_dependencies():
dep_app = App(app_name, bench=bench)
is_valid_frappe_branch(dep_app.url, dep_app.branch)
dep_app.required_by = app.name
if dep_app.repo in resolution:
click.secho(f"{dep_app.repo} is already resolved skipping", fg="yellow")
if dep_app.app_name in resolution:
click.secho(f"{dep_app.app_name} is already resolved skipping", fg="yellow")
continue
resolution[dep_app.repo] = dep_app
resolution[dep_app.app_name] = dep_app
resolution.update(make_resolution_plan(dep_app, bench))
app.local_resolution = [repo_name for repo_name, _ in reversed(resolution.items())]
return resolution
Expand All @@ -315,7 +315,7 @@ def get_excluded_apps(bench_path="."):

def add_to_excluded_apps_txt(app, bench_path="."):
if app == "frappe":
raise ValueError("Frappe app cannot be excludeed from update")
raise ValueError("Frappe app cannot be excluded from update")
if app not in os.listdir("apps"):
raise ValueError(f"The app {app} does not exist")
apps = get_excluded_apps(bench_path=bench_path)
Expand Down Expand Up @@ -586,7 +586,9 @@ def install_app(
build_assets(bench_path=bench_path, app=app)

if restart_bench:
bench.reload()
# Avoiding exceptions here as production might not be set-up
# OR we might just be generating docker images.
bench.reload(_raise=False)


def pull_apps(apps=None, bench_path=".", reset=False):
Expand Down
33 changes: 24 additions & 9 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@


class Base:
def run(self, cmd, cwd=None):
return exec_cmd(cmd, cwd=cwd or self.cwd)
def run(self, cmd, cwd=None, _raise=True):
return exec_cmd(cmd, cwd=cwd or self.cwd, _raise=_raise)


class Validator:
Expand Down Expand Up @@ -131,26 +131,27 @@ def uninstall(self, app, no_backup=False, force=False):
except InvalidRemoteException:
if not force:
raise

self.apps.sync()
# self.build() - removed because it seems unnecessary
self.reload()
self.reload(_raise=False)

@step(title="Building Bench Assets", success="Bench Assets Built")
def build(self):
# build assets & stuff
run_frappe_cmd("build", bench_path=self.name)

@step(title="Reloading Bench Processes", success="Bench Processes Reloaded")
def reload(self, web=False, supervisor=True, systemd=True):
def reload(self, web=False, supervisor=True, systemd=True, _raise=True):
"""If web is True, only web workers are restarted"""
conf = self.conf

if conf.get("developer_mode"):
restart_process_manager(bench_path=self.name, web_workers=web)
if supervisor and conf.get("restart_supervisor_on_update"):
restart_supervisor_processes(bench_path=self.name, web_workers=web)
if supervisor or conf.get("restart_supervisor_on_update"):
restart_supervisor_processes(bench_path=self.name, web_workers=web, _raise=_raise)
if systemd and conf.get("restart_systemd_on_update"):
restart_systemd_processes(bench_path=self.name, web_workers=web)
restart_systemd_processes(bench_path=self.name, web_workers=web, _raise=_raise)

def get_installed_apps(self) -> List:
"""Returns list of installed apps on bench, not in excluded_apps.txt"""
Expand Down Expand Up @@ -309,13 +310,13 @@ def insert(self, key, value):
def add(self, app: "App"):
app.get()
app.install()
super().append(app.repo)
super().append(app.app_name)
self.apps.sort()

def remove(self, app: "App", no_backup: bool = False):
app.uninstall()
app.remove(no_backup=no_backup)
super().remove(app.repo)
super().remove(app.app_name)

def append(self, app: "App"):
return self.add(app)
Expand Down Expand Up @@ -361,6 +362,7 @@ def env(self, python="python3"):
self.run(f"{venv} env", cwd=self.bench.name)

self.pip()
self.wheel()

if os.path.exists(frappe):
self.run(
Expand Down Expand Up @@ -398,6 +400,19 @@ def pip(self, verbose=False):
f"{self.bench.python} -m pip install {quiet_flag} --upgrade pip", cwd=self.bench.name
)

@step(title="Installing wheel", success="Installed wheel")
def wheel(self, verbose=False):
"""Wheel is required for building old setup.py packages.
ref: https://github.com/pypa/pip/issues/8559"""
import bench.cli

verbose = bench.cli.verbose or verbose
quiet_flag = "" if verbose else "--quiet"

return self.run(
f"{self.bench.python} -m pip install {quiet_flag} wheel", cwd=self.bench.name
)

def logging(self):
from bench.utils import setup_logging

Expand Down
Loading

0 comments on commit 2a41815

Please sign in to comment.