Press Blocks
Import the Press-Block
module and Instantiate a Press-Block
Client
[ ]:
from collections.abc import Iterator
from typing import Any
from peak.press import blocks
client: blocks.Block = blocks.get_client()
Prepare payload and create a new workflow block-spec
[ ]:
workflow_private_spec_body: dict[str, Any] = {
"version": "1",
"kind": "workflow",
"metadata": {
"name": "workflow-block-private",
"title": "Workflow Block",
"summary": "Creating a new workflow block spec.",
"description": "Creating a new workflow block spec from SDK.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"tags": [
{
"name": "sdk",
},
],
},
"release": {
"version": "1.0.0",
"notes": "This is the original release",
},
"config": {
"triggers": [],
"images": {
"example-image": {
"buildArguments": {
"CHUNK_SIZE": "1000",
},
"context": ".",
"dockerfile": "Dockerfile",
"secrets": ["SECRET_1"],
"useCache": False,
"version": "0.0.1",
},
},
"steps": {
"step-1": {
"type": "standard",
"imageRef": "example-image",
"resources": {
"instanceTypeId": 21,
"storage": "10GB",
},
"command": "python main.py",
},
"step-2": {
"type": "standard",
"imageDetails": {
"id": 1,
"versionId": 1,
},
"resources": {
"instanceTypeId": 21,
"storage": "10GB",
},
"command": "python main.py",
},
},
},
}
workflow_private_spec: dict[str, str] = client.create_spec(
body=workflow_private_spec_body,
artifact={"path": "../peak", "ignore_files": [".dockerignore"]},
featured=True,
scope="private",
)
workflow_shared_spec_body: dict[str, Any] = {
"version": "1",
"kind": "workflow",
"metadata": {
"name": "workflow-block-shared",
"title": "Workflow Block",
"summary": "Creating a new workflow block spec.",
"description": "Creating a new workflow block spec from SDK.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"tags": [
{
"name": "sdk",
},
],
},
"release": {
"version": "1.0.0",
"notes": "This is the original release",
},
"config": {
"triggers": [],
"steps": {
"step-1": {
"type": "standard",
"image": {
"context": ".",
"dockerfile": "Dockerfile",
"version": "0.0.1",
},
"resources": {
"instanceTypeId": 21,
"storage": "10GB",
},
"command": "python main.py",
},
},
},
}
workflow_shared_spec: dict[str, str] = client.create_spec(
body=workflow_shared_spec_body,
artifact={"path": "../peak", "ignore_files": [".dockerignore"]},
featured=True,
scope="shared",
tenants=["tenant1", "tenant2"],
)
Prepare payload and create a new webapp block-spec
[ ]:
webapp_private_spec_body: dict[str, Any] = {
"version": "1",
"kind": "webapp",
"metadata": {
"name": "webapp-block-private",
"title": "Webapp Block",
"summary": "Creating a new webapp block spec.",
"description": "Creating a new webapp block spec from SDK.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"tags": [
{
"name": "sdk",
},
],
},
"release": {
"version": "1.0.0",
"notes": "This is the original release",
},
"config": {
"imageDetails": {
"id": 123,
"versionId": 1,
},
},
}
webapp_private_spec: dict[str, str] = client.create_spec(
body=webapp_private_spec_body,
featured=True,
scope="private",
)
webapp_shared_spec_body: dict[str, Any] = {
"version": "1",
"kind": "webapp",
"metadata": {
"name": "webapp-block-shared",
"title": "Webapp Block",
"summary": "Creating a new webapp block spec.",
"description": "Creating a new webapp block spec from SDK.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"tags": [
{
"name": "sdk",
},
],
},
"release": {
"version": "1.0.0",
"notes": "This is the original release",
},
"config": {
"image": {
"buildArguments": {
"CHUNK_SIZE": "1000",
},
"context": ".",
"dockerfile": "Dockerfile",
"version": "0.0.1",
},
},
}
webapp_shared_spec: dict[str, str] = client.create_spec(
body=webapp_shared_spec_body,
artifact={"path": "../peak", "ignore_files": [".dockerignore"]},
featured=True,
scope="shared",
tenants=["tenant1", "tenant2"],
)
List created block-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 block-spec
[ ]:
existing_spec: dict[str, Any] = client.describe_spec(workflow_private_spec["id"])
Update the metadata and discoverability of a block-spec
[ ]:
updated_spec_body: dict[str, Any] = {
"metadata": {
"name": "updated-block-spec",
"title": "Updated Spec Metadata",
"summary": "Updating block spec metadata.",
"description": "Updating block spec metadata from SDK.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"tags": [
{
"name": "sdk",
},
],
"status": "available",
},
"featured": False,
"scope": "private",
}
client.update_spec_metadata(
spec_id=workflow_private_spec["id"],
body=updated_spec_body,
)
Create a new workflow block-spec
release with updated config and release
[ ]:
body: dict[str, Any] = {
"config": {
"triggers": [],
"images": {
"example-image": {
"buildArguments": {
"CHUNK_SIZE": "1000",
},
"context": ".",
"dockerfile": "Dockerfile",
"secrets": ["SECRET_1"],
"useCache": False,
"version": "0.0.1",
},
},
"steps": {
"step-1": {
"type": "standard",
"imageRef": "example-image",
"resources": {
"instanceTypeId": 21,
"storage": "10GB",
},
"command": "python main.py",
},
"step-2": {
"type": "standard",
"imageDetails": {
"id": 123,
"versionId": 2,
},
"resources": {
"instanceTypeId": 21,
"storage": "15GB",
},
"command": "python main.py",
},
},
},
"release": {
"version": "2.0.0",
"notes": "This is a revised release",
},
}
new_spec_release: dict[str, str] = client.create_spec_release(
spec_id=workflow_private_spec["id"],
body=body,
artifact={"path": "../peak", "ignore_files": [".dockerignore"]},
)
Create a new webapp block-spec
release with updated config and release
[ ]:
body: dict[str, Any] = {
"config": {
"image": {
"buildArguments": {
"CHUNK_SIZE": "100",
},
"context": ".",
"dockerfile": "Dockerfile",
"version": "0.0.2",
},
},
"release": {
"version": "2.0.0",
"notes": "This is a revised release",
},
}
new_spec_release: dict[str, str] = client.create_spec_release(
spec_id=webapp_private_spec["id"],
body=body,
artifact={"path": "../peak", "ignore_files": [".dockerignore"]},
)
Describe the block-spec
release
[ ]:
block_spec_release_info: dict[str, Any] = client.describe_spec_release(workflow_private_spec["id"], "2.0.0")
List all release
(s) in a block-spec
and iterate over them
[ ]:
spec_releases_iterator: Iterator[dict[str, Any]] = client.list_spec_releases(workflow_private_spec["id"])
spec_releases_iterated: dict[str, Any] = next(spec_releases_iterator)
Create a new deployment
from a specific block-spec
’s release
[ ]:
body: dict[str, str] = {
"metadata": {
"description": "Creating a new workflow block deployment.",
"descriptionContentType": "text/plain",
"imageUrl": "https://my-block-pics.com/image-0.jpg",
"name": "new-deployment",
"summary": "Creating new deployment.",
"tags": [
{
"name": "sdk",
},
],
"title": "New Deployment",
},
"revision": {
"notes": "This is the initial revision",
},
"spec": {
"id": workflow_private_spec["id"],
"release": {
"version": "1.0.0",
},
},
}
workflow_block_deployment: dict[str, str] = client.create_deployment(body)
List all existing deployment
(s) and iterate over them
[ ]:
list_deployments_iterator: Iterator[dict[str, Any]] = client.list_deployments()
list_deployments_iterated: dict[str, Any] = next(list_deployments_iterator)
Describe a block
deployment
[ ]:
client.describe_deployment(workflow_block_deployment["id"])
Update an existing deployment
’s metadata
[ ]:
updated_deployment_body = {
"description": "Updating workflow deployment",
"descriptionContentType": "text/plain",
"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(workflow_block_deployment["id"], body=updated_deployment_body)
Delete a block
deployment
[ ]:
client.delete_deployment(workflow_block_deployment["id"])
Delete an existing block-spec
with all it’s release
(s)
[ ]:
client.delete_spec(workflow_private_spec["id"])