Skip to content

Commit

Permalink
Merge branch 'staging' into v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Oct 21, 2023
2 parents acbceb8 + ce1ec43 commit 0122ef1
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
7 changes: 4 additions & 3 deletions bench/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def install_prerequisites():
@click.command(
"mariadb", help="Install and setup MariaDB of specified version and root password"
)
@click.option("--mysql_root_password", "--mysql-root-password", default="")
@click.option("--mysql_root_password", "--mysql-root-password",
"--mariadb_root_password", "--mariadb-root-password", default="")
@click.option("--version", default="10.3")
def install_maridb(mysql_root_password, version):
def install_mariadb(mysql_root_password, version):
if mysql_root_password:
extra_vars.update(
{
Expand Down Expand Up @@ -111,7 +112,7 @@ def install_failtoban(**kwargs):


install.add_command(install_prerequisites)
install.add_command(install_maridb)
install.add_command(install_mariadb)
install.add_command(install_wkhtmltopdf)
install.add_command(install_nodejs)
install.add_command(install_psutil)
Expand Down
2 changes: 1 addition & 1 deletion bench/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def sync_domains(domain=None, site=None):
@click.command("role", help="Install dependencies via ansible roles")
@click.argument("role")
@click.option("--admin_emails", default="")
@click.option("--mysql_root_password")
@click.option("--mysql_root_password", "--mariadb_root_password")
@click.option("--container", is_flag=True, default=False)
def setup_roles(role, **kwargs):
extra_vars = {"production": True}
Expand Down
2 changes: 1 addition & 1 deletion bench/config/common_site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def update_config_for_frappe(config, bench_path):

for key in ("redis_cache", "redis_queue", "redis_socketio"):
if key not in config:
config[key] = f"redis://localhost:{ports[key]}"
config[key] = f"redis://127.0.0.1:{ports[key]}"

for key in ("webserver_port", "socketio_port", "file_watcher_port"):
if key not in config:
Expand Down
2 changes: 1 addition & 1 deletion bench/config/templates/bench_manager_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ server {
}

location @webserver {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frappe-Site-Name {{ bench_manager_site_name }};
proxy_set_header Host {{ bench_manager_site_name }};
Expand Down
4 changes: 2 additions & 2 deletions bench/playbooks/roles/mariadb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Debain 9

## Post install

Run `mysql_secure_installation`
Run `mariadb-secure-installation`

## Requirements

Expand All @@ -39,7 +39,7 @@ Configuration filename:
mysql_conf_file: settings.cnf
```

### Experimental unattended mysql_secure_installation
### Experimental unattended mariadb-secure-installation

```
ansible-playbook release.yml --extra-vars "mysql_secure_installation=true mysql_root_password=your_very_secret_password"
Expand Down
4 changes: 2 additions & 2 deletions bench/playbooks/roles/mariadb/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
- name: restart mysql
service: name=mysql state=restarted
- name: restart mariadb
service: name=mariadb state=restarted
6 changes: 3 additions & 3 deletions bench/playbooks/roles/mariadb/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
group: root
mode: 0644
when: mysql_conf_tpl != 'change_me' and ansible_distribution != 'Debian'
notify: restart mysql
notify: restart mariadb

- include_tasks: debian.yml
when: ansible_distribution == 'Debian'
Expand All @@ -29,7 +29,7 @@
group: root
mode: 0644
when: mysql_conf_tpl != 'change_me' and ansible_distribution == 'Debian'
notify: restart mysql
notify: restart mariadb

- name: Add additional conf for MariaDB 10.2 in mariadb.conf.d
blockinfile:
Expand Down Expand Up @@ -59,7 +59,7 @@

- name: Start and enable service
service:
name: mysql
name: mariadb
state: started
enabled: yes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@
- ::1

- name: Reload privilege tables
command: 'mysql -ne "{{ item }}"'
command: 'mariadb -ne "{{ item }}"'
with_items:
- FLUSH PRIVILEGES
changed_when: False
when: run_travis is not defined

- name: Remove anonymous users
command: 'mysql -ne "{{ item }}"'
command: 'mariadb -ne "{{ item }}"'
with_items:
- DELETE FROM mysql.user WHERE User=''
changed_when: False
when: run_travis is not defined

- name: Disallow root login remotely
command: 'mysql -ne "{{ item }}"'
command: 'mariadb -ne "{{ item }}"'
with_items:
- DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
changed_when: False
when: run_travis is not defined

- name: Remove test database and access to it
command: 'mysql -ne "{{ item }}"'
command: 'mariadb -ne "{{ item }}"'
with_items:
- DROP DATABASE IF EXISTS test
- DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
changed_when: False
when: run_travis is not defined

- name: Reload privilege tables
command: 'mysql -ne "{{ item }}"'
command: 'mariadb -ne "{{ item }}"'
with_items:
- FLUSH PRIVILEGES
changed_when: False
Expand Down
12 changes: 6 additions & 6 deletions bench/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def test_multiple_benches(self):
"webserver_port": 8000,
"socketio_port": 9000,
"file_watcher_port": 6787,
"redis_queue": "redis://localhost:11000",
"redis_socketio": "redis://localhost:13000",
"redis_cache": "redis://localhost:13000",
"redis_queue": "redis://127.0.0.1:11000",
"redis_socketio": "redis://127.0.0.1:13000",
"redis_cache": "redis://127.0.0.1:13000",
},
)

Expand All @@ -66,9 +66,9 @@ def test_multiple_benches(self):
"webserver_port": 8001,
"socketio_port": 9001,
"file_watcher_port": 6788,
"redis_queue": "redis://localhost:11001",
"redis_socketio": "redis://localhost:13001",
"redis_cache": "redis://localhost:13001",
"redis_queue": "redis://127.0.0.1:11001",
"redis_socketio": "redis://127.0.0.1:13001",
"redis_cache": "redis://127.0.0.1:13001",
},
)

