Skip to content

Commit 08e3097

Browse files
committed
Add support for docker pull, update tests and readme.
1 parent 334b981 commit 08e3097

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,26 @@ docker.command('login -u myusername -p mypassword').then(function (data) {
600600
// Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
601601
```
602602

603+
* docker pull
604+
605+
```js
606+
docker.command('pull nginx:latest').then(function (data) {
607+
console.log('data = ', data);
608+
// Successfully pulled image
609+
}, function (rejected) {
610+
console.log('rejected = ', rejected);
611+
// Failed to pull image
612+
});
613+
614+
// data = { command: 'docker pull nginx:1.15.2 ',
615+
// raw:'1.15.2: Pulling from library/nginx\nDigest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424\nStatus: Image is up to date for nginx:1.15.2\n',
616+
// login: '1.15.2: Pulling from library/nginx\nDigest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424\nStatus: Image is up to date for nginx:1.15.2' }
617+
618+
// rejected = error: 'Error: Command failed: docker pull nginx:999.999.999
619+
// Error response from daemon: manifest for nginx:999.999.999 not found
620+
// ' stdout = '' stderr = 'Error response from daemon: manifest for nginx:999.999.999 not found
621+
```
622+
603623

604624
## License
605625

src/index.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,37 @@ test("docker-cli-js", (t) => {
132132
});
133133
});
134134

135+
t.test("pull latest", (t) => {
136+
137+
const docker = new Docker();
138+
139+
return docker.command("pull nginx").then(function(data) {
140+
console.log("data = ", data);
141+
t.ok(data.login);
142+
});
143+
});
144+
145+
t.test("pull specific tag", (t) => {
146+
147+
const docker = new Docker();
148+
149+
return docker.command("pull nginx:1.15.2").then(function(data) {
150+
console.log("data = ", data);
151+
t.ok(data.login);
152+
});
153+
});
154+
155+
t.test("pull intentionally failed, invalid image", (t) => {
156+
157+
const docker = new Docker();
158+
159+
return docker.command("pull nginx:999.999.999").then(function(data) {
160+
console.log("data = ", data);
161+
t.notOk(data.login);
162+
}, function(rejected) {
163+
console.log("rejected = ", rejected);
164+
t.ok(/error/.test(rejected));
165+
});
166+
});
167+
135168
});

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ const extractResult = function(result: any) {
130130
run(resultp: any) {
131131
resultp.login = resultp.raw.trim();
132132

133+
return resultp;
134+
},
135+
},
136+
{
137+
re: / pull /,
138+
run(resultp: any) {
139+
resultp.login = resultp.raw.trim();
140+
133141
return resultp;
134142
},
135143
},

0 commit comments

Comments
 (0)