Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- name: Install
run: |
npm install
- name: Check
run: |
npm run check
- name: Test
run: |
npm test
- name: Format
run: |
prettier --check
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
package.json
package-lock.json
makefile
swagger.yaml
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"build": "npm run generate && tsup",
"test": "vitest run",
"lint": "oxlint --type-aware",
"format": "prettier --write ."
"format": "prettier --write .",
"check": "prettier --check ."
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.23.4",
Expand Down
58 changes: 30 additions & 28 deletions src/docker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import * as os from 'os';
import * as models from './models/index.js';
import { HTTPClient } from './http.js';
import { Filter } from './filter.js';
import { Writable } from 'stream';
import { FileInfo } from './models/FileInfo.js';

export class Credentials {
username: string;
Expand Down Expand Up @@ -242,9 +240,11 @@ export class DockerClient {
) {
await this.api.sendHTTPRequest('GET', '/events', {
params: options,
timeout: -1,
callback: (chunk: string) =>
callback(JSON.parse(chunk) as models.EventMessage),
callback: (data: string) => {
data.split('\n').forEach((line) => {
callback(JSON.parse(line) as models.EventMessage);
});
},
});
}

Expand Down Expand Up @@ -345,16 +345,10 @@ export class DockerClient {
stderr?: boolean;
},
): Promise<void> {
return this.api.post(
`/containers/${id}/attach`,
options,
undefined,
undefined,
{
Connection: 'Upgrade',
Upgrade: 'tcp',
},
);
return this.api.post(`/containers/${id}/attach`, options, undefined, {
Connection: 'Upgrade',
Upgrade: 'tcp',
});
}

/**
Expand Down Expand Up @@ -684,7 +678,6 @@ export class DockerClient {
`/containers/${id}/wait`,
undefined,
options,
-1,
);
}

Expand Down Expand Up @@ -885,17 +878,20 @@ export class DockerClient {
* @param platform Platform in the format os[/arch[/variant]]. When used in combination with the 'fromImage' option, the daemon checks if the given image is present in the local image cache with the given OS and Architecture, and otherwise attempts to pull the image. If the option is not set, the host\&#39;s native OS and Architecture are used. If the given image does not exist in the local image cache, the daemon attempts to pull the image with the host\&#39;s native OS and Architecture. If the given image does exists in the local image cache, but its OS or architecture does not match, a warning is produced. When used with the 'fromSrc' option to import an image from an archive, this option sets the platform information for the imported image. If the option is not set, the host\&#39;s native OS and Architecture are used for the imported image.
* @param inputImage Image content if the value '-' has been specified in fromSrc query parameter
*/
public async imageCreate(options?: {
fromImage?: string;
fromSrc?: string;
repo?: string;
tag?: string;
message?: string;
credentials?: Credentials | IdentityToken;
changes?: Array<string>;
platform?: string;
inputImage?: string;
}): Promise<void> {
public async imageCreate(
callback: (event: any) => void,
options?: {
fromImage?: string;
fromSrc?: string;
repo?: string;
tag?: string;
message?: string;
credentials?: Credentials | IdentityToken;
changes?: Array<string>;
platform?: string;
inputImage?: string;
},
): Promise<void> {
const headers: Record<string, string> = {};

if (options?.credentials) {
Expand All @@ -917,8 +913,14 @@ export class DockerClient {
inputImage: options?.inputImage,
},
undefined,
undefined,
headers,
(data: string) => {
data.split('\n').forEach((line) => {
if (line) {
callback(JSON.parse(line));
}
});
},
);
}

Expand Down
14 changes: 12 additions & 2 deletions src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ test('container lifecycle should work end-to-end', async () => {
let containerId: string | undefined;

try {
await client.imageCreate(
(event) => {
console.log(event);
},
{
fromImage: 'docker.io/library/nginx',
tag: 'latest',
},
);

console.log(' Creating nginx container...');
// Create container with label
const createResponse = await client.containerCreate(
{
Image: 'nginx:latest',
Image: 'docker.io/library/nginx',
Labels: {
'test.type': 'e2e',
},
Expand Down Expand Up @@ -173,7 +183,7 @@ test('container lifecycle should work end-to-end', async () => {
}
}
}
});
}, 30000);

test('network lifecycle should work end-to-end', async () => {
const client = await DockerClient.fromDockerConfig();
Expand Down
Loading