fix(core): Stabilize CI/workflows and runtime: update CI images/metadata, improve streaming requests and image handling, and fix tests & package metadata

This commit is contained in:
2025-08-19 01:46:37 +00:00
parent 4b1c908b89
commit 414d7dd727
19 changed files with 444 additions and 243 deletions

137
readme.md
View File

@@ -38,7 +38,7 @@ const docker = new DockerHost();
// Or connect to remote Docker host
const remoteDocker = new DockerHost({
socketPath: 'tcp://remote-docker-host:2375'
socketPath: 'tcp://remote-docker-host:2375',
});
```
@@ -56,9 +56,9 @@ const docker = new DockerHost();
// Custom initialization options
const customDocker = new DockerHost({
socketPath: '/var/run/docker.sock', // Unix socket path
socketPath: '/var/run/docker.sock', // Unix socket path
// or
socketPath: 'tcp://192.168.1.100:2375' // TCP connection
socketPath: 'tcp://192.168.1.100:2375', // TCP connection
});
// Start and stop (for lifecycle management)
@@ -76,7 +76,7 @@ await docker.stop();
const allContainers = await docker.getContainers();
// Each container includes detailed information
allContainers.forEach(container => {
allContainers.forEach((container) => {
console.log(`Container: ${container.Names[0]}`);
console.log(` ID: ${container.Id}`);
console.log(` Status: ${container.Status}`);
@@ -96,21 +96,18 @@ const container = await DockerContainer.create(docker, {
name: 'my-nginx-server',
HostConfig: {
PortBindings: {
'80/tcp': [{ HostPort: '8080' }]
'80/tcp': [{ HostPort: '8080' }],
},
RestartPolicy: {
Name: 'unless-stopped'
Name: 'unless-stopped',
},
Memory: 512 * 1024 * 1024, // 512MB memory limit
},
Env: [
'NODE_ENV=production',
'LOG_LEVEL=info'
],
Env: ['NODE_ENV=production', 'LOG_LEVEL=info'],
Labels: {
'app': 'web-server',
'environment': 'production'
}
app: 'web-server',
environment: 'production',
},
});
console.log(`Container created: ${container.Id}`);
@@ -124,7 +121,10 @@ console.log(`Container created: ${container.Id}`);
#### Get Container by ID
```typescript
const container = await DockerContainer.getContainerById(docker, 'container-id-here');
const container = await DockerContainer.getContainerById(
docker,
'container-id-here',
);
if (container) {
console.log(`Found container: ${container.Names[0]}`);
}
@@ -142,7 +142,7 @@ const image = await DockerImage.createFromRegistry(docker, {
imageName: 'node',
imageTag: '18-alpine',
// Optional: provide registry authentication
authToken: 'your-registry-auth-token'
authToken: 'your-registry-auth-token',
});
console.log(`Image pulled: ${image.RepoTags[0]}`);
@@ -159,7 +159,7 @@ const tarStream = fs.createReadStream('./my-image.tar');
const importedImage = await DockerImage.createFromTarStream(docker, {
tarStream,
imageUrl: 'file://./my-image.tar',
imageTag: 'my-app:v1.0.0'
imageTag: 'my-app:v1.0.0',
});
```
@@ -182,7 +182,7 @@ exportStream.pipe(writeStream);
await DockerImage.tagImageByIdOrName(docker, 'node:18-alpine', {
registry: 'myregistry.com',
imageName: 'my-node-app',
imageTag: 'v2.0.0'
imageTag: 'v2.0.0',
});
// Result: myregistry.com/my-node-app:v2.0.0
```
@@ -201,15 +201,17 @@ const network = await DockerNetwork.createNetwork(docker, {
EnableIPv6: false,
IPAM: {
Driver: 'default',
Config: [{
Subnet: '172.28.0.0/16',
Gateway: '172.28.0.1'
}]
Config: [
{
Subnet: '172.28.0.0/16',
Gateway: '172.28.0.1',
},
],
},
Labels: {
'project': 'my-app',
'environment': 'production'
}
project: 'my-app',
environment: 'production',
},
});
console.log(`Network created: ${network.Id}`);
@@ -220,14 +222,17 @@ console.log(`Network created: ${network.Id}`);
```typescript
// Get all networks
const networks = await docker.getNetworks();
networks.forEach(net => {
networks.forEach((net) => {
console.log(`Network: ${net.Name} (${net.Driver})`);
console.log(` Scope: ${net.Scope}`);
console.log(` Internal: ${net.Internal}`);
});
// Get specific network
const appNetwork = await DockerNetwork.getNetworkByName(docker, 'my-app-network');
const appNetwork = await DockerNetwork.getNetworkByName(
docker,
'my-app-network',
);
// Get containers on network
const containers = await appNetwork.getContainersOnNetwork();
@@ -246,28 +251,32 @@ const service = await DockerService.createService(docker, {
name: 'web-api',
image: 'my-api:latest',
replicas: 3,
ports: [{
Protocol: 'tcp',
PublishedPort: 80,
TargetPort: 3000
}],
ports: [
{
Protocol: 'tcp',
PublishedPort: 80,
TargetPort: 3000,
},
],
networks: ['my-app-network'],
labels: {
'app': 'api',
'version': '2.0.0'
app: 'api',
version: '2.0.0',
},
resources: {
limits: {
Memory: 256 * 1024 * 1024, // 256MB
CPUs: 0.5
}
CPUs: 0.5,
},
},
secrets: ['api-key', 'db-password'],
mounts: [{
Target: '/data',
Source: 'app-data',
Type: 'volume'
}]
mounts: [
{
Target: '/data',
Source: 'app-data',
Type: 'volume',
},
],
});
console.log(`Service deployed: ${service.ID}`);
@@ -278,7 +287,7 @@ console.log(`Service deployed: ${service.ID}`);
```typescript
// List all services
const services = await docker.getServices();
services.forEach(service => {
services.forEach((service) => {
console.log(`Service: ${service.Spec.Name}`);
console.log(` Replicas: ${service.Spec.Mode.Replicated.Replicas}`);
console.log(` Image: ${service.Spec.TaskTemplate.ContainerSpec.Image}`);
@@ -307,16 +316,16 @@ const secret = await DockerSecret.createSecret(docker, {
name: 'api-key',
data: Buffer.from('super-secret-key-123').toString('base64'),
labels: {
'app': 'my-app',
'type': 'api-key'
}
app: 'my-app',
type: 'api-key',
},
});
console.log(`Secret created: ${secret.ID}`);
// List secrets
const secrets = await DockerSecret.getSecrets(docker);
secrets.forEach(secret => {
secrets.forEach((secret) => {
console.log(`Secret: ${secret.Spec.Name}`);
});
@@ -325,7 +334,7 @@ const apiKeySecret = await DockerSecret.getSecretByName(docker, 'api-key');
// Update secret
await apiKeySecret.update({
data: Buffer.from('new-secret-key-456').toString('base64')
data: Buffer.from('new-secret-key-456').toString('base64'),
});
// Remove secret
@@ -342,7 +351,7 @@ await docker.addS3Storage({
endpoint: 's3.amazonaws.com',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
bucket: 'docker-images'
bucket: 'docker-images',
});
// Store an image to S3
@@ -368,7 +377,7 @@ const subscription = eventStream.subscribe({
console.log(`Time: ${new Date(event.time * 1000).toISOString()}`);
},
error: (err) => console.error('Event stream error:', err),
complete: () => console.log('Event stream completed')
complete: () => console.log('Event stream completed'),
});
// Unsubscribe when done
@@ -384,7 +393,7 @@ Authenticate with Docker registries for private images:
await docker.auth({
username: 'your-username',
password: 'your-password',
serveraddress: 'https://index.docker.io/v1/'
serveraddress: 'https://index.docker.io/v1/',
});
// Or use existing Docker config
@@ -394,7 +403,7 @@ const authToken = await docker.getAuthTokenFromDockerConfig('myregistry.com');
const privateImage = await DockerImage.createFromRegistry(docker, {
imageName: 'myregistry.com/private/image',
imageTag: 'latest',
authToken
authToken,
});
```
@@ -407,14 +416,14 @@ Initialize and manage Docker Swarm:
await docker.activateSwarm({
ListenAddr: '0.0.0.0:2377',
AdvertiseAddr: '192.168.1.100:2377',
ForceNewCluster: false
ForceNewCluster: false,
});
// Now you can create services, secrets, and use swarm features
const service = await DockerService.createService(docker, {
name: 'my-swarm-service',
image: 'nginx:latest',
replicas: 5
replicas: 5,
// ... more service config
});
```
@@ -426,37 +435,37 @@ const service = await DockerService.createService(docker, {
```typescript
async function deployStack() {
const docker = new DockerHost();
// Create network
const network = await DockerNetwork.createNetwork(docker, {
Name: 'app-network',
Driver: 'overlay' // for swarm mode
Driver: 'overlay', // for swarm mode
});
// Create secrets
const dbPassword = await DockerSecret.createSecret(docker, {
name: 'db-password',
data: Buffer.from('strong-password').toString('base64')
data: Buffer.from('strong-password').toString('base64'),
});
// Deploy database service
const dbService = await DockerService.createService(docker, {
name: 'postgres',
image: 'postgres:14',
networks: ['app-network'],
secrets: ['db-password'],
env: ['POSTGRES_PASSWORD_FILE=/run/secrets/db-password']
env: ['POSTGRES_PASSWORD_FILE=/run/secrets/db-password'],
});
// Deploy application service
const appService = await DockerService.createService(docker, {
name: 'web-app',
image: 'my-app:latest',
replicas: 3,
networks: ['app-network'],
ports: [{ Protocol: 'tcp', PublishedPort: 80, TargetPort: 3000 }]
ports: [{ Protocol: 'tcp', PublishedPort: 80, TargetPort: 3000 }],
});
console.log('Stack deployed successfully!');
}
```
@@ -471,7 +480,7 @@ import type {
IServiceCreationDescriptor,
INetworkCreationDescriptor,
IImageCreationDescriptor,
ISecretCreationDescriptor
ISecretCreationDescriptor,
} from '@apiclient.xyz/docker';
// Full IntelliSense support for all configuration options
@@ -493,7 +502,7 @@ For Docker Remote API reference, see [Docker Engine API Documentation](https://d
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
@@ -508,4 +517,4 @@ Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.