Skip to content

Commit

Permalink
TRITON-2403 Add support for docker OCI manifest format (#40)
Browse files Browse the repository at this point in the history
Reviewed by: Travis Paul <travis.paul@mnx.io>
  • Loading branch information
bahamat committed Jul 21, 2023
1 parent 07ad96f commit faf8c06
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
@@ -1,6 +1,6 @@
[submodule "deps/javascriptlint"]
path = deps/javascriptlint
url = https://github.com/davepacheco/javascriptlint.git
url = https://github.com/TritonDataCenter/javascriptlint.git
[submodule "deps/jsstyle"]
path = deps/jsstyle
url = https://github.com/joyent/jsstyle.git
url = https://github.com/TritonDataCenter/jsstyle.git
37 changes: 8 additions & 29 deletions CHANGES.md
Expand Up @@ -4,6 +4,13 @@

(nothing yet)

## 3.4.0

- TRITON-2403 Add support for docker OCI manifest format

As of this version, v1 repositories are still supported, but most tests have
been disabled due to the lack of available public repositories.

## 3.3.0

- DOCKER-524 Implement docker push. Adds uploadBlob and putManifest API methods.
Expand Down Expand Up @@ -81,38 +88,32 @@
- #8 Fix usage against a *http* registry.
- #7 Fix test suite against Docker Hub.


## 3.1.5

- DOCKER-772: Change `pingV2` to `callback(err)` rather than `throw err` if
the given `opts.indexName` is invalid.


## 3.1.4

- DOCKER-764: As of Docker 1.11, `docker login` will no longer prompt for an
email (docker/docker#20565). This updates `drc.login()` to no blow up
attempting to do v1 login if an email is not provided.


## 3.1.3

- DOCKER-689 Don't overwrite `err.body` for an HTTP response error that doesn't have
a JSON body.


## 3.1.2

- IMGAPI-546: 'docker pull nope.example.com/nope' throws exception in IMGAPI


## 3.1.1

- IMGAPI-542: Don't *require* the Docker-Content-Digest header on v2 GetBlob
server responses: `RegistryClientV2.prototype.createBlobReadStream`. Also
don't throw if can't parse an existing Docker-Content-Digest header.


## 3.1.0

- [pull #6, plus some additions] Allow one to ping a v2 registry using bearer
Expand Down Expand Up @@ -158,14 +159,11 @@
}
});



## 3.0.5

- DOCKER-643: RegistryClientV2 doesn't pass `insecure` flag to `ping()`
function properly.


## 3.0.4

