From 0336d8fbc22e280676ea3c9e1ad1a65d32e0f4e5 Mon Sep 17 00:00:00 2001 From: deepakdinesh1123 <52698821+deepakdinesh1123@users.noreply.github.com> Date: Tue, 21 May 2024 07:01:06 +0530 Subject: [PATCH] sandbox added (#235) * sandbox added path error fixed non existent directory error fixed setup_project argument fixed missing arguments added platform_domain_url added platform_domain_url added platform_domain_url fixed commands fixed and directory structure changed location update location update location update location update location update dockerfile updated and docker build step removed * localhost added as default platform url * chmod removed and email and password updated * Scaling image in readme updated * multiple keys in .env file solved * readme & docs changes * fix: docs link in readme --------- Co-authored-by: Harsh Shah --- .gitpod.yml | 96 +++++++++++++++++++ README.md | 7 +- backend/README.md | 8 +- .../project_template/project_name/settings.py | 17 ++-- backend/src/zango/cli/start_project.py | 20 +++- deploy/init.sh | 8 +- .../installing-zelthy/gitpod.mdx | 8 +- setup_project.py | 3 + 8 files changed, 141 insertions(+), 26 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..70e3d4fe --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,96 @@ +# Image of workspace. Learn more: https://www.gitpod.io/docs/configure/workspaces/workspace-image +image: gitpod/workspace-full:latest +checkoutLocation: "zango-sandbox/zango" +workspaceLocation: "zango-sandbox" + +tasks: + - name: URLs + command: | + cd /workspace/ + + # Run the gp info --json containing workspace info like workspace_id, url + info=$(gp info --json) + + # Extract the workspace ID + workspace_id=$(echo "$info" | jq -r '.workspace_id') + + # Extract cluster host + cluster_host=$(echo "$info" | jq -r '.cluster_host') + + # array to store app urls + app_urls=() + + # Expose local ports + for port in {8000..8001}; do + nohup gp ports expose $port > nohup.out 2>&1 & + done + + # Storing URLs + for port in {8001..8002}; do + gp ports visibility $port:public + app_url="${port}-${workspace_id}.${cluster_host}" + app_urls+=("$app_url") + done + + platform_domain_url=$(gp url 8000) + + # Printing the URLs + GREEN='\033[0;32m' # ANSI color code for green + NC='\033[0m' # ANSI color code to reset to default + + printf "\n${GREEN}Platform URL :${NC}\n" + printf "${GREEN}%s${NC}\n" "$platform_domain_url/platform" + printf "\n${GREEN}username: platform_admin@zelthy.com ${NC}" + printf "\n${GREEN}password: Zango@123 ${NC}\n" + + printf "\n${GREEN}App URLs :${NC}\n" + for url in "${app_urls[@]}"; do + printf "${GREEN}%s${NC}\n" "$url" + done + + - name: Setup and start the project + command: | + cd /workspace/zango-sandbox/zango + export UID=$(id -u) + export GID=$(id -g) + # Run the gp info --json containing workspace info like workspace_id, url + info=$(gp info --json) + + # Extract the workspace ID + workspace_id=$(echo "$info" | jq -r '.workspace_id') + + # Extract cluster host + cluster_host=$(echo "$info" | jq -r '.cluster_host') + + app_server_port=8000 + + platform_domain_url="${app_server_port}-${workspace_id}.${cluster_host}" + + if [ ! -d "/workspace/zango-sandbox/sandbox" ]; then + python setup_project.py --project_dir /workspace/zango-sandbox/sandbox --platform_domain_url $platform_domain_url + cd /workspace/zango-sandbox/sandbox + echo "CORS_ORIGIN_WHITELIST=https://*.gitpod.io" >> .env + echo "CSRF_TRUSTED_ORIGINS=https://*.gitpod.io" >> .env + else + cd /workspace/zango-sandbox/sandbox + fi + + if [ ! -d "/workspace/zango-sandbox/sandbox/zango_project" ]; then + # Building project + DOCKER_BUILDKIT=0 HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose build + + # starting services + docker-compose up + else + # Starting server + echo "Existing project, Starting server..." + + # starting services + docker-compose up + fi + + sudo chown -R gitpod:gitpod /workspace/zango-sandbox/sandbox/zango_project + +ports: + - port: 8000 + visibility: public diff --git a/README.md b/README.md index 1d946e96..60b3c6e5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ - Suite of essential packages to serve as the building blocks of Apps - Use case packages to build the industry specific use cases -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/zelthy3-gitpod-sandbox-official/) +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/Zango/) #### App Panel - Central hub to manage all your apps/ microservices @@ -50,8 +50,7 @@ Perform tasks such as configuring permissions, managing user roles, and much mor Zango redefines multi-tenancy by enabling multiple different apps to run on a single server. Say goodbye to the limitations of traditional scaling methods. With our platform, you can run multiple different applications on a single server, which helps in keeping the cost in check. -![Zango Scaling](https://zelthy-initium-production-static.s3.amazonaws.com/static/zelthymain/react-images/cost-effective-scaling.svg) - +![Scaling](https://github.com/Healthlane-Technologies/Zango/assets/52698821/497837f7-5210-4cfd-8f36-961327c9c405) #### 🚀 Getting Started: - [Gitpod](https://www.zango.dev/docs/core/getting-started/installing-zelthy/gitpod) @@ -61,7 +60,7 @@ Zango redefines multi-tenancy by enabling multiple different apps to run on a si #### 📦 Free Packages A few essential packages are freely available. These packages enable development of a wide variety of applications and are available for installation from the App Panel. -- [Basic Auth](https://www.zango.dev/docs/login/introduction) +- [Basic Auth](https://www.zango.dev/docs/basic-auth/introduction) - [Frames](https://www.zango.dev/docs/frame/introduction) - [CRUD](https://www.zango.dev/docs/crud/introduction) - [Workflow](https://www.zango.dev/docs/workflow/overview) diff --git a/backend/README.md b/backend/README.md index ea603cf1..b75124d6 100644 --- a/backend/README.md +++ b/backend/README.md @@ -36,7 +36,7 @@ - Suite of essential packages to serve as the building blocks of Apps - Use case packages to build the industry specific use cases -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/zelthy3-gitpod-sandbox-official/) +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/Zango/) #### App Panel - Central hub to manage all your apps/ microservices @@ -48,7 +48,7 @@ Perform tasks such as configuring permissions, managing user roles, and much mor Zango redefines multi-tenancy by enabling multiple different apps to run on a single server. Say goodbye to the limitations of traditional scaling methods. With our platform, you can run multiple different applications on a single server, which helps in keeping the cost in check. -![Zango Scaling](https://zelthy-initium-production-static.s3.amazonaws.com/static/zelthymain/react-images/cost-effective-scaling.svg) +![Scaling](https://github.com/Healthlane-Technologies/Zango/assets/52698821/497837f7-5210-4cfd-8f36-961327c9c405) #### 🚀 Getting Started: @@ -60,9 +60,9 @@ Zango redefines multi-tenancy by enabling multiple different apps to run on a si A few essential packages are freely available. These packages enable development of a wide variety of applications and are available for installation from the App Panel. -- [Basic Auth](https://www.zango.dev/docs/login/introduction) +- [Basic Auth](https://www.zango.dev/docs/basic-auth/introduction) - [Frames](https://www.zango.dev/docs/frame/introduction) -- [CRUD](https://www.zango.dev/docs/crud/introduction) +- [CRUD](https://www.zango.dev/docs/crud/introduction) - [Workflow](https://www.zango.dev/docs/workflow/overview) #### 🌟 Get Involved and Make a Difference diff --git a/backend/src/zango/cli/project_template/project_name/settings.py b/backend/src/zango/cli/project_template/project_name/settings.py index 00866682..cd3bae4e 100644 --- a/backend/src/zango/cli/project_template/project_name/settings.py +++ b/backend/src/zango/cli/project_template/project_name/settings.py @@ -13,6 +13,9 @@ SESSION_SECURITY_WARN_AFTER=(int, 1700), SESSION_SECURITY_EXPIRE_AFTER=(int, 1800), INTERNAL_IPS=(list, []), + ALLOWED_HOSTS=(list, ["*"]), + CORS_ORIGIN_WHITELIST=(list, ["http://localhost:1443", "http://localhost:8000"]), + CSRF_TRUSTED_ORIGINS=(list, ["http://localhost:1443", "http://localhost:8000"]), ) environ.Env.read_env(os.path.join(BASE_DIR.parent, ".env")) @@ -21,7 +24,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = env("ALLOWED_HOSTS") PROJECT_NAME = env("PROJECT_NAME") @@ -61,12 +64,12 @@ CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True -CORS_ORIGIN_WHITELIST = [ - "http://localhost:8000" -] # Change according to domain configured -CSRF_TRUSTED_ORIGINS = [ - "http://localhost:1443" -] # Change according to domain configured +CORS_ORIGIN_WHITELIST = env( + "CORS_ORIGIN_WHITELIST" +) # Change according to domain configured +CSRF_TRUSTED_ORIGINS = env( + "CSRF_TRUSTED_ORIGINS" +) # Change according to domain configured # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ diff --git a/backend/src/zango/cli/start_project.py b/backend/src/zango/cli/start_project.py index 250d1969..725aa2aa 100644 --- a/backend/src/zango/cli/start_project.py +++ b/backend/src/zango/cli/start_project.py @@ -95,11 +95,21 @@ def create_project( command = f"{command} --template {str(project_template_path)}" subprocess.run(command, shell=True, check=True) - env_file = open(f".env", "w") - env_file.write( - f"POSTGRES_DB={db_name}\nPOSTGRES_USER={db_user}\nPOSTGRES_PASSWORD={db_password}\nPOSTGRES_HOST={db_host}\nPOSTGRES_PORT={db_port}\nREDIS_HOST={redis_host}\nREDIS_PORT={redis_port}\nPROJECT_NAME={project_name}\n" - ) - env_file.close() + env_keys = { + "POSTGRES_DB": db_name, + "POSTGRES_USER": db_user, + "POSTGRES_PASSWORD": db_password, + "POSTGRES_HOST": db_host, + "POSTGRES_PORT": db_port, + "REDIS_HOST": redis_host, + "REDIS_PORT": redis_port, + "PROJECT_NAME": project_name, + } + fcontent = open(".env", "r").read() + with open(f".env", "a+") as f: + for key, value in env_keys.items(): + if key not in fcontent: + f.write(f"{key}={value}\n") return True, "Project created successfully" diff --git a/deploy/init.sh b/deploy/init.sh index fc2b68f0..a7388fcb 100644 --- a/deploy/init.sh +++ b/deploy/init.sh @@ -1,10 +1,14 @@ #!/bin/sh +if [ -z "$PLATFORM_DOMAIN_URL" ]; then + PLATFORM_DOMAIN_URL="localhost" +fi + if [ "$ENV" = "dev" ]; then if [ -d "$PROJECT_NAME" ]; then echo "restarting existing project" else - zango start-project $PROJECT_NAME --db_name="$POSTGRES_DB" --db_user="$POSTGRES_USER" --db_password="$POSTGRES_PASSWORD" --db_host="$POSTGRES_HOST" --db_port="$POSTGRES_PORT" --platform_username="$PLATFORM_USERNAME" --platform_user_password="$PLATFORM_USER_PASSWORD" --redis_host="$REDIS_HOST" --redis_port="$REDIS_PORT" + zango start-project $PROJECT_NAME --db_name="$POSTGRES_DB" --db_user="$POSTGRES_USER" --db_password="$POSTGRES_PASSWORD" --db_host="$POSTGRES_HOST" --db_port="$POSTGRES_PORT" --platform_username="$PLATFORM_USERNAME" --platform_user_password="$PLATFORM_USER_PASSWORD" --redis_host="$REDIS_HOST" --redis_port="$REDIS_PORT" --platform_domain_url="$PLATFORM_DOMAIN_URL" fi cd "$PROJECT_NAME" python manage.py runserver 0.0.0.0:8000 @@ -12,7 +16,7 @@ else if [ -d "$PROJECT_NAME" ]; then echo "restarting existing project" else - zango start-project $PROJECT_NAME --db_name="$POSTGRES_DB" --db_user="$POSTGRES_USER" --db_password="$POSTGRES_PASSWORD" --db_host="$POSTGRES_HOST" --db_port="$POSTGRES_PORT" --platform_username="$PLATFORM_USERNAME" --platform_user_password="$PLATFORM_USER_PASSWORD" --redis_host="$REDIS_HOST" --redis_port="$REDIS_PORT" + zango start-project $PROJECT_NAME --db_name="$POSTGRES_DB" --db_user="$POSTGRES_USER" --db_password="$POSTGRES_PASSWORD" --db_host="$POSTGRES_HOST" --db_port="$POSTGRES_PORT" --platform_username="$PLATFORM_USERNAME" --platform_user_password="$PLATFORM_USER_PASSWORD" --redis_host="$REDIS_HOST" --redis_port="$REDIS_PORT" --platform_domain_url="$PLATFORM_DOMAIN_URL" fi cd "$PROJECT_NAME" cp /zango/config/gunicorn.conf.py . diff --git a/docs/docs/documentation/getting-started/installing-zelthy/gitpod.mdx b/docs/docs/documentation/getting-started/installing-zelthy/gitpod.mdx index 71fd8fcc..ae27efb5 100644 --- a/docs/docs/documentation/getting-started/installing-zelthy/gitpod.mdx +++ b/docs/docs/documentation/getting-started/installing-zelthy/gitpod.mdx @@ -15,7 +15,7 @@ sidebar_label: GitPod To get started with using Zango in gitpod, you can click on the button below: -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/zelthy3-gitpod-sandbox-official/) +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Healthlane-Technologies/Zango/) Please refer to the video above and follow the steps to launch the workspace and set up the Zango project. @@ -51,15 +51,15 @@ All the Zango services, such as the app server, database, Celery, and Redis, are To run the management commands, you will need to enter the app container: ```bash -docker exec -it zelthy3-gitpod-sandbox-official-app-1 bash +docker exec -it sandbox-app-1 bash ``` -Once you are in the app container, you can run the management commands from the ``zelthy_project`` directory: +Once you are in the app container, you can run the management commands from the ``zango_project`` directory: Example: ```bash -gitpod@b1be57580132:/zelthy/zelthy_project$ python manage.py ws_migrate +gitpod@b1be57580132:/zango/zango_project$ python manage.py ws_migrate ``` diff --git a/setup_project.py b/setup_project.py index 5465ae2c..b76a1b77 100644 --- a/setup_project.py +++ b/setup_project.py @@ -47,6 +47,8 @@ def write_env_file(project_dir, args): f.write(f"POSTGRES_PORT=5432\n") f.write(f"REDIS_HOST=redis\n") f.write(f"REDIS_PORT=6379\n") + if args.platform_domain_url: + f.write(f"PLATFORM_DOMAIN_URL={args.platform_domain_url}\n") def build_core(): @@ -135,6 +137,7 @@ def rebuild_core(project_dir): help="The platform user password", ) parser.add_argument("--rebuild_core", action="store_true", default=False) + parser.add_argument("--platform_domain_url", default="localhost") args = parser.parse_args() try: if args.build_core: