Template 与 Sandbox 资源入口。
构建 Python 镜像并运行 Sandbox
from ppio_sandbox import PPIO
ppio = PPIO()
template = ppio.template.new().from_python_image("3.12")
build = ppio.template.build(template, "example-python-template")
sandbox = ppio.sandbox.create(build.template_id)
result = sandbox.commands.run("python --version")
print(result.stdout)
sandbox.kill()
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const template = ppio.template.new().fromPythonImage('3.12')
const build = await ppio.template.build(template, 'example-python-template')
const sandbox = await ppio.sandbox.create(build.templateId)
const result = await sandbox.commands.run('python --version')
console.log(result.stdout)
await sandbox.kill()
# 从 Dockerfile 构建 Template,然后创建 Sandbox 并运行命令
ppio template create example-python-template --dockerfile ./ppio.Dockerfile
sandbox_id=$(ppio sandbox create example-python-template -d)
ppio sandbox exec "$sandbox_id" -- python --version
ppio sandbox kill "$sandbox_id"
为发布版本打标签
from ppio_sandbox import PPIO
ppio = PPIO()
template = ppio.template.new().from_python_image("3.12")
build = ppio.template.build(template, "my-template", tags=["latest", "stable"])
ppio.template.assign_tags("my-template:v1.0", "production")
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const template = ppio.template.new().fromPythonImage('3.12')
const build = await ppio.template.build(template, 'my-template', {
tags: ['latest', 'stable'],
})
await ppio.template.assignTags('my-template:v1.0', 'production')
查看 Template
from ppio_sandbox import PPIO
ppio = PPIO()
res = ppio.template.list(template_type="template_build", page=1, limit=5)
for item in res.items:
print(item.template_id, item.aliases, item.cpu_count, item.memory_mb)
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const paginator = ppio.template.list({ templateType: 'template_build', limit: 5 })
const page = await paginator.nextPage()
for (const item of page.templates) {
console.log(item.templateId, item.aliases, item.cpuCount, item.memoryMB)
}