- DOCKER-640: Fix assertion hit when attempting `getManifest` (or other v2 API
Expand All @@ -179,14 +177,12 @@
- Fix my config error that made me think the v2.quayioprivate tests
were failing. Re-enable that test in `make test`.


## 3.0.3

- DOCKER-627: Fix login for v2 quay.io. Two issues here:
1. quay.io has a bug where www-authenticate header isn't always in 401 response headers
2. passing "scope=" (empty value) query param to quay.io/v2/auth results in a 400


## 3.0.2

- DOCKER-625: Fix v1 pull of 'rhel7' from Docker Hub, which *redirects*
Expand All @@ -205,12 +201,10 @@
tests. Will revisit this later. See "test/v2.quayio.test.js" for some
notes on what I think are quay.io v2 bugs that I'll report.


## 3.0.1

- DOCKER-586 Allow `opts.proxy` to be a boolean.


## 3.0.0

- DOCKER-586 Add `drc.pingV2`, `drc.loginV2` and `drc.login`. The latter knows
Expand All @@ -227,7 +221,6 @@
in this module just to follow the form of the Docker Remote API "GET /auth"
response, and (b) this will mean being compatible with `pingV2`.


## 2.0.2

- DOCKER-583: Docker pull from v1 private registry failed with Resource Not Found error
Expand All @@ -238,7 +231,6 @@
- Fix passing through of username (for token 'account' field) and basic
authorization for token auth.


## 2.0.0

- A start at Docker Registry API v2 support. For now just *pull* support (the
Expand All @@ -249,12 +241,10 @@
My understanding is that this was due to <https://github.com/nodejs/node/issues/3055>.
This module is now avoiding `agent: false`, at least for the blob downloads.


## 1.4.1

- DOCKER-549 Fix pulling from quay.io *private* repos.


## 1.4.0

- Test suites improvements to actually check against docker.io, quay.io, and
Expand All @@ -270,7 +260,6 @@
- v1 Search doesn't need to do a ping. Presumably this is historical for
mistakenly thinking there was a need to determine `this.standalone`.


## 1.3.0

- [DOCKER-526] HTTP proxy support. This should work either (a) with the
Expand All @@ -294,25 +283,20 @@

The "example/\*.js" scripts all do this now.



## 1.2.2

- [pull #4] Fix `getImgAncestry` when using node 0.12 (by github.com/vincentwoo).


## 1.2.1

- Sanitize the non-json (text/html) `err.message` from `listRepoImgs` on a 404.
See before and after: https://gist.github.com/trentm/94c11e1243fb7fd4fe90

See before and after: <https://gist.github.com/trentm/94c11e1243fb7fd4fe90>

## 1.2.0

- Add `drc.login(...)` for handling a Docker Engine would use for the Remote
API side of `docker login`.


## 1.1.0

- `RegistryClient.ping` will not retry so that a ping failure check is quick.
Expand All @@ -323,7 +307,6 @@
- A client to localhost will default to the 'http' scheme to (mostly) match
docker-docker's behaviour here.


## 1.0.0

A major re-write with lots of backwards compat *breakage*. This release adds
Expand All @@ -341,7 +324,6 @@ There *is* a `drc.pingIndex()` which can be used to check that a registry
host (aka an "index" from the old separation of an "Index API") is up.
Usage is best learned from the complete set of examples in "examples/".


- **Backward incompat change** in return value from `parseRepoAndTag`.
In addition to adding support for the optional index prefix, and a
"@DIGEST" suffix, the fields on the return value have been changed to
Expand Down Expand Up @@ -392,8 +374,6 @@ Usage is best learned from the complete set of examples in "examples/".
tag: '1.2.3'
}



## 0.3.2

Note: Any 0.x work (I don't anticipate any) will be on the "0.x" branch.
Expand All @@ -415,7 +395,6 @@ Note: Any 0.x work (I don't anticipate any) will be on the "0.x" branch.
subsequent downloads.
- URL encode params in API call paths.


## 0.2.0

Started changelog after this version.
2 changes: 1 addition & 1 deletion deps/javascriptlint
Submodule javascriptlint updated 1 files
+31 −6 Makefile
5 changes: 5 additions & 0 deletions lib/index.js
Expand Up @@ -6,6 +6,7 @@

/*
* Copyright 2016 Joyent, Inc.
* Copyright 2023 MNX Cloud, Inc.
*/

var assert = require('assert-plus');
Expand Down Expand Up @@ -134,6 +135,10 @@ module.exports = {
digestFromManifestStr: reg2.digestFromManifestStr,
MEDIATYPE_MANIFEST_V2: reg2.MEDIATYPE_MANIFEST_LIST_V2,
MEDIATYPE_MANIFEST_LIST_V2: reg2.MEDIATYPE_MANIFEST_LIST_V2,
MEDIATYPE_OCI_MANIFEST_V1: reg2.MEDIATYPE_OCI_MANIFEST_V1,
MEDIATYPE_OCI_MANIFEST_LIST_V1: reg2.MEDIATYPE_OCI_MANIFEST_LIST_V1,
manifestTypes: reg2.manifestTypes,
manifestListTypes: reg2.manifestListTypes,

createClientV1: reg1.createClient,
pingIndexV1: reg1.pingIndex,
Expand Down
24 changes: 21 additions & 3 deletions lib/registry-client-v2.js
Expand Up @@ -6,6 +6,7 @@

/*
* Copyright 2017 Joyent, Inc.
* Copyright 2023 MNX Cloud, Inc.
*/

/*
Expand Down Expand Up @@ -43,7 +44,18 @@ var MEDIATYPE_MANIFEST_V2
= 'application/vnd.docker.distribution.manifest.v2+json';
var MEDIATYPE_MANIFEST_LIST_V2
= 'application/vnd.docker.distribution.manifest.list.v2+json';

var MEDIATYPE_OCI_MANIFEST_V1
= 'application/vnd.oci.image.manifest.v1+json';
var MEDIATYPE_OCI_MANIFEST_LIST_V1
= 'application/vnd.oci.image.index.v1+json';
var manifestTypes = [
MEDIATYPE_MANIFEST_V2,
MEDIATYPE_OCI_MANIFEST_V1
];
var manifestListTypes = [
MEDIATYPE_MANIFEST_LIST_V2,
MEDIATYPE_OCI_MANIFEST_LIST_V1
];

// --- internal support functions

Expand Down Expand Up @@ -1396,8 +1408,10 @@ RegistryClientV2.prototype.getManifest = function getManifest(opts, cb) {
}
}
accept.push(MEDIATYPE_MANIFEST_V2);
accept.push(MEDIATYPE_OCI_MANIFEST_V1);
if (acceptManifestLists) {
accept.push(MEDIATYPE_MANIFEST_LIST_V2);
accept.push(MEDIATYPE_OCI_MANIFEST_LIST_V1);
}
headers = common.objMerge({}, self._headers, {accept: accept});
}
Expand Down Expand Up @@ -1460,7 +1474,7 @@ RegistryClientV2.prototype.getManifest = function getManifest(opts, cb) {
}

// Verify the manifest contents.
if (manifest.mediaType === MEDIATYPE_MANIFEST_LIST_V2) {
if (manifestListTypes.indexOf(manifest.mediaType) !== -1) {
if (!Array.isArray(manifest.manifests) ||
manifest.manifests.length === 0) {
cb(new restifyErrors.InvalidContentError(fmt(
Expand Down Expand Up @@ -2088,5 +2102,9 @@ module.exports = {
login: login,
digestFromManifestStr: digestFromManifestStr,
MEDIATYPE_MANIFEST_V2: MEDIATYPE_MANIFEST_V2,
MEDIATYPE_MANIFEST_LIST_V2: MEDIATYPE_MANIFEST_LIST_V2
MEDIATYPE_MANIFEST_LIST_V2: MEDIATYPE_MANIFEST_LIST_V2,
MEDIATYPE_OCI_MANIFEST_V1: MEDIATYPE_OCI_MANIFEST_V1,
MEDIATYPE_OCI_MANIFEST_LIST_V1: MEDIATYPE_OCI_MANIFEST_LIST_V1,
manifestTypes: manifestTypes,
manifestListTypes: manifestListTypes
};
6 changes: 3 additions & 3 deletions package.json
@@ -1,8 +1,8 @@
{
"name": "docker-registry-client",
"version": "3.3.1",
"version": "3.4.0",
"description": "node.js client for the Docker Registry API",
"author": "Joyent (joyent.com)",
"author": "MNX Cloud (mnx.io)",
"main": "./lib/index.js",
"dependencies": {
"assert-plus": "^0.1.5",
Expand Down Expand Up @@ -38,7 +38,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/joyent/node-docker-registry-client.git"
"url": "https://github.com/TritonDataCenter/node-docker-registry-client.git"
},
"license": "MPL-2.0"
}
15 changes: 8 additions & 7 deletions test/v1.dockerio.test.js
Expand Up @@ -6,6 +6,7 @@

/*
* Copyright (c) 2015, Joyent, Inc.
* Copyright 2023 MNX Cloud, Inc.
*/

var test = require('tape');
Expand Down Expand Up @@ -33,7 +34,7 @@ test('v1 docker.io', function (tt) {
t.end();
});

tt.test(' ping', function (t) {
tt.skip(' ping', function (t) {
client.ping(function (err, status, res) {
t.ifErr(err);
t.equal(status, true);
Expand All @@ -55,7 +56,7 @@ test('v1 docker.io', function (tt) {
});
});

tt.test(' listRepoImgs', function (t) {
tt.skip(' listRepoImgs', function (t) {
client.listRepoImgs(function (err, imgs) {
t.ifErr(err);
t.ok(Array.isArray(imgs));
Expand All @@ -71,7 +72,7 @@ test('v1 docker.io', function (tt) {
var tag = '2.7';
var repoTags;

tt.test(' listRepoTags', function (t) {
tt.skip(' listRepoTags', function (t) {
client.listRepoTags(function (err, repoTags_) {
repoTags = repoTags_;
t.ifErr(err);
Expand All @@ -82,7 +83,7 @@ test('v1 docker.io', function (tt) {
});
});

tt.test(' getImgId', function (t) {
tt.skip(' getImgId', function (t) {
client.getImgId({tag: tag}, function (err, imgId) {
t.ifErr(err);
t.ok(imgId);
Expand All @@ -92,7 +93,7 @@ test('v1 docker.io', function (tt) {
});
});

tt.test(' getImgAncestry', function (t) {
tt.skip(' getImgAncestry', function (t) {
client.getImgAncestry({imgId: repoTags[tag]}, function (err, ancestry) {
t.ifErr(err);
t.ok(Array.isArray(ancestry));
Expand All @@ -102,7 +103,7 @@ test('v1 docker.io', function (tt) {
});
});

tt.test(' getImgJson', function (t) {
tt.skip(' getImgJson', function (t) {
var imgId = repoTags[tag];
client.getImgJson({imgId: imgId}, function (err, imgJson, res) {
t.ifErr(err);
Expand All @@ -112,7 +113,7 @@ test('v1 docker.io', function (tt) {
});
});

tt.test(' getImgLayerStream', function (t) {
tt.skip(' getImgLayerStream', function (t) {
var imgId = repoTags[tag];
client.getImgLayerStream({imgId: imgId}, function (getErr, stream) {
t.ifErr(getErr, 'no error');
Expand Down

0 comments on commit faf8c06

Please sign in to comment.