Skip to content

Commit 3fb8bbd

Browse files
authored
Merge pull request #90 from rumpl/feat-move-docs
Move the documentation a bit
2 parents bcea5da + c1ce945 commit 3fb8bbd

File tree

5 files changed

+223
-178
lines changed

5 files changed

+223
-178
lines changed

docs/dev/api/backend.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
## Communication with the backend
2+
3+
The `window.ddClient.backend` object can be used to communicate with the backend
4+
defined in the [vm section](../../extensions/METADATA.md#vm-section) in the
5+
extensions metadata. The client is already connected to the backend.
6+
7+
It implements the following interface
8+
9+
```typescript
10+
interface Backend {
11+
get(url: string): Promise<unknown>;
12+
post(url: string, data: any): Promise<unknown>;
13+
put(url: string, data: any): Promise<unknown>;
14+
patch(url: string, data: any): Promise<unknown>;
15+
delete(url: string): Promise<unknown>;
16+
head(url: string): Promise<unknown>;
17+
request(config: RequestConfig): Promise<unknown>;
18+
execInContainer(container: string, cmd: string): Promise<execResult>;
19+
execInVMExtension(cmd: string): Promise<execResult>;
20+
}
21+
22+
interface RequestConfig {
23+
url: string;
24+
method: string;
25+
headers: Record<string, string>;
26+
data: any;
27+
}
28+
29+
interface nodeExecResult {
30+
readonly cmd?: string;
31+
readonly killed?: boolean;
32+
readonly signal?: string;
33+
readonly code?: number;
34+
readonly stdout: string;
35+
readonly stderr: string;
36+
}
37+
38+
interface execResult extends nodeExecResult {
39+
lines(): string[];
40+
parseJsonLines(): any[];
41+
parseJsonObject(): any;
42+
}
43+
```
44+
45+
Example usages:
46+
47+
```typescript
48+
window.ddClient.backend
49+
.get("/some/service")
50+
.then((value: any) => console.log(value));
51+
52+
window.ddClient.backend
53+
.post("/some/service", { ... })
54+
.then((value: any) => console.log(value));
55+
56+
window.ddClient.backend
57+
.put("/some/service", { ... })
58+
.then((value: any) => console.log(value));
59+
60+
window.ddClient.backend
61+
.patch("/some/service", { ... })
62+
.then((value: any) => console.log(value));
63+
64+
window.ddClient.backend
65+
.delete("/some/service")
66+
.then((value: any) => console.log(value));
67+
68+
window.ddClient.backend
69+
.head("/some/service")
70+
.then((value: any) => console.log(value));
71+
72+
window.ddClient.backend
73+
.request({ url: "/url", method: "GET", headers: { 'header-key': 'header-value' }, data: { ... }})
74+
.then((value: any) => console.log(value));
75+
```
76+
77+
## Running a command in the backend container
78+
79+
If your extensions ships with additional binaries that should be run inside the
80+
backend container you can use the `execInVMExtension` function
81+
82+
```typescript
83+
const output = await window.ddClient.backend.execInVMExtension(
84+
`cliShippedInTheVm xxx`
85+
);
86+
console.log(output);
87+
```
88+
89+
## Invoking an extension binary
90+
91+
You can run binaries defined in the [host section](../../extensions/METADATA.md#host-section)
92+
in the exension metadata.
93+
94+
```typescript
95+
window.ddClient.execHostCmd(`cliShippedOnHost xxx`).then((cmdResult: any) => {
96+
console.log(cmdResult);
97+
});
98+
```
99+
100+
Invoking an extension binary on your host and getting the output stream:
101+
102+
```typescript
103+
window.ddClient.spawnHostCmd(
104+
`cliShippedOnHost`,
105+
[`arg1`, `arg2`],
106+
(data: any, err: any) => {
107+
console.log(data.stdout, data.stderr);
108+
// Once the command exits we get the status code
109+
if (data.code) {
110+
console.log(data.code);
111+
}
112+
}
113+
);
114+
```

docs/dev/api/dashboard.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## User notifications
2+
3+
Toasts provide a brief notification to the user. They appear temporarily and
4+
shouldn't interrupt the user experience, they don't require user input to disappear.
5+
6+
```typescript
7+
window.ddClient.toastError("Something went wrong");
8+
```
9+
10+
## Opening a URL
11+
12+
This function opens an external URL with the system default browser.
13+
14+
```typescript
15+
window.ddClient.openExternal("https://docker.com");
16+
```
17+
18+
_Note:_ the URL must have the protocol `http` or `https`.
19+
20+
## Navigation to Dashboard routes
21+
22+
From your extension, you can navigate to various tabs in Docker Desktop Dashboard.
23+
24+
See details [here](dashboard-routes-navigation.md)

docs/dev/api/docker.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Docker objects
2+
3+
### Listing containers
4+
5+
```typescript
6+
const containers = await window.ddClient.listContainers();
7+
```
8+
9+
This method takes an optional argument in the form of an object:
10+
11+
```json
12+
{
13+
"all": true,
14+
"limit": 10,
15+
"size": true,
16+
"filters": "..."
17+
}
18+
```
19+
20+
For more information about the different properties see [the Docker API endpoint documentation](https://docs.docker.com/engine/api/v1.37/#operation/ContainerList)
21+
22+
### Listing images
23+
24+
```typescript
25+
const images = await window.ddClient.listImages();
26+
```
27+
28+
This method takes an optional argument in the form of an object:
29+
30+
```json
31+
{
32+
"all": true,
33+
"filters": "...",
34+
"digests": true
35+
}
36+
```
37+
38+
For more information about the different properties see [the Docker API endpoint documentation](https://docs.docker.com/engine/api/v1.37/#tag/Image)
39+
40+
## Docker commands
41+
42+
You can also directly execute the `docker` binary.
43+
44+
```typescript
45+
const output = await window.ddClient.execDockerCmd("info", "--format", '"{{ json . }}"');
46+
```
47+
48+
The result will contain both the standard output and the standard error of the
49+
executed command
50+
51+
```json
52+
{
53+
"stderr": "...",
54+
"stdout": "..."
55+
}
56+
```
57+
58+
In this example the docker command output is a json output.
59+
60+
For convenience, the command result object also has methods to easily parse it:
61+
62+
- `output.lines(): string[]` split output lines
63+
- `output.parseJsonObject(): any` parse a well formed json output
64+
- `output.parseJsonLines(): any[]` parse each output line as a json object
65+
66+
If the output of the command is too long or you need to get the output as a
67+
stream you can use the `spawnDockerCmd` function:
68+
69+
```typescript
70+
window.ddClient.spawnDockerCmd("logs", ["-f", "..."], (data, error) => {
71+
console.log(data.stdout);
72+
});
73+
```

0 commit comments

Comments
 (0)