Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .service file #5

Open
ndrezn opened this issue May 27, 2023 · 0 comments
Open

Add support for .service file #5

ndrezn opened this issue May 27, 2023 · 0 comments

Comments

@ndrezn
Copy link
Member

ndrezn commented May 27, 2023

For applications which require services like Redis or Postgres, a standard file (probably .service) would be useful to recognize and automatically spin up those services for the app. This is especially useful as part of the deploy preview, which would be frustrating to use for now for apps which depend on those resources.

We can accomplish this with logic along the lines of:

SERVICE_FILEPATH = os.environ.get("SERVICEFILEPATH")
METHOD = os.environ.get("METHOD")

if SERVICE_FILEPATH:
    with open(SERVICE_FILEPATH, 'r') as svc_file:
        service_configs = json.load(svc_file)
        if not isinstance(service_configs, list):
            service_configs = [service_configs]

if METHOD == "CHECKSVC":
    for service in service_configs:
        push = "false" if connection.serviceExists(APP, service['type']) else "true"
        if push == "true":
            print(push)

in manage_apps.py and logic along the lines of:

# Check if service needs to be created
if [[ -f "$APPS_DIR/$APP/.service" ]]; then
  service_file="$APPS_DIR/$APP/.service"
  create_svc=true
fi

if [[ "$create_svc" == "true" ]]; then
  APP=$with_suffix METHOD="CREATESVC" SERVICEFILEPATH=$service_file python ./manage_apps.py
fi

in deploy.sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant