Pastebin using ORAS
31 May, 2024 - Tags: oras
Pastebin using ORAS
With new release of ORAS, I was playing with it and I realized that using ORAS combined with Compatible OCI Registries can be a really good pastebin service.
The only requirement is that you and the other person both should be using ORAS.
We will go directly into examples:
sharing files
Many a time, I redirect the logs of pod (container to be specific) to a file called logs.txt
using the command kubectl -n kube-system logs kube-apiserver-kind-control-plane > logs.txt
Now, if something is breaking there and If I want to share it with someone then I'll copy the content of the file using my editor and then paste it to online chat groups.
Sometimes, chat groups complains about having too many lines and they don't support more than x amount of lines.
I think to avoid these all hurdles, we can use oras directly and it's simple.
You can push your logs file to the registry using the following command:
$ oras push ghcr.io/kranurag7/pastebin-testing:v1 logs.txt
✓ Uploaded application/vnd.oci.empty.v1+json 2/2 B 100.00% 843ms
└─ sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a
✓ Uploaded logs.txt 13.9/13.9 kB 100.00% 909ms
└─ sha256:d46db609f9c8e92ad78d50e05cf9a04110683c566aa0c24f6f2a1b43304e8f7c
✓ Uploaded application/vnd.oci.image.manifest.v1+json 590/590 B 100.00% 400ms
└─ sha256:f21586e58085d0d2bfdbff57365cd99fd96c9329ef35c9196d0734c3ab3996ba
Pushed [registry] ghcr.io/kranurag7/pastebin-testing:v1
ArtifactType: application/vnd.unknown.artifact.v1
Digest: sha256:f21586e58085d0d2bfdbff57365cd99fd96c9329ef35c9196d0734c3ab3996ba
Anyone can pull it using the command:
$ oras pull ghcr.io/kranurag7/pastebin-testing:v1
✓ Pulled logs.txt 13.9/13.9 kB 100.00% 4ms
└─ sha256:d46db609f9c8e92ad78d50e05cf9a04110683c566aa0c24f6f2a1b43304e8f7c
✓ Pulled application/vnd.oci.image.manifest.v1+json 590/590 B 100.00% 71µs
└─ sha256:f21586e58085d0d2bfdbff57365cd99fd96c9329ef35c9196d0734c3ab3996ba
Pulled [registry] ghcr.io/kranurag7/pastebin-testing:v1
Digest: sha256:f21586e58085d0d2bfdbff57365cd99fd96c9329ef35c9196d0734c3ab3996ba
$ ls
logs.txt
$ head -n 5 logs.txt
I0531 02:16:56.713095 1 options.go:222] external host was not specified, using 172.18.0.2
I0531 02:16:56.713907 1 server.go:148] Version: v1.29.2
I0531 02:16:56.713931 1 server.go:150] "Golang settings" GOGC="" GOMAXPROCS="" GOTRACEBACK=""
I0531 02:16:57.074027 1 shared_informer.go:311] Waiting for caches to sync for node_authorizer
I0531 02:16:57.076576 1 plugins.go:157] Loaded 12 mutating admission controller(s) successfully in the following order: NamespaceLifecycle,LimitRanger,ServiceAccount,NodeRestriction,TaintNodesByCondition,Priority,DefaultTolerationSeconds,DefaultStorageClass,StorageObjectInUseProtection,RuntimeClass,DefaultIngressClass,MutatingAdmissionWebhook.
One can quickly analyze the logs just by running one pull command. Best thing is that they can do it on their terminal using their favourite text editor and search tools (rg, grep etc.)
sharing multiple files is also possible, just append more files as argument to push command.
sharing directories
Many a times, you want to share complete directories that contains logs from several components.
To demonstrate let's use the following command:
$ kubectl cluster-info dump --output-directory=manifests -oyaml
Cluster info dumped to manifests
$ tree manifests/ -L 1
manifests/
├── default
├── kube-system
└── nodes.yaml
2 directories, 1 file
Above command dumps all the manifests from all the components in manifests directory.
Now, I want to store it in registry and share it with someone. You can use the following command to do that:
$ oras push ghcr.io/kranurag7/pastebin-testing:manifests-v1 manifests/
✓ Exists application/vnd.oci.empty.v1+json 2/2 B 100.00% 0s
└─ sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a
✓ Uploaded manifests 25.8/25.8 kB 100.00% 863ms
└─ sha256:9866fbaa916f5e8c207c5ab36bbc27cbdd4fd8963d244e06155ee7f210aac26b
✓ Uploaded application/vnd.oci.image.manifest.v1+json 737/737 B 100.00% 317ms
└─ sha256:bcbb657c31326bb4bc135889d43a5b3ebc70eb73ca0191002ad2e01d1dbb73da
Pushed [registry] ghcr.io/kranurag7/pastebin-testing:manifests-v1
ArtifactType: application/vnd.unknown.artifact.v1
Digest: sha256:bcbb657c31326bb4bc135889d43a5b3ebc70eb73ca0191002ad2e01d1dbb73da
One can pull it using the following command:
$ oras pull ghcr.io/kranurag7/pastebin-testing:manifests-v1
✓ Pulled manifests 25.8/25.8 kB 100.00% 2ms
└─ sha256:9866fbaa916f5e8c207c5ab36bbc27cbdd4fd8963d244e06155ee7f210aac26b
✓ Pulled application/vnd.oci.image.manifest.v1+json 737/737 B 100.00% 0s
└─ sha256:bcbb657c31326bb4bc135889d43a5b3ebc70eb73ca0191002ad2e01d1dbb73da
Pulled [registry] ghcr.io/kranurag7/pastebin-testing:manifests-v1
Digest: sha256:bcbb657c31326bb4bc135889d43a5b3ebc70eb73ca0191002ad2e01d1dbb73da
$ tree manifests/ -L 1
manifests/
├── default
├── kube-system
└── nodes.yaml
3 directories, 1 file
The benefit here is that this workflow this much better than archiving a directory and then sharing it with someone. The other person have to download it and then unarchive to see the content. I'm not counting moving directories here.
I generally checkout these files in /tmp
directory and I've an alias set in my terminal which is gtmp
(called as go to /tmp directory)
The command behind alias is following:
cd $(mktemp --directory --tmpdir demo_XXXXXX)
This helps me quickly checkout random files or download something archives from the internet, unarchive it and move the relevant executable to somewhere else.
That's all. I will write more if I find something more interesting.