Skip to content

Commit f914509

Browse files
committed
Added support for OCI image indexes and manifest
Added test for dockerv2 kiwix-serve (3.8.1) and ociv1 (3.8.2) Fixes #12
1 parent f953852 commit f914509

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Support for OCI image indexes and manifest (#12)
13+
814
## [1.1.0] - 2024-01-30
915

1016
### Added

src/docker_export/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
3838
logger = logging.getLogger("docker-export")
3939
logging.getLogger("urllib3").setLevel(logging.WARNING)
40+
CT_DOCKER_MANIFEST_LIST = "application/vnd.docker.distribution.manifest.list.v2+json"
41+
CT_DOCKER_MANIFEST = "application/vnd.docker.distribution.manifest.v2+json"
42+
CT_OCI_INDEXES = "application/vnd.oci.image.index.v1+json"
43+
CT_OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json"
44+
CT_OCI_IMAGE_CONFIG = "application/vnd.oci.image.config.v1+json"
45+
CT_OCI_EMPTY = "application/vnd.oci.image.config.v1+json"
46+
CT_OCI_LAYERS = (
47+
"application/vnd.oci.image.layer.v1.tar,application/vnd.oci.image.layer.v1.tar+gzip"
48+
)
4049

4150

4251
class ImageNotFoundError(Exception): ...
@@ -384,7 +393,7 @@ def get_manifests(image: Image, auth: RegistryAuth):
384393
f"/manifests/{image.reference}",
385394
headers=dict(
386395
**auth.headers,
387-
**{"Accept": "application/vnd.docker.distribution.manifest.list.v2+json"},
396+
**{"Accept": ", ".join([CT_DOCKER_MANIFEST_LIST, CT_OCI_INDEXES])},
388397
),
389398
timeout=REQUEST_TIMEOUT,
390399
)
@@ -415,13 +424,12 @@ def get_layers_manifest_for(
415424
f"/manifests/{reference}",
416425
headers=dict(
417426
**auth.headers,
418-
**{"Accept": "application/vnd.docker.distribution.manifest.v2+json"},
427+
**{"Accept": ", ".join([CT_DOCKER_MANIFEST, CT_OCI_MANIFEST])},
419428
),
420429
timeout=REQUEST_TIMEOUT,
421430
)
422431
if resp.status_code != http.HTTPStatus.OK:
423-
raise OSError("HTTP {resp.status_code}: {resp.reason} -- {resp.text}")
424-
432+
raise OSError(f"HTTP {resp.status_code}: {resp.reason} -- {resp.text}")
425433
return resp.json()
426434

427435

@@ -438,7 +446,7 @@ def get_layers_from_v1_manifest(
438446
)
439447

440448
return {
441-
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
449+
"mediaType": CT_DOCKER_MANIFEST,
442450
"schemaVersion": 2,
443451
"config": {
444452
"mediaType": "application/vnd.docker.container.image.v1+json",
@@ -447,7 +455,7 @@ def get_layers_from_v1_manifest(
447455
},
448456
"layers": [
449457
{
450-
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
458+
"mediaType": CT_DOCKER_MANIFEST,
451459
"digest": layer["blobSum"],
452460
# "size": None,
453461
"platform": {"architecture": architecture, "os": os},
@@ -524,7 +532,7 @@ def download_layer_blob(
524532
f"https://{image.registry}/v2/{image.fullname}/blobs/{layer_digest}",
525533
headers=dict(
526534
**auth.headers,
527-
**{"Accept": "application/vnd.docker.distribution.manifest.v2+json"},
535+
**{"Accept": CT_DOCKER_MANIFEST},
528536
),
529537
stream=True,
530538
timeout=REQUEST_TIMEOUT,
@@ -536,7 +544,7 @@ def download_layer_blob(
536544
layer["urls"][0],
537545
headers=dict(
538546
**auth.headers,
539-
**{"Accept": "application/vnd.docker.distribution.manifest.v2+json"},
547+
**{"Accept": CT_DOCKER_MANIFEST},
540548
),
541549
stream=True,
542550
timeout=REQUEST_TIMEOUT,

tests/test_digest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
# which is the Docker-Content-Digest
2525
"sha256:148e55d6f2c3fa74bdba8f2b6870677cfcb268e5a9bebc9e5135a026f502f447",
2626
),
27+
(
28+
"ghcr.io/offspot/kiwix-serve:3.8.2",
29+
"linux/arm64",
30+
"sha256:eb186010ca6318da285db02383d2bb4aef45034faead4eb8a78fcde758d919c3",
31+
),
32+
(
33+
"ghcr.io/offspot/kiwix-serve:3.8.1",
34+
"linux/amd64",
35+
"sha256:c7e75fd985a93aedcc4582751f23d64bcf4274294fff63c3b7a0ba32bc3d103f",
36+
),
2737
(
2838
f"{kiwix_tools}:3.5.0-2",
2939
"linux/amd64",

0 commit comments

Comments
 (0)