Skip to content

Commit

Permalink
sandbox added (#235)
Browse files Browse the repository at this point in the history
* 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 <shahharsh176@gmail.com>
  • Loading branch information
deepakdinesh1123 and shahharsh176 committed May 21, 2024
1 parent 1ea5327 commit 0336d8f
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 26 deletions.
96 changes: 96 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions backend/src/zango/cli/project_template/project_name/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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")

Expand Down Expand Up @@ -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/
Expand Down
20 changes: 15 additions & 5 deletions backend/src/zango/cli/start_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 6 additions & 2 deletions deploy/init.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#!/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
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 .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 <app_name>
gitpod@b1be57580132:/zango/zango_project$ python manage.py ws_migrate <app_name>
```


Expand Down
3 changes: 3 additions & 0 deletions setup_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0336d8f

Please sign in to comment.