Skip to content

Commit

Permalink
feat: add GHA tests
Browse files Browse the repository at this point in the history
chore: added reading from env when rerunning script
- Makes current site as default
  • Loading branch information
athul committed Dec 14, 2022
1 parent 9313777 commit e76c7dc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/easy-install.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 15 additions & 5 deletions easy-install.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ def clone_frappe_docker_repo() -> None:
logging.error("Download and unzip failed", exc_info=True)
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 ={}
with open(os.path.join(dir,"example.env")) as f:
with open(os.path.join(dir,file)) as f:
for line in f:
if line.startswith('#') or not line.strip():
continue
key, value = line.strip().split('=', 1)
env_vars[key] = value
return env_vars


def write_to_env(wd: str, site: str, db_pass: str, admin_pass: str, email: str) -> None:
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:
f.writelines(
[
Expand Down Expand Up @@ -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",
level=3,
)
admin_pass = generate_pass()
db_pass = generate_pass(9)
admin_pass = ""
db_pass = ""
with open(compose_file_name, "w") as f:
# Writing to compose file
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)
cprint(
"\nA .env file is generated with basic configs. Please edit it to fit to your needs \n",
Expand All @@ -130,6 +133,10 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
) as en:
en.writelines(f"ADMINISTRATOR_PASSWORD={admin_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:
# TODO: Include flags for non-https and non-erpnext installation
subprocess.run(
Expand Down Expand Up @@ -182,6 +189,7 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
except Exception as e:
logging.error("Prod docker-compose failed", exc_info=True)
cprint(" Docker Compose failed, please check the container logs\n", e)
sys.exit(1)

cprint(f"\nCreating site: {sitename} \n", level=3)

Expand All @@ -203,13 +211,15 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
admin_pass,
"--install-app",
"erpnext",
"--set-default"
],
check=True,
)
logging.info("New site creation completed")
except Exception as e:
logging.error("Bench site creation failed", exc_info=True)
cprint("Bench Site creation failed\n", e)
sys.exit(1)
else:
install_docker()
clone_frappe_docker_repo()
Expand Down

0 comments on commit e76c7dc

Please sign in to comment.