2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-08 16:14:12 +00:00

feat: add GHA tests

chore: added reading from env when rerunning script
- Makes current site as default
This commit is contained in:
Athul Cyriac Ajay 2022-12-14 17:42:24 +05:30
parent 9313777276
commit e76c7dccf5
2 changed files with 42 additions and 5 deletions

27
.github/workflows/easy-install.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: 'Easy Install Test'
on:
pull_request:
workflow_dispatch:
push:
branches: [ develop ]
permissions:
contents: read
jobs:
easy-install-setup:
runs-on: ubuntu-latest
timeout-minutes: 60
name: Easy Install Test
steps:
- uses: actions/checkout@v3
- 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.local list-apps --format json
result=$(curl -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

View File

@ -59,9 +59,9 @@ def clone_frappe_docker_repo() -> None:
logging.error("Download and unzip failed", exc_info=True) logging.error("Download and unzip failed", exc_info=True)
cprint("\nCloning frappe_docker Failed\n\n", "[ERROR]: ", e, level=1) cprint("\nCloning frappe_docker Failed\n\n", "[ERROR]: ", e, level=1)
def get_latest_version(dir) -> Dict: def get_from_env(dir,file) -> Dict:
env_vars ={} env_vars ={}
with open(os.path.join(dir,"example.env")) as f: with open(os.path.join(dir,file)) as f:
for line in f: for line in f:
if line.startswith('#') or not line.strip(): if line.startswith('#') or not line.strip():
continue continue
@ -69,9 +69,10 @@ def get_latest_version(dir) -> Dict:
env_vars[key] = value env_vars[key] = value
return env_vars return env_vars
def write_to_env(wd: str, site: str, db_pass: str, admin_pass: str, email: str) -> None: def write_to_env(wd: str, site: str, db_pass: str, admin_pass: str, email: str) -> None:
site_name = site or "" site_name = site or ""
example_env = get_latest_version(wd) example_env = get_from_env(wd,"example.env")
with open(os.path.join(wd, ".env"), "w") as f: with open(os.path.join(wd, ".env"), "w") as f:
f.writelines( f.writelines(
[ [
@ -115,11 +116,13 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
"\nPlease refer to .example.env file in the frappe_docker folder to know which keys to set\n\n", "\nPlease refer to .example.env file in the frappe_docker folder to know which keys to set\n\n",
level=3, level=3,
) )
admin_pass = generate_pass() admin_pass = ""
db_pass = generate_pass(9) db_pass = ""
with open(compose_file_name, "w") as f: with open(compose_file_name, "w") as f:
# Writing to compose file # Writing to compose file
if not os.path.exists(os.path.join(docker_repo_path, ".env")): if not os.path.exists(os.path.join(docker_repo_path, ".env")):
admin_pass = generate_pass()
db_pass = generate_pass(9)
write_to_env(docker_repo_path, sitename, db_pass, admin_pass, email) write_to_env(docker_repo_path, sitename, db_pass, admin_pass, email)
cprint( cprint(
"\nA .env file is generated with basic configs. Please edit it to fit to your needs \n", "\nA .env file is generated with basic configs. Please edit it to fit to your needs \n",
@ -130,6 +133,10 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
) as en: ) as en:
en.writelines(f"ADMINISTRATOR_PASSWORD={admin_pass}\n") en.writelines(f"ADMINISTRATOR_PASSWORD={admin_pass}\n")
en.writelines(f"MARIADB_ROOT_PASSWORD={db_pass}\n") en.writelines(f"MARIADB_ROOT_PASSWORD={db_pass}\n")
else:
env = get_from_env(docker_repo_path,".env")
admin_pass = env['SITE_ADMIN_PASS']
db_pass = env['DB_PASSWORD']
try: try:
# TODO: Include flags for non-https and non-erpnext installation # TODO: Include flags for non-https and non-erpnext installation
subprocess.run( subprocess.run(
@ -182,6 +189,7 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
except Exception as e: except Exception as e:
logging.error("Prod docker-compose failed", exc_info=True) logging.error("Prod docker-compose failed", exc_info=True)
cprint(" Docker Compose failed, please check the container logs\n", e) cprint(" Docker Compose failed, please check the container logs\n", e)
sys.exit(1)
cprint(f"\nCreating site: {sitename} \n", level=3) cprint(f"\nCreating site: {sitename} \n", level=3)
@ -203,6 +211,7 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
admin_pass, admin_pass,
"--install-app", "--install-app",
"erpnext", "erpnext",
"--set-default"
], ],
check=True, check=True,
) )
@ -210,6 +219,7 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
except Exception as e: except Exception as e:
logging.error("Bench site creation failed", exc_info=True) logging.error("Bench site creation failed", exc_info=True)
cprint("Bench Site creation failed\n", e) cprint("Bench Site creation failed\n", e)
sys.exit(1)
else: else:
install_docker() install_docker()
clone_frappe_docker_repo() clone_frappe_docker_repo()