Skip to content

Add support for .service file #5

Open
@ndrezn

Description

@ndrezn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions