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
62 changes: 60 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
- name: Setup Node for Unit Tests
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.0.3
with:
cache: npm
Expand All @@ -47,7 +47,7 @@ jobs:

- name: Set up Docker
id: engine
uses: docker/setup-docker-action@v4
uses: docker/setup-docker-action@b60f85385d03ac8acfca6d9996982511d8620a19 #v4.3.0
with:
version: type=image,version=${{ matrix.engine }}

Expand All @@ -57,18 +57,76 @@ jobs:
env:
DOCKER_HOST: ${{ steps.engine.outputs.sock }}

build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node for Build
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.0.3
with:
cache: npm
node-version-file: .node-version

- name: Install
run: |
npm install

- name: Build
run: |
npm run build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/

ci-integration:
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
node:
- 18
- 20
- 22
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: dist

- name: Set up Docker
id: engine
uses: docker/setup-docker-action@b60f85385d03ac8acfca6d9996982511d8620a19 #v4.3.0
with:
version: type=image,version=28

- name: Setup Node v${{ matrix.node }} for Integration Tests
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.0.3
with:
cache: npm
node-version: ${{ matrix.node }}

- name: Integration tests ESM
working-directory: ./test-integration/esm-project
run: |
npm install --install-links
npm run test
env:
DOCKER_HOST: ${{ steps.engine.outputs.sock }}

- name: Integration tests CJS
working-directory: ./test-integration/cjs-project
run: |
npm install --install-links
npm run test
env:
DOCKER_HOST: ${{ steps.engine.outputs.sock }}
7 changes: 4 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DockerClient } from './lib/docker-client.js';
import { createWriteStream } from 'node:fs';
import { tmpdir } from 'node:os';

try {
const docker = await DockerClient.fromDockerConfig();
Expand All @@ -18,10 +19,10 @@ try {
return value.Id;
});

const out = createWriteStream('/tmp/test.tar');
const out = createWriteStream(tmpdir() + '/test.tar');
await docker.containerExport(ctr, out);

docker.close();
} catch (error) {
console.error(error);
} catch (error: any) {
console.error(`Error: ${error.message ?? error}`);
Comment thread Dismissed
Comment thread Dismissed
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"vitest": "^3.2.4"
},
"engines": {
"node": ">=22.19.0"
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
},
"packageManager": "npm@10.9.3"
}
1 change: 1 addition & 0 deletions test-integration/cjs-project/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.20.8
34 changes: 34 additions & 0 deletions test-integration/cjs-project/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { DockerClient } = require('@docker/node-sdk');
const fs = require('fs');
const os = require('os');

async function main() {
try {
const docker = await DockerClient.fromDockerConfig();

await docker.systemPing();

const v = await docker.systemVersion();
console.dir(v, { depth: null });

const ctr = await docker
.containerCreate({
Image: 'alpine',
})
.then((value) => {
console.dir(value, { depth: null });
return value.Id;
});

const out = fs.createWriteStream(os.tmpdir() + '/test.tar');
await docker.containerExport(ctr, out);

docker.close();
} catch (error) {
console.error(`Error: ${error.message ?? error}`);
Comment thread Dismissed
Comment thread Dismissed
}
}

main().catch((error) => {
console.error('Error:', error);
});
8 changes: 3 additions & 5 deletions test-integration/cjs-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
"version": "1.0.0",
"private": true,
"scripts": {
"test": "node --test"
"test": "node --test",
"start": "node main.js"
},
"type": "commonjs",
"main": "main.js",
"dependencies": {
"@docker/node-sdk": "file:../.."
},
"devDependencies": {
"typescript": "^5.9.2",
"vitest": "^3.2.4"
}
}
1 change: 1 addition & 0 deletions test-integration/esm-project/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.20.8
28 changes: 28 additions & 0 deletions test-integration/esm-project/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { DockerClient } from '@docker/node-sdk';
import { createWriteStream } from 'node:fs';
import { tmpdir } from 'node:os';

try {
const docker = await DockerClient.fromDockerConfig();

await docker.systemPing();

const v = await docker.systemVersion();
console.dir(v, { depth: null });

const ctr = await docker
.containerCreate({
Image: 'alpine',
})
.then((value) => {
console.dir(value, { depth: null });
return value.Id;
});

const out = createWriteStream(tmpdir() + '/test.tar');
await docker.containerExport(ctr, out);

docker.close();
} catch (error: any) {
console.error(`Error: ${error?.message ?? error}`);
Comment thread Dismissed
Comment thread Dismissed
}
30 changes: 16 additions & 14 deletions test-integration/esm-project/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "esm-project",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "node --test"
},
"type": "module",
"dependencies": {
"@docker/node-sdk": "file:../.."
},
"devDependencies": {
"@types/node": "^24.5.2",
"typescript": "^5.9.2"
}
"name": "esm-project",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "tsx --test import.test.ts",
"start": "tsx main.ts"
},
"type": "module",
"dependencies": {
"@docker/node-sdk": "file:../.."
},
"devDependencies": {
"@types/node": "^24.5.2",
"tsx": "^4.20.6",
"typescript": "^5.9.2"
}
}
2 changes: 1 addition & 1 deletion tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
sourcemap: true,
unbundle: false,
treeshake: false,
target: 'es2022',
target: ['es2022', 'node18'],
platform: 'node',
tsconfig: './tsconfig.json',
nodeProtocol: true,
Expand Down