Skip to content

support --output - to pull to stdout #346

Closed as duplicate
Closed as duplicate

Description

@ndeloof

My use case is to rely on oras CLI to restore a data cache, stored as tar.gz
on pull, I'd like to pipe directly the downloaded artifact to tar xz

Activity

  1. SteveLasker commented on Jan 14, 2022

    @SteveLasker
    Contributor

    Looks super interesting. Please open a PR for the proposal.

  2. added
    help wanted
    on Apr 19, 2022
  3. shizhMSFT commented on May 7, 2022

    @shizhMSFT
    Contributor

    This is an interesting one. How would you handle multiple files?

  4. FeynmanZhou commented on Aug 31, 2022

    @FeynmanZhou
    Member

    restore a data cache

    Hi @ndeloof ,

    Could you pls elaborate more on your use case?

    Actually, ORAS CLI v0.15 will provide oras manifest fetch and oras blob fetch that might meet your need. You can check out this doc for details.

  5. added this to the future milestone on Sep 7, 2022
  6. TerryHowe commented on Dec 5, 2022

    @TerryHowe
    Member

    Seems like the output of this should be a tgz so multiple files can be supported

  7. shizhMSFT commented on Mar 15, 2023

    @shizhMSFT
    Contributor

    One UX can be: oras pull localhost:5000/json-artifact:v1 --output - | jq and oras returns error if there are multiple blobs associated with the target manifest.

  8. modified the milestones: future, v1.1.0 on Mar 22, 2023
  9. modified the milestones: v1.1.0, v1.2.0 on Mar 22, 2023
  10. 15 remaining items

  11. qweeah commented on Nov 29, 2023

    @qweeah
    Contributor

    Before upload any blob to a registry, the digest must be specified.
    Unless you can get the digest before archiving is done, Otherwise it's not possible to do the streamed uploading.

    In order to circumvent this oras could buffer the input stream in memory until for example 64MiB and if this threshold has been reached oras pauses reading new input and first writes the 64MiB into a temporary file with narrow access rights and then resumes reading from the input and directly pipe it into the file. After reaching the EOF oras could calculate the digest either from the in memory buffer or if the content was too large from the file, pack it, and upload the image.

    The buffering in memory would only be for performance (and security) reasons, but would mostly be a nice to have feature.

    It's not sth oras can circumvent, you cannot get the checksum of the blob before tar finishes writing

  12. ProbstDJakob commented on Nov 29, 2023

    @ProbstDJakob

    I know that is why I proposed the solution with buffering/writing to a temporary file. Thus the calculation of the digest can be done after tar finishes without the need of creating/deleting a temporary file by oneself and therefore support streaming.

  13. qweeah commented on Nov 29, 2023

    @qweeah
    Contributor

    Yes, the digest calculation can be done while packing and this optimization has already been applied in oras-go.

    The question is after getting the digest, oras CLI still need to go through the archive file to upload it.

  14. ProbstDJakob commented on Dec 10, 2023

    @ProbstDJakob

    Sorry for the late response. Maybe I do not know enough about how oras works, but wouldn't the proposed solution be equivalent to supplying files as arguments but instead of including the files from the arguments the only file to include is the buffer/temporary file?

    Maybe the following pseudo script will help you understand my suggestion:

    uint8[64MiB] buffer;
    
    read(into=buffer, from=stdin);
    Readable inputData;
    
    if (peek(stdio) == EOF) {
      inputData = buffer;
    else {
      File tmpFile = tmpFileCreate();
      write(to=tmpFile, from=buffer);
      readAll(into=tmpFile, from=stdin);
    
      seek(origin=START, offset=0, file=tmpFile);
      inputData = tmpFile;
    }
    
    call oras push registry.example:5000 inputData # Yes the CLI is not able to accept buffers, but I hope you get what I intend to say
  15. qweeah commented on Dec 11, 2023

    @qweeah
    Contributor

    @ProbstDJakob Besides from the seek operation, what you described is already implemented in here.

    P.S. I think this discussion has gone too far from this issue and I have created #1200 so we can continue there.

  16. ProbstDJakob commented on Dec 11, 2023

    @ProbstDJakob

    The following script is a real world example where streaming could come in handy.

    Background

    We fully manage the life cycle of an OpenShift cluster via a GitLab Pipeline. When creating a cluster with the openshift-install tool some files like terraform state and kube-configs will be created. Those files are needed during the whole life cycle of the cluster (not only in the current pipeline), thus they need to be stored persistently. In our case we use the existing GitLab registry and oras to create an image.

    Current way to pull the artifacts from the registry

    #!/usr/bin/env sh
    set -eu
    
    # [...] some preparations
    
    tempDir="$(mktemp -d)"
    oras pull --output "$tempDir" "$ENCRYPTED_OPENSHIFT_INSTALL_ARTIFACTS_IMAGE"
    sops --decrypt --input-type binary --output-type binary "$tempDir/openshift-install-artifacts.tar.gz.enc" \
      | tar -xzC "$CI_PROJECT_DIR"
    rm -rf "$tempDir"

    Possible way to pull the artifacts from the registry with pipelining

    #!/usr/bin/env sh
    set -eu
    
    # [...] some preparations
    
    oras pull --output - "$ENCRYPTED_OPENSHIFT_INSTALL_ARTIFACTS_IMAGE" \
      | sops --decrypt --input-type binary --output-type binary /dev/stdin \
      | tar -xzC "$CI_PROJECT_DIR"

    This way there is no need to create a temporary directory and to know how the file is called within the image (not a problem for us since we named it within the same repo).

    Counterpart

    See #1200 (comment)

  17. Horiodino commented on Jan 21, 2025

    @Horiodino
    Contributor

    Hi, if no one is working on it, I’d like to take it on. Is it still open?

  18. TerryHowe commented on Jan 22, 2025

    @TerryHowe
    Member

    It is assigned to @yizha1 and @shizhMSFT although I don't think either of them is working on this.

  19. shizhMSFT commented on Jan 22, 2025

    @shizhMSFT
    Contributor

    @Horiodino Thanks for showing the interests. Please propose a design before heading to any implementations.

  20. DerRockWolf commented on Sep 26, 2026

    @DerRockWolf

    Something that might also be helpful in this context is allowing the user to specify the mediaType in the pull command so that oras can return a proper error instead of the application where the output is piped into returning hard to understand errors or just crashing.

    Or should that be the job of the artifactType (via the +type suffix perhaps?)? To be honest, when thinking about it right now I never fully understood what artifactType should communicate and what should be handled by the mediaType in the layers list 🤔

  21. TerryHowe commented on Sep 28, 2026

    @TerryHowe
    Member

    @DerRockWolf Layer mediaType is the one you want. artifactType sits on the manifest and says what the artifact as a whole is for — it is the referrers filter key (oras discover --artifact-type) and says nothing about blob encoding. mediaType sits on each layers[] descriptor and says how those particular bytes are encoded, which is what the <file>[:<type>] suffix sets on oras push.

    So "fail cleanly instead of feeding garbage into tar" is a layer-mediaType assertion, and oras manifest fetch --media-type is the precedent for the flag shape.

    I have summarized this and the other open design questions from this thread, with a concrete approach, in #2197.

  22. TerryHowe commented on Oct 22, 2026

    @TerryHowe
    Member

    Closing in favor of #2197, which collects the open design questions from this thread and proposes a design for oras pull --output -. Please continue the discussion there. Streaming push from stdin is tracked in #1200.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementquestion

    Type

    No type

    Projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions