Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
606c82dafa | |||
9fc4afe4b8 | |||
90689c2645 | |||
4a1d649e5e | |||
66bd36dc4f | |||
349d711cc5 | |||
c74a4bcd5b | |||
ff835c4160 | |||
05eceeb056 | |||
de55beda08 | |||
9aa2b0c7be | |||
a283bbfba0 |
33
changelog.md
33
changelog.md
@ -1,5 +1,38 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-12-23 - 1.3.0 - feat(core)
|
||||||
|
Initial release of Docker client with TypeScript support
|
||||||
|
|
||||||
|
- Provides easy communication with Docker's remote API from Node.js
|
||||||
|
- Includes implementations for managing Docker services, networks, secrets, containers, and images
|
||||||
|
|
||||||
|
## 2024-12-23 - 1.2.8 - fix(core)
|
||||||
|
Improved the image creation process from tar stream in DockerImage class.
|
||||||
|
|
||||||
|
- Enhanced `DockerImage.createFromTarStream` method to handle streamed response and parse imported image details.
|
||||||
|
- Fixed the dependency version for `@push.rocks/smartarchive` in package.json.
|
||||||
|
|
||||||
|
## 2024-10-13 - 1.2.7 - fix(core)
|
||||||
|
Prepare patch release with minor fixes and improvements
|
||||||
|
|
||||||
|
|
||||||
|
## 2024-10-13 - 1.2.6 - fix(core)
|
||||||
|
Minor refactoring and code quality improvements.
|
||||||
|
|
||||||
|
|
||||||
|
## 2024-10-13 - 1.2.5 - fix(dependencies)
|
||||||
|
Update dependencies for stability improvements
|
||||||
|
|
||||||
|
- Updated @push.rocks/smartstream to version ^3.0.46
|
||||||
|
- Updated @push.rocks/tapbundle to version ^5.3.0
|
||||||
|
- Updated @types/node to version 22.7.5
|
||||||
|
|
||||||
|
## 2024-10-13 - 1.2.4 - fix(core)
|
||||||
|
Refactored DockerImageStore constructor to remove DockerHost dependency
|
||||||
|
|
||||||
|
- Adjusted DockerImageStore constructor to remove dependency on DockerHost
|
||||||
|
- Updated ts/classes.host.ts to align with DockerImageStore's new constructor signature
|
||||||
|
|
||||||
## 2024-08-21 - 1.2.3 - fix(dependencies)
|
## 2024-08-21 - 1.2.3 - fix(dependencies)
|
||||||
Update dependencies to the latest versions and fix image export test
|
Update dependencies to the latest versions and fix image export test
|
||||||
|
|
||||||
|
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/docker",
|
"name": "@apiclient.xyz/docker",
|
||||||
"version": "1.2.3",
|
"version": "1.3.0",
|
||||||
"description": "Provides easy communication with Docker remote API from Node.js, with TypeScript support.",
|
"description": "Provides easy communication with Docker remote API from Node.js, with TypeScript support.",
|
||||||
"private": false,
|
"private": false,
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -34,7 +34,7 @@
|
|||||||
"homepage": "https://gitlab.com/mojoio/docker#readme",
|
"homepage": "https://gitlab.com/mojoio/docker#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/lik": "^6.0.15",
|
"@push.rocks/lik": "^6.0.15",
|
||||||
"@push.rocks/smartarchive": "^4.0.37",
|
"@push.rocks/smartarchive": "^4.0.39",
|
||||||
"@push.rocks/smartbucket": "^3.0.22",
|
"@push.rocks/smartbucket": "^3.0.22",
|
||||||
"@push.rocks/smartfile": "^11.0.21",
|
"@push.rocks/smartfile": "^11.0.21",
|
||||||
"@push.rocks/smartjson": "^5.0.20",
|
"@push.rocks/smartjson": "^5.0.20",
|
||||||
@ -43,7 +43,7 @@
|
|||||||
"@push.rocks/smartpath": "^5.0.18",
|
"@push.rocks/smartpath": "^5.0.18",
|
||||||
"@push.rocks/smartpromise": "^4.0.4",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@push.rocks/smartrequest": "^2.0.22",
|
"@push.rocks/smartrequest": "^2.0.22",
|
||||||
"@push.rocks/smartstream": "^3.0.44",
|
"@push.rocks/smartstream": "^3.0.46",
|
||||||
"@push.rocks/smartstring": "^4.0.15",
|
"@push.rocks/smartstring": "^4.0.15",
|
||||||
"@push.rocks/smartunique": "^3.0.9",
|
"@push.rocks/smartunique": "^3.0.9",
|
||||||
"@push.rocks/smartversion": "^3.0.5",
|
"@push.rocks/smartversion": "^3.0.5",
|
||||||
@ -55,8 +55,8 @@
|
|||||||
"@git.zone/tsrun": "^1.2.49",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@git.zone/tstest": "^1.0.90",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/qenv": "^6.0.5",
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
"@push.rocks/tapbundle": "^5.0.24",
|
"@push.rocks/tapbundle": "^5.3.0",
|
||||||
"@types/node": "22.4.2"
|
"@types/node": "22.7.5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
469
pnpm-lock.yaml
generated
469
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/docker',
|
name: '@apiclient.xyz/docker',
|
||||||
version: '1.2.3',
|
version: '1.3.0',
|
||||||
description: 'Provides easy communication with Docker remote API from Node.js, with TypeScript support.'
|
description: 'Provides easy communication with Docker remote API from Node.js, with TypeScript support.'
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ export class DockerHost {
|
|||||||
}
|
}
|
||||||
console.log(`using docker sock at ${pathToUse}`);
|
console.log(`using docker sock at ${pathToUse}`);
|
||||||
this.socketPath = pathToUse;
|
this.socketPath = pathToUse;
|
||||||
this.imageStore = new DockerImageStore(this, {
|
this.imageStore = new DockerImageStore({
|
||||||
bucketDir: null,
|
bucketDir: null,
|
||||||
localDirPath: this.options.imageStoreDir,
|
localDirPath: this.options.imageStoreDir,
|
||||||
})
|
})
|
||||||
|
@ -82,13 +82,93 @@ export class DockerImage {
|
|||||||
* @param dockerHostArg
|
* @param dockerHostArg
|
||||||
* @param tarStreamArg
|
* @param tarStreamArg
|
||||||
*/
|
*/
|
||||||
public static async createFromTarStream(dockerHostArg: DockerHost, optionsArg: {
|
public static async createFromTarStream(
|
||||||
creationObject: interfaces.IImageCreationDescriptor,
|
dockerHostArg: DockerHost,
|
||||||
tarStream: plugins.smartstream.stream.Readable,
|
optionsArg: {
|
||||||
}) {
|
creationObject: interfaces.IImageCreationDescriptor;
|
||||||
const response = await dockerHostArg.requestStreaming('POST', '/images/load', optionsArg.tarStream);
|
tarStream: plugins.smartstream.stream.Readable;
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
): Promise<DockerImage> {
|
||||||
|
// Start the request for importing an image
|
||||||
|
const response = await dockerHostArg.requestStreaming(
|
||||||
|
'POST',
|
||||||
|
'/images/load',
|
||||||
|
optionsArg.tarStream
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Docker typically returns lines like:
|
||||||
|
* {"stream":"Loaded image: myrepo/myimage:latest"}
|
||||||
|
*
|
||||||
|
* So we will collect those lines and parse out the final image name.
|
||||||
|
*/
|
||||||
|
let rawOutput = '';
|
||||||
|
response.on('data', (chunk) => {
|
||||||
|
rawOutput += chunk.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wrap the end event in a Promise for easier async/await usage
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
response.on('end', () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
response.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attempt to parse each line to find something like "Loaded image: ..."
|
||||||
|
let loadedImageTag: string | undefined;
|
||||||
|
const lines = rawOutput.trim().split('\n').filter(Boolean);
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
try {
|
||||||
|
const jsonLine = JSON.parse(line);
|
||||||
|
if (
|
||||||
|
jsonLine.stream &&
|
||||||
|
(jsonLine.stream.startsWith('Loaded image:') ||
|
||||||
|
jsonLine.stream.startsWith('Loaded image ID:'))
|
||||||
|
) {
|
||||||
|
// Examples:
|
||||||
|
// "Loaded image: your-image:latest"
|
||||||
|
// "Loaded image ID: sha256:...."
|
||||||
|
loadedImageTag = jsonLine.stream
|
||||||
|
.replace('Loaded image: ', '')
|
||||||
|
.replace('Loaded image ID: ', '')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// not valid JSON, ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!loadedImageTag) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not parse the loaded image info from Docker response.\nResponse was:\n${rawOutput}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now try to look up that image by the "loadedImageTag".
|
||||||
|
// Depending on Docker’s response, it might be something like:
|
||||||
|
// "myrepo/myimage:latest" OR "sha256:someHash..."
|
||||||
|
// If Docker gave you an ID (e.g. "sha256:..."), you may need a separate
|
||||||
|
// DockerImage.getImageById method; or if you prefer, you can treat it as a name.
|
||||||
|
const newlyImportedImage = await DockerImage.getImageByName(dockerHostArg, loadedImageTag);
|
||||||
|
|
||||||
|
if (!newlyImportedImage) {
|
||||||
|
throw new Error(
|
||||||
|
`Image load succeeded, but no local reference found for "${loadedImageTag}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
'info',
|
||||||
|
`Successfully imported image "${loadedImageTag}".`
|
||||||
|
);
|
||||||
|
|
||||||
|
return newlyImportedImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static async tagImageByIdOrName(
|
public static async tagImageByIdOrName(
|
||||||
dockerHost: DockerHost,
|
dockerHost: DockerHost,
|
||||||
@ -99,6 +179,8 @@ export class DockerImage {
|
|||||||
'POST',
|
'POST',
|
||||||
`/images/${encodeURIComponent(idOrNameArg)}/${encodeURIComponent(newTagArg)}`
|
`/images/${encodeURIComponent(idOrNameArg)}/${encodeURIComponent(newTagArg)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async buildImage(dockerHostArg: DockerHost, dockerImageTag) {
|
public static async buildImage(dockerHostArg: DockerHost, dockerImageTag) {
|
||||||
|
@ -17,7 +17,7 @@ export interface IDockerImageStoreConstructorOptions {
|
|||||||
export class DockerImageStore {
|
export class DockerImageStore {
|
||||||
public options: IDockerImageStoreConstructorOptions;
|
public options: IDockerImageStoreConstructorOptions;
|
||||||
|
|
||||||
constructor(dockerHost: DockerHost, optionsArg: IDockerImageStoreConstructorOptions) {
|
constructor(optionsArg: IDockerImageStoreConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user