持续集成(CI)
目录
为了帮助验证您的扩展并确保其功能正常,扩展 SDK 提供了相关工具,以协助您为扩展配置持续集成。
重要
The Docker Desktop Action 和 extension-test-helper 库 均为 实验性 功能。
使用 GitHub Actions 配置 CI 环境
您需要安装并启动 Docker Desktop,才能安装并验证您的扩展。 您可以在 GitHub Actions 中使用 Docker Desktop Action 来启动 Docker Desktop,只需在工作流文件中添加以下内容:
steps:
- id: start_desktop
uses: docker/desktop-action/start@v0.1.0注意
此操作目前仅支持 GitHub Action 的 macOS 运行器。您需要为端到端测试指定
runs-on: macOS-latest。
一旦该步骤执行完毕,后续步骤将使用 Docker Desktop 和 Docker CLI 来安装并测试该扩展。
使用 Puppeteer 验证您的扩展程序
一旦 Docker Desktop 在 CI 中启动,您就可以使用 Jest 和 Puppeteer 构建、安装并验证您的扩展。
首先,从您的测试环境中构建并安装该扩展:
import { DesktopUI } from "@docker/extension-test-helper";
import { exec as originalExec } from "child_process";
import * as util from "util";
export const exec = util.promisify(originalExec);
// keep a handle on the app to stop it at the end of tests
let dashboard: DesktopUI;
beforeAll(async () => {
await exec(`docker build -t my/extension:latest .`, {
cwd: "my-extension-src-root",
});
await exec(`docker extension install -f my/extension:latest`);
});然后打开 Docker Desktop 仪表板,并在您的扩展界面中运行一些测试:
describe("Test my extension", () => {
test("should be functional", async () => {
dashboard = await DesktopUI.start();
const eFrame = await dashboard.navigateToExtension("my/extension");
// use puppeteer APIs to manipulate the UI, click on buttons, expect visual display and validate your extension
await eFrame.waitForSelector("#someElementId");
});
});最后,关闭 Docker Desktop 仪表板并卸载您的扩展程序:
afterAll(async () => {
dashboard?.stop();
await exec(`docker extension uninstall my/extension`);
});