feat: add base mod
This commit is contained in:
@@ -3,6 +3,20 @@ import { Container } from "./container.ts";
|
||||
import { Image } from "./image.ts";
|
||||
import { modem } from "./modem.ts";
|
||||
|
||||
/**
|
||||
* @module
|
||||
*
|
||||
* A simple wrapper for pulling a docker image, and creating docker containers.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { docker } from "@valkyr/testcontainers";
|
||||
*
|
||||
* await docker.pullImage("docker:image");
|
||||
*
|
||||
* const container = await docker.createContainer({ Image: "docker:image" });
|
||||
* ```
|
||||
*/
|
||||
export class Docker {
|
||||
/**
|
||||
* Create a new docker container.
|
||||
@@ -12,7 +26,10 @@ export class Docker {
|
||||
* @params config - The configuration for the container.
|
||||
* @params query - Query parameters.
|
||||
*/
|
||||
async createContainer(config: Partial<ContainerConfig>, query: Partial<{ name: string; platform: string }> = {}) {
|
||||
async createContainer(
|
||||
config: Partial<ContainerConfig>,
|
||||
query: Partial<{ name: string; platform: string }> = {},
|
||||
): Promise<Container> {
|
||||
const { Id, Warnings } = await modem.post<{ Id: string; Warnings: string[] }>({
|
||||
path: "/containers/create",
|
||||
query,
|
||||
@@ -26,7 +43,7 @@ export class Docker {
|
||||
*
|
||||
* @param image - The image to pull.
|
||||
*/
|
||||
async pullImage(image: string) {
|
||||
async pullImage(image: string): Promise<void> {
|
||||
await new Image().create({ fromImage: image });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user