Skip to content

Commit 18d38b2

Browse files
committed
Add support for docker push, update tests and readme.
1 parent 08e3097 commit 18d38b2

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,45 @@ docker.command('pull nginx:latest').then(function (data) {
620620
// ' stdout = '' stderr = 'Error response from daemon: manifest for nginx:999.999.999 not found
621621
```
622622

623+
* docker push
624+
625+
```js
626+
docker.command('push nginx:latest').then(function (data) {
627+
console.log('data = ', data);
628+
// Successfully pulled image
629+
}, function (rejected) {
630+
console.log('rejected = ', rejected);
631+
// Failed to pull image
632+
});
633+
634+
// data = { command: 'docker push mattsoghoian/test ',
635+
// raw:
636+
// 'The push refers to repository [docker.io/<username>/<repo>]\n08d25fa0442e: Preparing\na8c4aeeaa045: Preparing\ncdb3f9544e4c: Preparing\n08d25fa0442e: Mounted from library/nginx\na8c4aeeaa045: Mounted from library/nginx\ncdb3f9544e4c: Mounted from library/nginx\nlatest: digest: sha256:4ffd9758ea9ea360fd87d0cee7a2d1cf9dba630bb57ca36b3108dcd3708dc189 size: 948\n',
637+
// login:
638+
// 'The push refers to repository [docker.io/<username>/<repo>]\n08d25fa0442e: Preparing\na8c4aeeaa045: Preparing\ncdb3f9544e4c: Preparing\n08d25fa0442e: Mounted from library/nginx\na8c4aeeaa045: Mounted from library/nginx\ncdb3f9544e4c: Mounted from library/nginx\nlatest: digest: sha256:4ffd9758ea9ea360fd87d0cee7a2d1cf9dba630bb57ca36b3108dcd3708dc189 size: 948' }
639+
640+
// rejected = error: 'Error: Command failed: docker push nginx
641+
// An image does not exist locally with the tag: nginx
642+
// ' stdout = 'The push refers to repository [docker.io/library/nginx]
643+
// ' stderr = 'An image does not exist locally with the tag: nginx
644+
645+
// rejected = error: 'Error: Command failed: docker push nginx
646+
// errors:
647+
// denied: requested access to the resource is denied
648+
// unauthorized: authentication required
649+
// ' stdout = 'The push refers to repository [docker.io/library/nginx]
650+
// 08d25fa0442e: Preparing
651+
// a8c4aeeaa045: Preparing
652+
// cdb3f9544e4c: Preparing
653+
// cdb3f9544e4c: Layer already exists
654+
// 08d25fa0442e: Layer already exists
655+
// a8c4aeeaa045: Layer already exists
656+
// ' stderr = 'errors:
657+
// denied: requested access to the resource is denied
658+
// unauthorized: authentication required
659+
// '
660+
```
661+
623662

624663
## License
625664

src/index.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,29 @@ test("docker-cli-js", (t) => {
165165
});
166166
});
167167

168+
t.test("push intentionally failed, denied repo access", (t) => {
169+
170+
const docker = new Docker();
171+
172+
return docker.command("push nginx").then(function(data) {
173+
console.log("data = ", data);
174+
t.ok(data.login);
175+
}, function(rejected) {
176+
console.log("rejected = ", rejected);
177+
t.ok(/error/.test(rejected));
178+
});
179+
});
180+
181+
t.test("push intentionally failed, local image does not exist", (t) => {
182+
183+
const docker = new Docker();
184+
185+
return docker.command("push dmarionertfulthestoncoag").then(function(data) {
186+
console.log("data = ", data);
187+
t.ok(data.login);
188+
}, function(rejected) {
189+
console.log("rejected = ", rejected);
190+
t.ok(/error/.test(rejected));
191+
});
192+
});
168193
});

src/index.ts

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

141+
return resultp;
142+
},
143+
},
144+
{
145+
re: / push /,
146+
run(resultp: any) {
147+
resultp.login = resultp.raw.trim();
148+
141149
return resultp;
142150
},
143151
},

0 commit comments

Comments
 (0)