Azure 容器 Apps Sandbox 客户端库, 用于 JavaScript
此套件包含 Azure 容器 Apps Sandbox API 的同位素 SDK (数据平面+控制平面).
Azure Contractor Apps Sandbox是安全的,硬件同位化的微型VMs带有 子秒启动, 基于快照的悬浮/ 重现, 和每发箱网络 egress 政策——理想运行无信任代码,AI代理工作空间,dev环境, 和CI跑车.
预览 ——此软件包在预览中. API 表面可不改变 备注。 见 变化 用于升级时的移民笔记.
开始
目前得到支持的环境
先决条件
- 一个 Azure 订阅。 。 。 .
安装 @azure/containerapps-sandbox 软件包
安装客户端库 无数字 :
npm install @azure/containerapps-sandbox
创建和认证客户端
要创建客户端, 您需要 TokenCredential 从
@azure/identity数字 :
npm install @azure/identity
有两个客户:
ContainerAppsSandboxManagementClient- ARM号 控制平面 用于创建 并删除沙盒组.SandboxGroupClient- 那个 数据平面 用于一个沙盒组(沙盒), 磁盘图像,快照,卷,秘密,端口,相机,文件).
import { DefaultAzureCredential } from "@azure/identity";
import {
ContainerAppsSandboxManagementClient,
SandboxGroupClient,
endpointForRegion,
} from "@azure/containerapps-sandbox";
const credential = new DefaultAzureCredential();
const subscriptionId = "<your-subscription-id>";
const resourceGroupName = "my-rg";
const sandboxGroupName = "my-sandbox-group";
const region = "eastus2";
// 1. Create the sandbox group (ARM control plane).
const mgmt = new ContainerAppsSandboxManagementClient(credential, subscriptionId);
await mgmt.sandboxGroups
.beginCreateOrUpdate(resourceGroupName, sandboxGroupName, { location: region })
.then((p) => p.pollUntilDone());
// (Grant yourself the "Container Apps SandboxGroup Data Owner" role on the
// resource group so the data-plane calls below are authorized.)
// 2. Connect to the data plane and create a sandbox.
const group = new SandboxGroupClient(
credential,
endpointForRegion(region),
subscriptionId,
resourceGroupName,
sandboxGroupName,
);
const sandbox = await group.sandboxes.beginCreate({ disk: undefined }).then((p) => p.pollUntilDone());
// 3. Run a command.
const result = await group.sandboxes.exec(sandbox.id, { command: "echo hello && uname -a" });
console.log(result.stdout);
// 4. Clean up.
await group.sandboxes.delete(sandbox.id);
await mgmt.sandboxGroups.beginDelete(resourceGroupName, sandboxGroupName).then((p) => p.pollUntilDone());
关键概念
行动组
和生成的 Azure 管理 SDK 一样, 操作被分组到客户端上
资源类型,例如:. group.sandboxes.get(...), (中文(简体) ), group.diskImages.list(), (中文(简体) ),
mgmt.sandboxGroups.beginCreateOrUpdate(...)。 。 。 .
长期运作
需要超过几秒钟的操作会暴露一个 begin* 返回的方法
(单位:千美元) PollerLike<OperationState<T>, T> 从 @azure/core-lro数字 :
const poller = group.sandboxes.beginCreate({ sourcesRef: { diskImage: { name: "ubuntu", isPublic: true } } });
const sandbox = await poller.pollUntilDone();
页面结果
清单操作返回a PagedAsyncIterableIterator数字 :
for await (const sbx of group.sandboxes.list()) {
console.log(sbx.id, sbx.state);
}
端口 IP 访问控制
PortIpAccessControl 在发送前被验证客户端(服务
批量 ports.update 路径不是重新验证的服务器侧。 CIDRs必须是
网络对齐,最多10个规则,每个规则有1-10 CIDR, 独特的名称和
优先事项,以及0-1000范围内的优先事项.
import type { PortIpAccessControl } from "@azure/containerapps-sandbox";
const acl: PortIpAccessControl = {
defaultAction: "Deny",
rules: [{ name: "office", action: "Allow", priority: 10, sourceCidrs: ["10.0.0.0/8"] }],
};
await group.ports.add(sandbox.id, 8443, { ipAccessControl: acl });
解决问题
日志
允许伐木可能有助于发现有关失败的有用信息。 查看日志
,设置 AZURE_LOG_LEVEL 环境变量改为
info。或者,可以在运行时拨打
setLogLevel 输入 @azure/logger数字 :
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
今后的步骤
见 现场融合测试 (单位:千美元) 有效的端到端实例,可以练习每个操作组.