Skip to content

Commit

Permalink
Merge pull request #5 from msoghoian/pull-push
Browse files Browse the repository at this point in the history
Docker push and pull support
  • Loading branch information
mattqs authored Aug 30, 2018
2 parents 334b981 + 18d38b2 commit 48f63b4
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,65 @@ docker.command('login -u myusername -p mypassword').then(function (data) {
// Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
```

* docker pull

```js
docker.command('pull nginx:latest').then(function (data) {
console.log('data = ', data);
// Successfully pulled image
}, function (rejected) {
console.log('rejected = ', rejected);
// Failed to pull image
});

// data = { command: 'docker pull nginx:1.15.2 ',
// raw:'1.15.2: Pulling from library/nginx\nDigest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424\nStatus: Image is up to date for nginx:1.15.2\n',
// login: '1.15.2: Pulling from library/nginx\nDigest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424\nStatus: Image is up to date for nginx:1.15.2' }

// rejected = error: 'Error: Command failed: docker pull nginx:999.999.999
// Error response from daemon: manifest for nginx:999.999.999 not found
// ' stdout = '' stderr = 'Error response from daemon: manifest for nginx:999.999.999 not found
```

* docker push

```js
docker.command('push nginx:latest').then(function (data) {
console.log('data = ', data);
// Successfully pulled image
}, function (rejected) {
console.log('rejected = ', rejected);
// Failed to pull image
});

// data = { command: 'docker push mattsoghoian/test ',
// raw:
// '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',
// login:
// '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' }

// rejected = error: 'Error: Command failed: docker push nginx
// An image does not exist locally with the tag: nginx
// ' stdout = 'The push refers to repository [docker.io/library/nginx]
// ' stderr = 'An image does not exist locally with the tag: nginx

// rejected = error: 'Error: Command failed: docker push nginx
// errors:
// denied: requested access to the resource is denied
// unauthorized: authentication required
// ' stdout = 'The push refers to repository [docker.io/library/nginx]
// 08d25fa0442e: Preparing
// a8c4aeeaa045: Preparing
// cdb3f9544e4c: Preparing
// cdb3f9544e4c: Layer already exists
// 08d25fa0442e: Layer already exists
// a8c4aeeaa045: Layer already exists
// ' stderr = 'errors:
// denied: requested access to the resource is denied
// unauthorized: authentication required
// '
```


## License

Expand Down
58 changes: 58 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,62 @@ test("docker-cli-js", (t) => {
});
});

t.test("pull latest", (t) => {

const docker = new Docker();

return docker.command("pull nginx").then(function(data) {
console.log("data = ", data);
t.ok(data.login);
});
});

t.test("pull specific tag", (t) => {

const docker = new Docker();

return docker.command("pull nginx:1.15.2").then(function(data) {
console.log("data = ", data);
t.ok(data.login);
});
});

t.test("pull intentionally failed, invalid image", (t) => {

const docker = new Docker();

return docker.command("pull nginx:999.999.999").then(function(data) {
console.log("data = ", data);
t.notOk(data.login);
}, function(rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});

t.test("push intentionally failed, denied repo access", (t) => {

const docker = new Docker();

return docker.command("push nginx").then(function(data) {
console.log("data = ", data);
t.ok(data.login);
}, function(rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});

t.test("push intentionally failed, local image does not exist", (t) => {

const docker = new Docker();

return docker.command("push dmarionertfulthestoncoag").then(function(data) {
console.log("data = ", data);
t.ok(data.login);
}, function(rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});
});
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ const extractResult = function(result: any) {
run(resultp: any) {
resultp.login = resultp.raw.trim();

return resultp;
},
},
{
re: / pull /,
run(resultp: any) {
resultp.login = resultp.raw.trim();

return resultp;
},
},
{
re: / push /,
run(resultp: any) {
resultp.login = resultp.raw.trim();

return resultp;
},
},
Expand Down

0 comments on commit 48f63b4

Please sign in to comment.