Repository navigation
Description
Supersedes #1200, which carried the original request and discussion. This issue restates it with an evaluation of the current state, so implementation can start from a settled design.
Request
Allow piping content straight into a push, without a temporary file:
tar -cz dir | sops --encrypt --input-type binary --output-type binary /dev/stdin \
| oras push localhost:5000/artifact:v1 -The pull side (oras pull --output -) was #346.
Feasibility
The library work that used to block this is done. oras-go v3.0.0, which the CLI already depends on, ships content.UnsafePusher. It computes the digest and size while writing. The remote repository (chunked upload, 8 MiB buffers), oci.Store (--oci-layout) and memory.Store all implement it.
What's left is CLI work, and three structural points make it more than adding a flag:
oras pushstages layers in a file store.runPushbuilds afile.Store,loadFilesadds every layer from a path, then the command packs a manifest and runsoras.Copyfrom a union of the memory and file stores.file.Storedoesn't implementUnsafePushand can't take a stream. The stdin layer has to go straight to the destination withUnsafePushbeforePackManifest, and its returned descriptor joins the layer list.CopyGraphchecks the destination first, so it skips that layer.- The progress wrappers hide the interface.
track.NewTargetwraps the destination ingraphTargetand variants, so a type check forcontent.UnsafePusherfails. The wrappers must forwardUnsafePush, or the stdin push uses the unwrapped target (no progress bar for that layer). - Stdin can only be read once. If a remote push fails midway there's no retry. Per the oras-go docs, the push fails outright when the registry doesn't support chunked uploads or advertises
OCI-Chunk-Min-Lengthabove 32 MiB.
Risks
- Registry compatibility is the main one: registries without chunked upload fail after stdin is consumed. Needs a clear error pointing to a temp-file workaround; an optional spool-to-temp fallback is worth considering.
- Size limit: oras-go's default cap is 4 GiB (
ErrSizeExceedsLimit); document it. - Stdin conflicts:
-with--password-stdin/--identity-token-stdinmust be rejected. Reuseoption.CheckStdinConflict, asblob pushandmanifest pushalready do. - Backward compatibility: low.
-is new syntax fororas push; fororas blob push, dropping the--size/digest requirement only loosens a check. A supplied digest must still be verified.
Proposed UX (to settle before coding)
- Name: require an explicit name (
--stdin-name <name>, or a title for"-"in--annotation-file) instead of silently defaulting tostdin.bin. A default can be added later without breaking anyone; removing one would be a breaking change. - Media type:
--stdin-media-type <type>, defaulting to the same layer media type used for files. This replaces the-:<type>form, which needs a--before it because pflag reads-:as a flag (oras push ref -- -:application/json). The--stdin-prefix pairs with--stdin-name; a--media-type-stdinspelling would wrongly suggest the media type itself is read from stdin, as--password-stdinreads the password. - Count:
-at most once, alongside any number of normal files. - Stdin is exclusive:
-cannot be combined with--password-stdinor--identity-token-stdin, since only one of them can consume stdin. Reject the combination up front withoption.CheckStdinConflict, before anything is read or pushed, asoras blob push -andoras manifest push -already do.
cat data.json | oras push localhost:5000/artifact:v1 - \
--stdin-name data.json --stdin-media-type application/jsonSuggested plan
oras blob pushfirst, as its own PR. When--sizeor the digest is missing, useUnsafePushand print the computed digest. Update the examples.oras push: pull-out of the file references beforeloadFiles; push it withUnsafePush(media type + title annotation,Size: -1, no digest); merge--annotation-fileannotations; add the descriptor to the layers; pack and copy as usual. Handle--dry-run(must not read stdin, or reject-) and--oci-layout.- Progress: add an
UnsafePushpassthrough to the track wrappers, or ship without progress for the stdin layer and follow up. - Tests:
- unit: parsing
-, conflict checks, name resolution, Windowsfilerefparsing - e2e: pipe into
oras pushthenoras pulland compare; stdin plus normal files;oras blob pushwith no--size; mismatched supplied digest fails;--oci-layouttarget;-with--password-stdinrejected; empty stdin (0-byte layer); stdin layer already present in the registry
- unit: parsing
Related code
| Location | Why |
|---|---|
cmd/oras/root/push.go (runPush, doPushCommand) |
file store setup, union source, pack and copy; the stdin layer goes here |
cmd/oras/root/file.go (loadFiles, addFile) |
title annotation and name resolution to reuse |
cmd/oras/root/blob/push.go |
current stdin path requiring --size |
internal/file/file.go (PrepareBlobContent) |
size/digest checks to relax |
cmd/oras/internal/display/status/track/target.go |
wrappers that hide UnsafePusher |
cmd/oras/internal/option/remote.go (CheckStdinConflict) |
stdin conflict check |
cmd/oras/internal/fileref/{unix,windows}.go |
path:mediaType parsing |
oras-go content/storage.go, registry/remote/unsafe.go |
UnsafePusher contract; chunked-upload requirement |
Tests: cmd/oras/root/push_test.go, cmd/oras/root/blob/push_test.go, internal/file/file_test.go, cmd/oras/internal/fileref/*_test.go, test/e2e/suite/command/{push,blob}.go |
existing coverage to extend |
@ShravanthReddy offered to take this in #1200 with a working branch, and the plan above is close to theirs. Feedback on the UX points is welcome here.
Activity