Skip to content

Commit

Permalink
refactor: Refactor of the publish path and HttpTransport (#162)
Browse files Browse the repository at this point in the history
To improve the testability of publishing a package,
`PyOci.publish_package()` is split into multiple methods.

Tests for the refactored parts were moved/restructured so it is no longer needed
to go through the entire request flow for every test (including mockito).

A new Trait `Transport` is introduced and `PyOci` is generic over `Transport`.
This allows swapping the `HttpTransport` in unittests in the future,
removing the need to mockito in a lot of cases.

Annotations have been structured a bit more.
- ImageIndex annotations will only include it's creation timestamp
- ImageIndex.manifests[] annotations will include package metadata
  we might need when listing/searching packages
- ImageManifest annotations will contain user-defined labels through
  `PyOci :: Label :: ` classifiers.

The `com.pyoci.sha256_digest` annotation is added containing the SHA256 digest
of the package blob.
This is a first step to make #160 work in an effective manner.

The SHA256 digest of the provided content is checked against the provided
`sha256_digest` in the request.
  • Loading branch information
AllexVeldman authored Jan 30, 2025
1 parent 6140d20 commit 968afe8
Show file tree
Hide file tree
Showing 9 changed files with 853 additions and 747 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ test-case = "3.3.1"
tokio = { version = "1.43.0", features = ["test-util"]}
bytes = "1.9.0"
reqwest = { version = "0.12.12", default-features = false, features = ["stream"] }
pretty_assertions = "1.4.1"
14 changes: 13 additions & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Packages published through PyOCI use the `application/pyoci.package.v1` [artifac
The image index gets tagged with the package version.
This allows multiple build artifacts to be published to the same package version.

`com.pyoci.sha256_digest` is added as an annotation in the `ImageIndex.manifests[]`
containing the digest of the package blob.
This is so we don't need to pull the manifest itself to get the digest of the package.

```json
{
"schemaVersion": 2,
Expand All @@ -22,7 +26,8 @@ This allows multiple build artifacts to be published to the same package version
"os": "any"
},
"annotations": {
"org.opencontainers.image.created":"2024-11-20T20:23:36Z"
"org.opencontainers.image.created":"2024-11-20T20:23:36Z",
"com.pyoci.sha256_digest": "b7513fb69106a855b69153582dec476677b3c79f4a13cfee6fb7a356cfa754c0"
}
}
],
Expand All @@ -34,6 +39,11 @@ This allows multiple build artifacts to be published to the same package version

## Image Manifest

When a package is published with `PyOci :: Label :: <key> :: <value>` classifiers,
the key/value pair will be added to the ImageManifest annotations.

'org.opencontainers.image.created' will always be added.

```json
{
"schemaVersion": 2,
Expand All @@ -52,6 +62,8 @@ This allows multiple build artifacts to be published to the same package version
}
],
"annotations": {
"org.opencontainers.image.description": "Published using PyOCI as part of the examples.",
"org.opencontainers.image.url": "https://github.com/allexveldman/pyoci",
"org.opencontainers.image.created":"2024-11-20T20:23:36Z"
}
}
Expand Down
Loading

0 comments on commit 968afe8

Please sign in to comment.