Expand Down
21 changes: 17 additions & 4 deletions easy-install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import fileinput
import logging
import os
import platform
Expand Down Expand Up @@ -114,7 +115,10 @@ def check_repo_exists() -> bool:
return os.path.exists(os.path.join(os.getcwd(), "frappe_docker"))


def setup_prod(project: str, sites, email: str, version: str = None) -> None:
def setup_prod(project: str, sites, email: str, version: str = None, image = None) -> None:
if len(sites) == 0:
sites = ["site1.localhost"]

if check_repo_exists():
compose_file_name = os.path.join(os.path.expanduser("~"), f"{project}-compose.yml")
docker_repo_path = os.path.join(os.getcwd(), "frappe_docker")
Expand Down Expand Up @@ -171,6 +175,14 @@ def setup_prod(project: str, sites, email: str, version: str = None) -> None:
logging.error("Docker Compose generation failed", exc_info=True)
cprint("\nGenerating Compose File failed\n")
sys.exit(1)

# Use custom image
if image:
for line in fileinput.input(compose_file_name, inplace=True):
if "image: frappe/erpnext" in line:
line = line.replace("image: frappe/erpnext", f"image: {image}")
sys.stdout.write(line)

try:
# Starting with generated compose file
subprocess.run(
Expand Down Expand Up @@ -199,7 +211,7 @@ def setup_prod(project: str, sites, email: str, version: str = None) -> None:
else:
install_docker()
clone_frappe_docker_repo()
setup_prod(project, sites, email, version) # Recursive
setup_prod(project, sites, email, version, image) # Recursive


def setup_dev_instance(project: str):
Expand Down Expand Up @@ -316,11 +328,12 @@ def create_site(
"-s",
"--sitename",
help="Site Name(s) for your production bench",
default=["site1.localhost"],
default=[],
action="append",
dest="sites",
)
parser.add_argument("-n", "--project", help="Project Name", default="frappe")
parser.add_argument("-i", "--image", help="Full Image Name")
parser.add_argument(
"--email", help="Add email for the SSL.", required="--prod" in sys.argv
)
Expand All @@ -338,6 +351,6 @@ def create_site(
if "example.com" in args.email:
cprint("Emails with example.com not acceptable", level=1)
sys.exit(1)
setup_prod(args.project, args.sites, args.email, args.version)
setup_prod(args.project, args.sites, args.email, args.version, args.image)
else:
parser.print_help()

0 comments on commit 0122ef1

Please sign in to comment.