alchemy 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/alchemy.mjs +45102 -45100
- package/bin/alchemy.ts +1 -1
- package/bin/create-alchemy.ts +10 -4
- package/lib/cloudflare/bundle/bundle-worker.js +1 -1
- package/lib/cloudflare/bundle/bundle-worker.js.map +1 -1
- package/lib/docker/api.d.ts +185 -0
- package/lib/docker/api.d.ts.map +1 -0
- package/lib/docker/api.js +288 -0
- package/lib/docker/api.js.map +1 -0
- package/lib/docker/container.d.ts +147 -0
- package/lib/docker/container.d.ts.map +1 -0
- package/lib/docker/container.js +109 -0
- package/lib/docker/container.js.map +1 -0
- package/lib/docker/image.d.ts +92 -0
- package/lib/docker/image.d.ts.map +1 -0
- package/lib/docker/image.js +92 -0
- package/lib/docker/image.js.map +1 -0
- package/lib/docker/index.d.ts +7 -0
- package/lib/docker/index.d.ts.map +1 -0
- package/lib/docker/index.js +7 -0
- package/lib/docker/index.js.map +1 -0
- package/lib/docker/network.d.ts +62 -0
- package/lib/docker/network.d.ts.map +1 -0
- package/lib/docker/network.js +49 -0
- package/lib/docker/network.js.map +1 -0
- package/lib/docker/remote-image.d.ts +45 -0
- package/lib/docker/remote-image.d.ts.map +1 -0
- package/lib/docker/remote-image.js +36 -0
- package/lib/docker/remote-image.js.map +1 -0
- package/lib/docker/volume.d.ts +83 -0
- package/lib/docker/volume.d.ts.map +1 -0
- package/lib/docker/volume.js +76 -0
- package/lib/docker/volume.js.map +1 -0
- package/lib/fs/file-system-state-store.d.ts.map +1 -1
- package/lib/fs/file-system-state-store.js +5 -1
- package/lib/fs/file-system-state-store.js.map +1 -1
- package/lib/fs/file.d.ts.map +1 -1
- package/lib/fs/file.js +6 -3
- package/lib/fs/file.js.map +1 -1
- package/lib/os/exec.d.ts +19 -1
- package/lib/os/exec.d.ts.map +1 -1
- package/lib/os/exec.js +28 -4
- package/lib/os/exec.js.map +1 -1
- package/lib/util/cli.d.ts.map +1 -1
- package/lib/util/cli.js +1 -1
- package/lib/util/cli.js.map +1 -1
- package/package.json +5 -1
- package/src/cloudflare/bundle/bundle-worker.ts +1 -1
- package/src/docker/api.ts +365 -0
- package/src/docker/container.ts +267 -0
- package/src/docker/image.ts +200 -0
- package/src/docker/index.ts +6 -0
- package/src/docker/network.ts +101 -0
- package/src/docker/remote-image.ts +83 -0
- package/src/docker/volume.ts +154 -0
- package/src/fs/file-system-state-store.ts +5 -1
- package/src/fs/file.ts +6 -3
- package/src/os/exec.ts +48 -6
- package/src/util/cli.ts +1 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
import type { Image } from "./image.ts";
|
|
4
|
+
import type { RemoteImage } from "./remote-image.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Port mapping configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface PortMapping {
|
|
9
|
+
/**
|
|
10
|
+
* External port on the host
|
|
11
|
+
*/
|
|
12
|
+
external: number | string;
|
|
13
|
+
/**
|
|
14
|
+
* Internal port inside the container
|
|
15
|
+
*/
|
|
16
|
+
internal: number | string;
|
|
17
|
+
/**
|
|
18
|
+
* Protocol (tcp or udp)
|
|
19
|
+
*/
|
|
20
|
+
protocol?: "tcp" | "udp";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Volume mapping configuration
|
|
24
|
+
*/
|
|
25
|
+
export interface VolumeMapping {
|
|
26
|
+
/**
|
|
27
|
+
* Host path
|
|
28
|
+
*/
|
|
29
|
+
hostPath: string;
|
|
30
|
+
/**
|
|
31
|
+
* Container path
|
|
32
|
+
*/
|
|
33
|
+
containerPath: string;
|
|
34
|
+
/**
|
|
35
|
+
* Read-only flag
|
|
36
|
+
*/
|
|
37
|
+
readOnly?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Network mapping configuration
|
|
41
|
+
*/
|
|
42
|
+
export interface NetworkMapping {
|
|
43
|
+
/**
|
|
44
|
+
* Network name or ID
|
|
45
|
+
*/
|
|
46
|
+
name: string;
|
|
47
|
+
/**
|
|
48
|
+
* Aliases for the container in the network
|
|
49
|
+
*/
|
|
50
|
+
aliases?: string[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Properties for creating a Docker container
|
|
54
|
+
*/
|
|
55
|
+
export interface ContainerProps {
|
|
56
|
+
/**
|
|
57
|
+
* Image to use for the container
|
|
58
|
+
* Can be an Alchemy Image or RemoteImage resource or a string image reference
|
|
59
|
+
*/
|
|
60
|
+
image: Image | RemoteImage | string;
|
|
61
|
+
/**
|
|
62
|
+
* Container name
|
|
63
|
+
*/
|
|
64
|
+
name?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Command to run in the container
|
|
67
|
+
*/
|
|
68
|
+
command?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Environment variables
|
|
71
|
+
*/
|
|
72
|
+
environment?: Record<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* Port mappings
|
|
75
|
+
*/
|
|
76
|
+
ports?: PortMapping[];
|
|
77
|
+
/**
|
|
78
|
+
* Volume mappings
|
|
79
|
+
*/
|
|
80
|
+
volumes?: VolumeMapping[];
|
|
81
|
+
/**
|
|
82
|
+
* Restart policy
|
|
83
|
+
*/
|
|
84
|
+
restart?: "no" | "always" | "on-failure" | "unless-stopped";
|
|
85
|
+
/**
|
|
86
|
+
* Networks to connect to
|
|
87
|
+
*/
|
|
88
|
+
networks?: NetworkMapping[];
|
|
89
|
+
/**
|
|
90
|
+
* Whether to remove the container when it exits
|
|
91
|
+
*/
|
|
92
|
+
removeOnExit?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Start the container after creation
|
|
95
|
+
*/
|
|
96
|
+
start?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Docker Container resource
|
|
100
|
+
*/
|
|
101
|
+
export interface Container extends Resource<"docker::Container">, ContainerProps {
|
|
102
|
+
/**
|
|
103
|
+
* Container ID
|
|
104
|
+
*/
|
|
105
|
+
id: string;
|
|
106
|
+
/**
|
|
107
|
+
* Container state
|
|
108
|
+
*/
|
|
109
|
+
state?: "created" | "running" | "paused" | "stopped" | "exited";
|
|
110
|
+
/**
|
|
111
|
+
* Time when the container was created
|
|
112
|
+
*/
|
|
113
|
+
createdAt: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create and manage a Docker Container
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // Create a simple Nginx container
|
|
120
|
+
* const webContainer = await Container("web", {
|
|
121
|
+
* image: "nginx:latest",
|
|
122
|
+
* ports: [
|
|
123
|
+
* { external: 8080, internal: 80 }
|
|
124
|
+
* ],
|
|
125
|
+
* start: true
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Create a container with environment variables and volume mounts
|
|
130
|
+
* const appContainer = await Container("app", {
|
|
131
|
+
* image: customImage, // Using an Alchemy RemoteImage resource
|
|
132
|
+
* environment: {
|
|
133
|
+
* NODE_ENV: "production",
|
|
134
|
+
* API_KEY: "secret-key"
|
|
135
|
+
* },
|
|
136
|
+
* volumes: [
|
|
137
|
+
* { hostPath: "./data", containerPath: "/app/data" }
|
|
138
|
+
* ],
|
|
139
|
+
* ports: [
|
|
140
|
+
* { external: 3000, internal: 3000 }
|
|
141
|
+
* ],
|
|
142
|
+
* restart: "always",
|
|
143
|
+
* start: true
|
|
144
|
+
* });
|
|
145
|
+
*/
|
|
146
|
+
export declare const Container: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Container>, id: string, props: ContainerProps) => Promise<Container>);
|
|
147
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/docker/container.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;IAE5B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SACf,SAAQ,QAAQ,CAAC,mBAAmB,CAAC,EACnC,cAAc;IAChB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IAEhE;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,SAAS,yFAGZ,OAAO,CAAC,SAAS,CAAC,MACpB,MAAM,SACH,cAAc,KACpB,OAAO,CAAC,SAAS,CAAC,CA0FtB,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Resource } from "../resource.js";
|
|
2
|
+
import { DockerApi } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create and manage a Docker Container
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Create a simple Nginx container
|
|
8
|
+
* const webContainer = await Container("web", {
|
|
9
|
+
* image: "nginx:latest",
|
|
10
|
+
* ports: [
|
|
11
|
+
* { external: 8080, internal: 80 }
|
|
12
|
+
* ],
|
|
13
|
+
* start: true
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Create a container with environment variables and volume mounts
|
|
18
|
+
* const appContainer = await Container("app", {
|
|
19
|
+
* image: customImage, // Using an Alchemy RemoteImage resource
|
|
20
|
+
* environment: {
|
|
21
|
+
* NODE_ENV: "production",
|
|
22
|
+
* API_KEY: "secret-key"
|
|
23
|
+
* },
|
|
24
|
+
* volumes: [
|
|
25
|
+
* { hostPath: "./data", containerPath: "/app/data" }
|
|
26
|
+
* ],
|
|
27
|
+
* ports: [
|
|
28
|
+
* { external: 3000, internal: 3000 }
|
|
29
|
+
* ],
|
|
30
|
+
* restart: "always",
|
|
31
|
+
* start: true
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export const Container = Resource("docker::Container", async function (id, props) {
|
|
35
|
+
// Initialize Docker API client
|
|
36
|
+
const api = new DockerApi();
|
|
37
|
+
// Get image reference
|
|
38
|
+
const imageRef = typeof props.image === "string" ? props.image : props.image.imageRef;
|
|
39
|
+
// Use provided name or generate one based on resource ID
|
|
40
|
+
const containerName = props.name || `alchemy-${id.replace(/[^a-zA-Z0-9_.-]/g, "-")}`;
|
|
41
|
+
// Handle delete phase
|
|
42
|
+
if (this.phase === "delete") {
|
|
43
|
+
if (this.output?.id) {
|
|
44
|
+
// Stop container if running
|
|
45
|
+
await api.stopContainer(this.output.id);
|
|
46
|
+
// Remove container
|
|
47
|
+
await api.removeContainer(this.output.id, true);
|
|
48
|
+
}
|
|
49
|
+
// Return destroyed state
|
|
50
|
+
return this.destroy();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
let containerState = "created";
|
|
54
|
+
if (this.phase === "update") {
|
|
55
|
+
// Check if container already exists (for update)
|
|
56
|
+
const containerExists = await api.containerExists(containerName);
|
|
57
|
+
if (containerExists) {
|
|
58
|
+
// Remove existing container for update
|
|
59
|
+
await api.removeContainer(containerName, true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Prepare port mappings
|
|
63
|
+
const portMappings = {};
|
|
64
|
+
if (props.ports) {
|
|
65
|
+
for (const port of props.ports) {
|
|
66
|
+
const protocol = port.protocol || "tcp";
|
|
67
|
+
portMappings[`${port.external}`] = `${port.internal}/${protocol}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Prepare volume mappings
|
|
71
|
+
const volumeMappings = {};
|
|
72
|
+
if (props.volumes) {
|
|
73
|
+
for (const volume of props.volumes) {
|
|
74
|
+
const readOnlyFlag = volume.readOnly ? ":ro" : "";
|
|
75
|
+
volumeMappings[volume.hostPath] =
|
|
76
|
+
`${volume.containerPath}${readOnlyFlag}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Create new container
|
|
80
|
+
const containerId = await api.createContainer(imageRef, containerName, {
|
|
81
|
+
ports: portMappings,
|
|
82
|
+
env: props.environment,
|
|
83
|
+
volumes: volumeMappings,
|
|
84
|
+
cmd: props.command,
|
|
85
|
+
});
|
|
86
|
+
// Connect to networks if specified
|
|
87
|
+
if (props.networks) {
|
|
88
|
+
for (const network of props.networks) {
|
|
89
|
+
const networkId = typeof network === "string" ? network : network.name;
|
|
90
|
+
await api.connectNetwork(containerId, networkId, {
|
|
91
|
+
aliases: network.aliases,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Start container if requested
|
|
96
|
+
if (props.start) {
|
|
97
|
+
await api.startContainer(containerId);
|
|
98
|
+
containerState = "running";
|
|
99
|
+
}
|
|
100
|
+
// Return the resource using this() to construct output
|
|
101
|
+
return this({
|
|
102
|
+
...props,
|
|
103
|
+
id: containerId,
|
|
104
|
+
state: containerState,
|
|
105
|
+
createdAt: Date.now(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/docker/container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAyIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAC/B,mBAAmB,EACnB,KAAK,WAEH,EAAU,EACV,KAAqB;IAErB,+BAA+B;IAC/B,MAAM,GAAG,GAAG,IAAI,SAAS,EAA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AAc,CAAC,WAAW,CAAC,CAAC;YACtC,cAAc,GAAG,SAAS,CAAC;QAC7B,CAAC;QAED,uDAAuD;QACvD,OAAO,IAAI,CAAC;YACV,GAAG,KAAK;YACR,EAAE,EAAE,WAAW;YACf,KAAK,EAAE,cAAc;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Options for building a Docker image
|
|
5
|
+
*/
|
|
6
|
+
export interface DockerBuildOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Path to the build context directory
|
|
9
|
+
*/
|
|
10
|
+
context: string;
|
|
11
|
+
/**
|
|
12
|
+
* Path to the Dockerfile, relative to context
|
|
13
|
+
*/
|
|
14
|
+
dockerfile?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Target build platform (e.g., linux/amd64)
|
|
17
|
+
*/
|
|
18
|
+
platform?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Build arguments as key-value pairs
|
|
21
|
+
*/
|
|
22
|
+
buildArgs?: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Target build stage in multi-stage builds
|
|
25
|
+
*/
|
|
26
|
+
target?: string;
|
|
27
|
+
/**
|
|
28
|
+
* List of images to use for cache
|
|
29
|
+
*/
|
|
30
|
+
cacheFrom?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Properties for creating a Docker image
|
|
34
|
+
*/
|
|
35
|
+
export interface ImageProps {
|
|
36
|
+
/**
|
|
37
|
+
* Repository name for the image (e.g., "username/image")
|
|
38
|
+
*/
|
|
39
|
+
name: string;
|
|
40
|
+
/**
|
|
41
|
+
* Tag for the image (e.g., "latest")
|
|
42
|
+
*/
|
|
43
|
+
tag?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Build configuration
|
|
46
|
+
*/
|
|
47
|
+
build: DockerBuildOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to skip pushing the image to registry
|
|
50
|
+
*/
|
|
51
|
+
skipPush?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Docker Image resource
|
|
55
|
+
*/
|
|
56
|
+
export interface Image extends Resource<"docker::Image">, ImageProps {
|
|
57
|
+
/**
|
|
58
|
+
* Full image reference (name:tag)
|
|
59
|
+
*/
|
|
60
|
+
imageRef: string;
|
|
61
|
+
/**
|
|
62
|
+
* Image ID
|
|
63
|
+
*/
|
|
64
|
+
imageId?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Repository digest if pushed
|
|
67
|
+
*/
|
|
68
|
+
repoDigest?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Time when the image was built
|
|
71
|
+
*/
|
|
72
|
+
builtAt: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build and manage a Docker image from a Dockerfile
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Build a Docker image from a Dockerfile
|
|
79
|
+
* const appImage = await Image("app-image", {
|
|
80
|
+
* name: "myapp",
|
|
81
|
+
* tag: "latest",
|
|
82
|
+
* build: {
|
|
83
|
+
* context: "./app",
|
|
84
|
+
* dockerfile: "Dockerfile",
|
|
85
|
+
* buildArgs: {
|
|
86
|
+
* NODE_ENV: "production"
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* });
|
|
90
|
+
*/
|
|
91
|
+
export declare const Image: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Image>, _id: string, props: ImageProps) => Promise<Image>);
|
|
92
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/docker/image.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,KAAM,SAAQ,QAAQ,CAAC,eAAe,CAAC,EAAE,UAAU;IAClE;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,KAAK,yFAGR,OAAO,CAAC,KAAK,CAAC,OACf,MAAM,SACJ,UAAU,KAChB,OAAO,CAAC,KAAK,CAAC,CAqFlB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Resource } from "../resource.js";
|
|
4
|
+
import { DockerApi } from "./api.js";
|
|
5
|
+
/**
|
|
6
|
+
* Build and manage a Docker image from a Dockerfile
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Build a Docker image from a Dockerfile
|
|
10
|
+
* const appImage = await Image("app-image", {
|
|
11
|
+
* name: "myapp",
|
|
12
|
+
* tag: "latest",
|
|
13
|
+
* build: {
|
|
14
|
+
* context: "./app",
|
|
15
|
+
* dockerfile: "Dockerfile",
|
|
16
|
+
* buildArgs: {
|
|
17
|
+
* NODE_ENV: "production"
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export const Image = Resource("docker::Image", async function (_id, props) {
|
|
23
|
+
// Initialize Docker API client
|
|
24
|
+
const api = new DockerApi();
|
|
25
|
+
if (this.phase === "delete") {
|
|
26
|
+
// No action needed for delete as Docker images aren't automatically removed
|
|
27
|
+
// This is intentional as other resources might depend on the same image
|
|
28
|
+
return this.destroy();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Normalize properties
|
|
32
|
+
const tag = props.tag || "latest";
|
|
33
|
+
const imageRef = `${props.name}:${tag}`;
|
|
34
|
+
// Validate build context
|
|
35
|
+
const { context } = props.build;
|
|
36
|
+
await fs.access(context);
|
|
37
|
+
// Determine Dockerfile path
|
|
38
|
+
const dockerfile = props.build.dockerfile || "Dockerfile";
|
|
39
|
+
const dockerfilePath = path.join(context, dockerfile);
|
|
40
|
+
await fs.access(dockerfilePath);
|
|
41
|
+
// Prepare build options
|
|
42
|
+
const buildOptions = props.build.buildArgs || {};
|
|
43
|
+
// Add platform if specified
|
|
44
|
+
let buildArgs = ["build", "-t", imageRef];
|
|
45
|
+
if (props.build.platform) {
|
|
46
|
+
buildArgs.push("--platform", props.build.platform);
|
|
47
|
+
}
|
|
48
|
+
// Add target if specified
|
|
49
|
+
if (props.build.target) {
|
|
50
|
+
buildArgs.push("--target", props.build.target);
|
|
51
|
+
}
|
|
52
|
+
// Add cache sources if specified
|
|
53
|
+
if (props.build.cacheFrom && props.build.cacheFrom.length > 0) {
|
|
54
|
+
for (const cacheSource of props.build.cacheFrom) {
|
|
55
|
+
buildArgs.push("--cache-from", cacheSource);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Add build arguments
|
|
59
|
+
for (const [key, value] of Object.entries(buildOptions)) {
|
|
60
|
+
buildArgs.push("--build-arg", `${key}="${value}"`);
|
|
61
|
+
}
|
|
62
|
+
// Add dockerfile if not the default
|
|
63
|
+
if (props.build.dockerfile && props.build.dockerfile !== "Dockerfile") {
|
|
64
|
+
buildArgs.push("-f", props.build.dockerfile);
|
|
65
|
+
}
|
|
66
|
+
// Add context path
|
|
67
|
+
buildArgs.push(props.build.context);
|
|
68
|
+
// Execute build command
|
|
69
|
+
console.log(`Building Docker image: ${imageRef}`);
|
|
70
|
+
const { stdout } = await api.exec(buildArgs);
|
|
71
|
+
// Extract image ID from build output if available
|
|
72
|
+
const imageIdMatch = /Successfully built ([a-f0-9]+)/.exec(stdout);
|
|
73
|
+
const imageId = imageIdMatch ? imageIdMatch[1] : undefined;
|
|
74
|
+
console.log(`Successfully built Docker image: ${imageRef}`);
|
|
75
|
+
// Handle push if required
|
|
76
|
+
let repoDigest;
|
|
77
|
+
if (!props.skipPush) {
|
|
78
|
+
console.log(`Pushing Docker image: ${imageRef}`);
|
|
79
|
+
// TODO: Implement push once API supports it
|
|
80
|
+
console.warn("Image pushing is not yet implemented");
|
|
81
|
+
}
|
|
82
|
+
// Return the resource using this() to construct output
|
|
83
|
+
return this({
|
|
84
|
+
...props,
|
|
85
|
+
imageRef,
|
|
86
|
+
imageId,
|
|
87
|
+
repoDigest,
|
|
88
|
+
builtAt: Date.now(),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/docker/image.ts"],"names":[],"mappings":"AAAA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C,CAAC;QAE7C,kDAAkD;QAClD,MAAM,YAAY,GAAG,gCAAgC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnE,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE3D,OAAO,CAAC,GAAG,CAAC,oCAAoC,QAAQ,EAAE,CAAC,CAAC;QAE5D,0BAA0B;QAC1B,IAAI,UAA8B,CAAC;QACnC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;YACjD,4CAA4C;YAC5C,OAAO,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACvD,CAAC;QAED,uDAAuD;QACvD,OAAO,IAAI,CAAC;YACV,GAAG,KAAK;YACR,QAAQ;YACR,OAAO;YACP,UAAU;YACV,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;SACpB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Properties for creating a Docker network
|
|
5
|
+
*/
|
|
6
|
+
export interface NetworkProps {
|
|
7
|
+
/**
|
|
8
|
+
* Network name
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Network driver to use
|
|
13
|
+
* @default "bridge"
|
|
14
|
+
*/
|
|
15
|
+
driver?: "bridge" | "host" | "none" | "overlay" | "macvlan" | (string & {});
|
|
16
|
+
/**
|
|
17
|
+
* Enable IPv6 on the network
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
enableIPv6?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Network-scoped alias for containers
|
|
23
|
+
*/
|
|
24
|
+
labels?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Docker Network resource
|
|
28
|
+
*/
|
|
29
|
+
export interface Network extends Resource<"docker::Network">, NetworkProps {
|
|
30
|
+
/**
|
|
31
|
+
* Network ID
|
|
32
|
+
*/
|
|
33
|
+
id: string;
|
|
34
|
+
/**
|
|
35
|
+
* Time when the network was created
|
|
36
|
+
*/
|
|
37
|
+
createdAt: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create and manage a Docker Network
|
|
41
|
+
*
|
|
42
|
+
* @see https://docs.docker.com/engine/network/
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Create a simple bridge network
|
|
46
|
+
* const appNetwork = await Network("app-network", {
|
|
47
|
+
* name: "app-network"
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Create a custom network with driver
|
|
52
|
+
* const overlayNetwork = await Network("overlay-network", {
|
|
53
|
+
* name: "overlay-network",
|
|
54
|
+
* driver: "overlay",
|
|
55
|
+
* enableIPv6: true,
|
|
56
|
+
* labels: {
|
|
57
|
+
* "com.example.description": "Network for application services"
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
*/
|
|
61
|
+
export declare const Network: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Network>, _id: string, props: NetworkProps) => Promise<Network>);
|
|
62
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/docker/network.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAE5E;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,OAAQ,SAAQ,QAAQ,CAAC,iBAAiB,CAAC,EAAE,YAAY;IACxE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,OAAO,yFAGV,OAAO,CAAC,OAAO,CAAC,OACjB,MAAM,SACJ,YAAY,KAClB,OAAO,CAAC,OAAO,CAAC,CA0BpB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Resource } from "../resource.js";
|
|
2
|
+
import { DockerApi } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create and manage a Docker Network
|
|
5
|
+
*
|
|
6
|
+
* @see https://docs.docker.com/engine/network/
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Create a simple bridge network
|
|
10
|
+
* const appNetwork = await Network("app-network", {
|
|
11
|
+
* name: "app-network"
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Create a custom network with driver
|
|
16
|
+
* const overlayNetwork = await Network("overlay-network", {
|
|
17
|
+
* name: "overlay-network",
|
|
18
|
+
* driver: "overlay",
|
|
19
|
+
* enableIPv6: true,
|
|
20
|
+
* labels: {
|
|
21
|
+
* "com.example.description": "Network for application services"
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
export const Network = Resource("docker::Network", async function (_id, props) {
|
|
26
|
+
// Initialize Docker API client
|
|
27
|
+
const api = new DockerApi();
|
|
28
|
+
// Handle delete phase
|
|
29
|
+
if (this.phase === "delete") {
|
|
30
|
+
if (this.output?.id) {
|
|
31
|
+
// Remove network
|
|
32
|
+
await api.removeNetwork(this.output.id);
|
|
33
|
+
}
|
|
34
|
+
// Return destroyed state
|
|
35
|
+
return this.destroy();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Create the network
|
|
39
|
+
props.driver = props.driver || "bridge";
|
|
40
|
+
const networkId = await api.createNetwork(props.name, props.driver);
|
|
41
|
+
// Return the resource using this() to construct output
|
|
42
|
+
return this({
|
|
43
|
+
...props,
|
|
44
|
+
id: networkId,
|
|
45
|
+
createdAt: Date.now(),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/docker/network.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AA4CrC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAC7B,iBAAiB,EACjB,KAAK,WAEH,GAAW,EACX,KAAmB;IAEnB,+BAA+B;IAC/B,MAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC;IAE5B,sBAAsB;IACtB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;YACpB,iBAAiB;YACjB,MAAM,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QAED,yBAAyB;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,qBAAqB;QACrB,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC;QACxC,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAEpE,uDAAuD;QACvD,OAAO,IAAI,CAAC;YACV,GAAG,KAAK;YACR,EAAE,EAAE,SAAS;YACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Properties for creating a Docker image
|
|
5
|
+
*/
|
|
6
|
+
export interface RemoteImageProps {
|
|
7
|
+
/**
|
|
8
|
+
* Docker image name (e.g., "nginx")
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Tag for the image (e.g., "latest" or "1.19-alpine")
|
|
13
|
+
*/
|
|
14
|
+
tag?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Always attempt to pull the image, even if it exists locally
|
|
17
|
+
*/
|
|
18
|
+
alwaysPull?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Docker Remote Image resource
|
|
22
|
+
*/
|
|
23
|
+
export interface RemoteImage extends Resource<"docker::RemoteImage">, RemoteImageProps {
|
|
24
|
+
/**
|
|
25
|
+
* Full image reference (name:tag)
|
|
26
|
+
*/
|
|
27
|
+
imageRef: string;
|
|
28
|
+
/**
|
|
29
|
+
* Time when the image was created or pulled
|
|
30
|
+
*/
|
|
31
|
+
createdAt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create or reference a Docker Remote Image
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Pull the nginx image
|
|
38
|
+
* const nginxImage = await RemoteImage("nginx", {
|
|
39
|
+
* name: "nginx",
|
|
40
|
+
* tag: "latest"
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export declare const RemoteImage: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<RemoteImage>, _id: string, props: RemoteImageProps) => Promise<RemoteImage>);
|
|
45
|
+
//# sourceMappingURL=remote-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-image.d.ts","sourceRoot":"","sources":["../../src/docker/remote-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WACf,SAAQ,QAAQ,CAAC,qBAAqB,CAAC,EACrC,gBAAgB;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,yFAGd,OAAO,CAAC,WAAW,CAAC,OACrB,MAAM,SACJ,gBAAgB,KACtB,OAAO,CAAC,WAAW,CAAC,CAwBxB,CAAC"}
|