Skip to content

Commit

Permalink
testing bb4c2ec
Browse files Browse the repository at this point in the history
  • Loading branch information
tarilabs committed Sep 23, 2024
1 parent b710f56 commit 5921e38
Show file tree
Hide file tree
Showing 4 changed files with 554 additions and 341 deletions.
122 changes: 122 additions & 0 deletions demo-ghcrio-token.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:oras.logger:Preparing layer {'mediaType': 'application/vnd.oci.image.layer.v1.tar', 'size': 164, 'digest': 'sha256:7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516', 'annotations': {'org.opencontainers.image.title': 'artifact.txt'}}\n",
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): ghcr.io:443\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"POST /v2/tarilabs/demo20240629-oras147/blobs/uploads/ HTTP/11\" 401 120\n",
"DEBUG:oras.logger:requesting auth token\n",
"DEBUG:oras.logger:Service: ghcr.io\n",
"DEBUG:oras.logger:Scope: repository:tarilabs/demo20240629-oras147:pull\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"GET /token?service=ghcr.io&scope=repository%3Atarilabs%2Fdemo20240629-oras147%3Apull HTTP/11\" 200 69\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"POST /v2/tarilabs/demo20240629-oras147/blobs/uploads/ HTTP/11\" 202 0\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"PUT /v2/tarilabs/demo20240629-oras147/blobs/upload/81249a9b-be05-4403-a8d0-a29e1f1873c0?digest=sha256%3A7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516 HTTP/11\" 201 0\n",
"DEBUG:oras.logger:Preparing config {'mediaType': 'application/vnd.unknown.config.v1+json', 'size': 2, 'digest': 'sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a'}\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"POST /v2/tarilabs/demo20240629-oras147/blobs/uploads/ HTTP/11\" 202 0\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"PUT /v2/tarilabs/demo20240629-oras147/blobs/upload/6dd58b23-7cd9-42fc-8630-4fe3551b0b61?digest=sha256%3A44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a HTTP/11\" 201 0\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"PUT /v2/tarilabs/demo20240629-oras147/manifests/latest HTTP/11\" 201 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Successfully pushed ghcr.io/tarilabs/demo20240629-oras147:latest\n"
]
},
{
"data": {
"text/plain": [
"<Response [201]>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"import logging\n",
"\n",
"TRACE=False\n",
"if TRACE:\n",
" import http.client as http_client\n",
" http_client.HTTPConnection.debuglevel = 1\n",
"\n",
"logging.basicConfig()\n",
"logging.getLogger().setLevel(logging.DEBUG)\n",
"requests_log = logging.getLogger(\"requests.packages.urllib3\")\n",
"requests_log.setLevel(logging.DEBUG)\n",
"requests_log.propagate = True\n",
"\n",
"import oras.client\n",
"\n",
"client = oras.client.OrasClient()\n",
"# skipping client.login() for my ...: using already-stored credentials from ~/.docker/config.json\n",
"client.push(files=[\"artifact.txt\"], target=\"ghcr.io/tarilabs/demo20240629-oras147\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"GET /v2/tarilabs/demo20240629-oras147/manifests/latest HTTP/11\" 200 495\n",
"DEBUG:urllib3.connectionpool:https://ghcr.io:443 \"GET /v2/tarilabs/demo20240629-oras147/blobs/sha256:7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516 HTTP/11\" 307 0\n",
"DEBUG:urllib3.connectionpool:https://pkg-containers.githubusercontent.com:443 \"GET /ghcr1/blobs/sha256:7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516?se=2024-09-23T10%3A45%3A00Z&sig=R9fkb8mRtd9NfFlcvBOmfMP7VG23sTDkTkRkv2GhKAo%3D&sp=r&spr=https&sr=b&sv=2019-12-12 HTTP/11\" 200 164\n",
"INFO:oras.logger:Successfully pulled /Users/mmortari/git/demo20240629-oras147-testregistries/tmp/ghcrio/artifact.txt.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the content of the file artifact.txt\n",
"\n",
"Using this file just to store some asset as OCI artifact\n",
"\n",
"If you are seeing this, this is the content of artifact.txt\n"
]
}
],
"source": [
"!rm -rf tmp/ghcrio\n",
"client.pull(\"ghcr.io/tarilabs/demo20240629-oras147\", outdir=\"tmp/ghcrio\")\n",
"!cat tmp/ghcrio/artifact.txt"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "demo20240629-oras147-testregistries-Ja2Z1fe0-py3.10",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
90 changes: 70 additions & 20 deletions demo-quayio-token.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,51 @@
"text": [
"DEBUG:oras.logger:Preparing layer {'mediaType': 'application/vnd.oci.image.layer.v1.tar', 'size': 164, 'digest': 'sha256:7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516', 'annotations': {'org.opencontainers.image.title': 'artifact.txt'}}\n",
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): quay.io:443\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"POST /v2/mmortari/demo20240629-oras147/blobs/uploads/ HTTP/11\" 401 112\n",
"DEBUG:oras.logger:No Authorization, requesting anonymous token\n",
"DEBUG:oras.logger:Final params are {'service': 'quay.io', 'scope': 'repository:mmortari/demo20240629-oras147:pull,push'}\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"GET /v2/auth?service=quay.io&scope=repository%3Ammortari%2Fdemo20240629-oras147%3Apull%2Cpush HTTP/11\" 200 870\n",
"DEBUG:oras.logger:Successfully obtained anonymous token!\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"POST /v2/mmortari/demo20240629-oras147/blobs/uploads/ HTTP/11\" 401 112\n"
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"POST /v2/mmortari/demo20240629-oras147/blobs/uploads/ HTTP/11\" 401 40\n",
"DEBUG:oras.logger:requesting auth token\n",
"DEBUG:oras.logger:Service: quay.io\n",
"DEBUG:oras.logger:Scope: repository:mmortari/demo20240629-oras147:pull,push\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"GET /v2/auth?service=quay.io&scope=repository%3Ammortari%2Fdemo20240629-oras147%3Apull%2Cpush HTTP/11\" 200 1051\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"POST /v2/mmortari/demo20240629-oras147/blobs/uploads/ HTTP/11\" 202 0\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"PUT /v2/mmortari/demo20240629-oras147/blobs/uploads/b9cc12ad-eb58-454c-8276-e783f2465ccb?digest=sha256%3A7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516 HTTP/11\" 201 0\n",
"DEBUG:oras.logger:Preparing config {'mediaType': 'application/vnd.unknown.config.v1+json', 'size': 2, 'digest': 'sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a'}\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"POST /v2/mmortari/demo20240629-oras147/blobs/uploads/ HTTP/11\" 202 0\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"PUT /v2/mmortari/demo20240629-oras147/blobs/uploads/63d52796-9d5b-4889-a777-80ec95606283?digest=sha256%3A44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a HTTP/11\" 201 0\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"PUT /v2/mmortari/demo20240629-oras147/manifests/latest HTTP/11\" 201 2\n"
]
},
{
"ename": "ValueError",
"evalue": "Issue retrieving session url: {'errors': [{'code': 'UNAUTHORIZED', 'detail': {}, 'message': 'access to the requested resource is not authorized'}]}",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 8\u001b[0m\n\u001b[1;32m 6\u001b[0m client \u001b[38;5;241m=\u001b[39m oras\u001b[38;5;241m.\u001b[39mclient\u001b[38;5;241m.\u001b[39mOrasClient()\n\u001b[1;32m 7\u001b[0m \u001b[38;5;66;03m# skipping client.login() for my Quay.io: using already-stored credentials from ~/.docker/config.json\u001b[39;00m\n\u001b[0;32m----> 8\u001b[0m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpush\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43martifact.txt\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mquay.io/mmortari/demo20240629-oras147\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/demo20240629-oras147-testregistries-Ja2Z1fe0-py3.10/lib/python3.10/site-packages/oras/provider.py:762\u001b[0m, in \u001b[0;36mRegistry.push\u001b[0;34m(self, target, config_path, disable_path_validation, files, manifest_config, annotation_file, manifest_annotations, subject)\u001b[0m\n\u001b[1;32m 759\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPreparing layer \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlayer\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 761\u001b[0m \u001b[38;5;66;03m# Upload the blob layer\u001b[39;00m\n\u001b[0;32m--> 762\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupload_blob\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblob\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcontainer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlayer\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 763\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_200_response(response)\n\u001b[1;32m 765\u001b[0m \u001b[38;5;66;03m# Do we need to cleanup a temporary targz?\u001b[39;00m\n",
"File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/demo20240629-oras147-testregistries-Ja2Z1fe0-py3.10/lib/python3.10/site-packages/oras/provider.py:275\u001b[0m, in \u001b[0;36mRegistry.upload_blob\u001b[0;34m(self, blob, container, layer, do_chunked)\u001b[0m\n\u001b[1;32m 271\u001b[0m \u001b[38;5;66;03m# Chunked for large, otherwise POST and PUT\u001b[39;00m\n\u001b[1;32m 272\u001b[0m \u001b[38;5;66;03m# This is currently disabled unless the user asks for it, as\u001b[39;00m\n\u001b[1;32m 273\u001b[0m \u001b[38;5;66;03m# it doesn't seem to work for all registries\u001b[39;00m\n\u001b[1;32m 274\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m do_chunked:\n\u001b[0;32m--> 275\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mput_upload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblob\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcontainer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlayer\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 277\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mchunked_upload(blob, container, layer)\n",
"File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/demo20240629-oras147-testregistries-Ja2Z1fe0-py3.10/lib/python3.10/site-packages/oras/provider.py:523\u001b[0m, in \u001b[0;36mRegistry.put_upload\u001b[0;34m(self, blob, container, layer)\u001b[0m\n\u001b[1;32m 521\u001b[0m session_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_location(r, container)\n\u001b[1;32m 522\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m session_url:\n\u001b[0;32m--> 523\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIssue retrieving session url: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mr\u001b[38;5;241m.\u001b[39mjson()\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 525\u001b[0m \u001b[38;5;66;03m# PUT to upload blob url\u001b[39;00m\n\u001b[1;32m 526\u001b[0m headers \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 527\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mContent-Length\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mstr\u001b[39m(layer[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msize\u001b[39m\u001b[38;5;124m\"\u001b[39m]),\n\u001b[1;32m 528\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mContent-Type\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplication/octet-stream\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 529\u001b[0m }\n",
"\u001b[0;31mValueError\u001b[0m: Issue retrieving session url: {'errors': [{'code': 'UNAUTHORIZED', 'detail': {}, 'message': 'access to the requested resource is not authorized'}]}"
"name": "stdout",
"output_type": "stream",
"text": [
"Successfully pushed quay.io/mmortari/demo20240629-oras147:latest\n"
]
},
{
"data": {
"text/plain": [
"<Response [201]>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"import logging\n",
"logging.basicConfig(level=logging.DEBUG)\n",
"\n",
"TRACE=False\n",
"if TRACE:\n",
" import http.client as http_client\n",
" http_client.HTTPConnection.debuglevel = 1\n",
"\n",
"logging.basicConfig()\n",
"logging.getLogger().setLevel(logging.DEBUG)\n",
"requests_log = logging.getLogger(\"requests.packages.urllib3\")\n",
"requests_log.setLevel(logging.DEBUG)\n",
"requests_log.propagate = True\n",
"\n",
"import oras.client\n",
"\n",
Expand All @@ -47,10 +66,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rm: tmp/quayio: is a directory\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"GET /v2/mmortari/demo20240629-oras147/manifests/latest HTTP/11\" 200 495\n",
"DEBUG:urllib3.connectionpool:https://quay.io:443 \"GET /v2/mmortari/demo20240629-oras147/blobs/sha256:7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516 HTTP/11\" 302 2031\n",
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): cdn03.quay.io:443\n",
"DEBUG:urllib3.connectionpool:https://cdn03.quay.io:443 \"GET /quayio-production-s3/sha256/7f/7f52942f815315896486adb3dd78f80d31a3269292eea67cf09d49ec3593c516?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI5LUAQGPZRPNKSJA%2F20240923%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240923T103826Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=18fbe2d195b1856f0e4f564c802d733f9c4a91641d5c588c169129eca6b3eb90&cf_sign=Lg1i0fbdBVu0mjuKKWW0HgE6dbPBcw7zRaVpviEc48TW5vjYTs0rQZIkIdK1j%2BtdGQ184DdI1ZocIH%2F1%2Bhny0bet3j8zYNnVMIh3NrEzIntks7dSJ%2FqIcERfMPmhussuwMrv%2Fgw0CEFbPKnq2eZlz0n39GXqx3t3d%2BOnzzbksKfrry61EKyks8JsYX7Wxne9lUm039uGTKDZ1pC5GBmTy8tz0%2F8AX83JV3wN%2BgmoGsJd4Z4QUFdcwGkEJJESkxDEA2LtIGi5xpXVpHaoXS4%2BdN8le1G8k8lBpvbDSvwOQWezvD6CQvBhQlwhpdmhL2IWBMISlVF5pAO2gjUHyHZ9Gw%3D%3D&cf_expiry=1727088506&region=us-east-1&namespace=mmortari&username=mmortari%2Bdockerlogin&repo_name=demo20240629-oras147 HTTP/11\" 200 164\n",
"INFO:oras.logger:Successfully pulled /Users/mmortari/git/demo20240629-oras147-testregistries/tmp/quayio/artifact.txt.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the content of the file artifact.txt\n",
"\n",
"Using this file just to store some asset as OCI artifact\n",
"\n",
"If you are seeing this, this is the content of artifact.txt\n"
]
}
],
"source": [
"!rm tmp/quayio\n",
"client.pull(\"quay.io/mmortari/demo20240629-oras147\", outdir=\"tmp/quayio\")\n",
"!cat tmp/quayio/artifact.txt"
]
Expand Down
Loading

0 comments on commit 5921e38

Please sign in to comment.