components/llm_service/notebooks/ArtifactRegistry.ipynb (263 lines of code) (raw):
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "955712fc-37ba-4643-a440-ee18d2a51f00",
"metadata": {},
"outputs": [],
"source": [
"PROJECT_ID = \"test-genie-install4\"\n",
"REGION = \"us-central1\"\n",
"import os\n",
"os.environ[\"PROJECT_ID\"] = PROJECT_ID\n",
"os.environ[\"PG_HOST\"] = \"\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e36fa893-da7e-4bff-b6a7-a9850d48a739",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../../common/src\")\n",
"sys.path.append(\"../src\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "12518458-c74b-4874-95be-d9e803d80342",
"metadata": {},
"outputs": [],
"source": [
"from google.cloud import artifactregistry_v1\n",
"from google.cloud.artifactregistry_v1 import ListTagsRequest"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "ddb59aa7-c6f6-4808-92b5-dc7b3657bd3a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your browser has been opened to visit:\n",
"\n",
" https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login&state=2DhOxQAX0wTfh0WBoHDgYVpXX10b4H&access_type=offline&code_challenge=ffIDQbfSPnV5GShufa6BOKkQBs8lnHgxCEpie7ppRxc&code_challenge_method=S256\n",
"\n",
"\n",
"Credentials saved to file: [/Users/lramsey/.config/gcloud/application_default_credentials.json]\n",
"\n",
"These credentials will be used by any library that requests Application Default Credentials (ADC).\n",
"\n",
"Quota project \"test-genie-install4\" was added to ADC which can be used by Google client libraries for billing and quota. Note that some services may still bill the project owning the resource.\n"
]
}
],
"source": [
"!gcloud auth application-default login"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "434566fb-417d-4b8b-af81-feadaa4478d8",
"metadata": {},
"outputs": [],
"source": [
"client = artifactregistry_v1.ArtifactRegistryClient()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "751b9faa-199a-4415-af6c-b438657a7e12",
"metadata": {},
"outputs": [],
"source": [
"project_id = \"test-genie-install4\"\n",
"location = \"us\"\n",
"repository = \"default\"\n",
"package_name = \"webscraper\"\n",
"image_name = \"us-docker.pkg.dev/test-genie-install4/default/webscraper:v0.3.2-412-gc9f60f0d-dirty\""
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "6b28dbe7-6c84-4dae-ac8b-59a1ef401d9c",
"metadata": {},
"outputs": [],
"source": [
"parent = client.package_path(project_id, location, repository, package)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "ee8b7b4a-b440-4d93-9b63-0bc146cdcdcf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'projects/test-genie-install4/locations/us/repositories/default/packages/webscraper'"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"parent"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "3f7a6326-a188-415e-b135-22b02ca58382",
"metadata": {},
"outputs": [],
"source": [
"request = ListTagsRequest(\n",
" parent=parent\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "82198b63-46ea-4985-b379-fbe7f6cf8c78",
"metadata": {},
"outputs": [],
"source": [
"tags = client.list_tags(request)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "486d11c1-76d2-403f-a3e2-3f1180bcc4b2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ListTagsPager<tags {\n",
" name: \"projects/test-genie-install4/locations/us/repositories/default/packages/webscraper/tags/v0.3.2-412-gc9f60f0d-dirty\"\n",
" version: \"projects/test-genie-install4/locations/us/repositories/default/packages/webscraper/versions/sha256:51d963428ff697497b5287578ebbcdfd2527c4af35619772fbeca664bab28a9d\"\n",
"}\n",
">"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tags"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "ff1aec3b-d660-4703-8b30-d2f1ad66936c",
"metadata": {},
"outputs": [],
"source": [
"latest_tag = None\n",
"latest_version = None\n",
"\n",
"for tag in tags:\n",
" if tag.version:\n",
" if not latest_version or tag.version > latest_version:\n",
" latest_tag = tag\n",
" latest_version = tag.version"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "1b5c93d5-970c-4075-bc85-48e6265f613e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"name: \"projects/test-genie-install4/locations/us/repositories/default/packages/webscraper/tags/v0.3.2-412-gc9f60f0d-dirty\"\n",
"version: \"projects/test-genie-install4/locations/us/repositories/default/packages/webscraper/versions/sha256:51d963428ff697497b5287578ebbcdfd2527c4af35619772fbeca664bab28a9d\""
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"latest_tag"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "7735c719-9615-464e-965f-47e60fd6b088",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'project': 'test-genie-install4',\n",
" 'location': 'us',\n",
" 'repository': 'default',\n",
" 'package': 'webscraper',\n",
" 'tag': 'v0.3.2-412-gc9f60f0d-dirty'}"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.parse_tag_path(latest_tag.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ea21509-51a9-4056-bd9e-186299bc0a59",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}