Press Apps

Import the press app module and Instantiate a press-app client

[ ]:
from collections.abc import Iterator
from typing import Any

from peak.press import apps

client: apps.App = apps.get_client()

Prepare an app-spec payload and create an app-spec

[ ]:
spec_body: dict[str, Any] = {
    "version": "1",
    "kind": "app",
    "metadata": {
        "name": "sdk",
        "title": "New App Spec",
        "summary": "Create new app spec",
        "description": "Creating app spec from SDK",
        "descriptionContentType": "text/markdown",
        "imageUrl": "https://my-spec-pics.com/image-1.jpg",
        "tags": [
            {
                "name": "sdk",
            },
        ],
    },
    "release": {
        "version": "1.0.0",
        "notes": "This is the original release",
    },
    "config": [
        {
            "id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
            "release": {
                "version": "1.0.0",
            },
        },
    ],
}


created_app_spec: dict[str, str] = client.create_spec(
    body=spec_body,
    featured=True,
    scope="shared",
    tenants=["tenant1", "tenant2"],
)

List created app-spec(s) and iterate over them

[ ]:
spec_iterator: Iterator[dict[str, Any]] = client.list_specs()
spec_iterated: dict[str, Any] = next(spec_iterator)

Describe an already existing app-spec

[ ]:
existing_spec: dict[str, Any] = client.describe_spec(created_app_spec["id"])

Update an app-spec’s metadata

[ ]:
client.update_spec_metadata(
    created_app_spec["id"],
    body={
        "metadata": {
            "name": "sdk-update",
            "description": "Update description from the SDK",
            "status": "available",
        },
        "featured": True,
    },
)

Create a new app-spec release with updated config and release

[ ]:
body: dict[str, Any] = {
    "config": [
        {
            "id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
            "release": {
                "version": "1.0.0",
            },
        },
    ],
    "release": {
        "version": "2.0.0",
        "notes": "This is a revised release",
    },
}


new_spec_release: dict[str, str] = client.create_spec_release(
    spec_id=created_app_spec["id"],
    body=body,
)

Describe the app-spec release

[ ]:
app_spec_release_info: dict[str, Any] = client.describe_spec_release(new_spec_release["id"], "2.0.0")

List all app-spec release(s) and iterate over them

[ ]:
releases_iterator: Iterator[dict[str, Any]] = client.list_spec_releases(
    spec_id=created_app_spec["id"],
    sort=["createdBy"],
)
releases_iterated: dict[str, Any] = next(releases_iterator)

Create a new deployment from an existing app-spec release

[ ]:
deployment: dict[str, str] = client.create_deployment(
    body={
        "metadata": {
            "description": "Creating a new deployment.",
            "descriptionContentType": "text/markdown",
            "imageUrl": "https://my-spec-pics.com/image-1.jpg",
            "name": "new-deployment",
            "summary": "This creates a new deployment",
            "tags": [
                {
                    "name": "sdk",
                },
            ],
            "title": "New Deployment",
        },
        "parameters": {
            "workflow-block-private": {
                "run": {
                    "agg_type": "AVG",
                    "email_notifications": True,
                    "num_iterations": 50,
                    "file_names": ["input.csv", "output.csv"],
                },
            },
            "webapp-block-private": {
                "run": {
                    "agg_type": "MAX",
                    "email_notifications": False,
                    "num_iterations": 10,
                    "file_names": ["input.csv", "output.csv"],
                },
            },
        },
        "revision": {
            "notes": "This is the initial revision",
        },
        "spec": {
            "id": created_app_spec["id"],
            "release": {
                "version": "1.0.0",
            },
        },
    },
)

List all existing deployment(s) and iterate over them

[ ]:
deployments_iterator: Iterator[dict[str, Any]] = client.list_deployments()
deployments: dict[str, Any] = next(deployments_iterator)

Describe an existing deployment

[ ]:
existing_deployment: dict[str, Any] = client.describe_deployment(deployment["id"])

Update an existing deployment’s metadata

[ ]:
updated_deployment_body = {
    "description": "Updated description",
    "descriptionContentType": "text/markdown",
    "imageUrl": "https://my-spec-pics.com/image-1.jpg",
    "name": "updated-deployment",
    "summary": "Updating the deployment metadata",
    "tags": [
        {
            "name": "sdk",
        },
    ],
    "title": "Updated Deployment",
}

client.update_deployment_metadata(deployment["id"], body=updated_deployment_body)

Create app deployment revision from a specific app-spec’s release

[ ]:
body: dict[str, str] = {
    "parameters": {
        "workflow-block-private": {
            "run": {
                "agg_type": "AVG",
                "email_notifications": True,
                "num_iterations": 50,
                "file_names": ["input.csv", "output.csv"],
            },
        },
        "webapp-block-private": {
            "run": {
                "agg_type": "MAX",
                "email_notifications": False,
                "num_iterations": 10,
                "file_names": ["input.csv", "output.csv"],
            },
        },
    },
    "revision": {
        "notes": "This is the second revision",
    },
    "spec": {
        "id": created_app_spec["id"],
        "release": {
            "version": "2.0.0",
        },
    },
}


deployment_revision: dict[str, str] = client.create_deployment_revision(deployment["id"], body)

Describe an app deployment revision

[ ]:
client.describe_deployment_revision(deployment["id"], deployment_revision["revision"])

List all revision(s) in an app deployment and iterate over them

[ ]:
deployment_revisions_iterator: Iterator[dict[str, Any]] = client.list_deployment_revisions(
    deployment["id"],
)
deployment_revisions_iterated: dict[str, Any] = next(deployment_revisions_iterator)

Delete an existing deployment

[ ]:
client.delete_deployment(deployment["id"])

Delete an existing app-spec with all its release(s)

[ ]:
client.delete_spec(created_app_spec["id"])