devbox-sdk
Version:
A lightweight development environment management tool based on Kubernetes
161 lines (156 loc) • 4.61 kB
TypeScript
import { Readable, Writable } from 'stream';
import * as k8s from '@kubernetes/client-node';
/**
* Options for creating a new DevBox
*/
interface DevBoxOptions {
/**
* Runtime for the DevBox
* @example 'next.js-14-2-5-2024-11-13-0835'
*/
runtime: Runtime;
/**
* Kubeconfig for authorization
*/
kubeconfig: string;
}
/**
* Available runtime options for DevBox
*/
type Runtime = 'next.js-14-2-5-2024-11-13-0835' | 'node.js-22-2024-11-13-0700' | 'node.js-18-2024-11-13-0700' | 'node.js-20-2024-11-13-0700' | 'python-3-10-2024-11-12-0651' | 'python-3-11-2024-11-12-0651' | 'python-3-12-2024-11-12-0651' | 'react-18-2-0-2024-11-13-0835' | 'vue-v3-4-29-2024-11-13-0835';
/**
* Response from the DevBox API
*/
interface DevBoxResponse<T = any> {
code: number;
data: T;
error?: string;
}
interface DevBoxDetail {
apiVersion: string;
kind: string;
metadata: {
creationTimestamp: string;
name: string;
namespace: string;
uid: string;
};
spec: {
network: {
extraPorts: Array<{
containerPort: number;
protocol: string;
}>;
type: string;
};
resource: {
cpu: string;
memory: string;
};
runtimeRef: {
name: string;
namespace: string;
};
squash: boolean;
state: string;
tolerations: Array<{
effect: string;
key: string;
operator: string;
}>;
runtimeType: string;
};
status: {
commitHistory: Array<{
containerID: string;
image: string;
node: string;
pod: string;
predicatedStatus: string;
status: string;
time: string;
}>;
lastState: Record<string, any>;
network: {
nodePort: number;
tailnet: string;
type: string;
};
phase: string;
state: {
running?: {
startedAt: string;
};
waiting?: Record<string, any>;
};
};
portInfos: Array<{
networkName: string;
port: number;
protocol: string;
openPublicDomain: boolean;
publicDomain: string;
customDomain: string;
portName: string;
}>;
}
declare class KubeFileSystem {
private readonly k8sExec;
private readonly namespace;
private readonly podName;
private readonly containerName;
constructor(k8sExec: k8s.Exec, namespace: string, podName: string, containerName: string);
execCommand(command: string[], stdin?: Readable | null, stdout?: Writable | null, retryCount?: number): Promise<string>;
private isRetryableError;
private executeWithTimeout;
writeFile(path: string, content: string): Promise<string>;
readFile(path: string): Promise<string>;
mkdir(path: string): Promise<string>;
rm(path: string): Promise<string>;
mv(from: string, to: string): Promise<string>;
}
declare class DevBox {
private static readonly DEFAULT_CPU;
private static readonly DEFAULT_MEMORY;
private static readonly DEFAULT_PORT;
private static readonly RUNTIME_NAMESPACE_MAP;
private static getApiUrlFromKubeconfig;
private static getDomainSuffixFromKubeconfig;
private readonly kubeconfig;
private readonly apiUrl;
private readonly domainSuffix;
readonly id: string;
readonly fileSystem: KubeFileSystem;
private constructor();
/**
* Create a new DevBox instance
*/
static create(options: DevBoxOptions): Promise<DevBox>;
private static getDetail;
/**
* Delete a DevBox instance by name
* @param name DevBox name to delete
* @param kubeconfig Kubernetes config for authentication
*/
static delete(name: string, kubeconfig: string): Promise<void>;
/**
* Get DevBox details
*/
getDetail(): Promise<DevBoxDetail>;
/**
* Delete this DevBox instance
*/
delete(): Promise<void>;
/**
* Get all DevBox instances
* @param kubeconfig Kubernetes config for authentication
*/
static list(kubeconfig: string): Promise<DevBoxDetail[]>;
/**
* Get an existing DevBox instance by ID
* @param id DevBox ID
* @param kubeconfig Kubernetes config for authentication
*/
static get(id: string, kubeconfig: string): Promise<DevBox>;
}
export { DevBox, type DevBoxDetail, type DevBoxOptions, type DevBoxResponse, type Runtime };