Closed ruodingt closed 1 year ago
I was not able to re-create the error. See example below to list all repositories, all images and their corresponding size.
from google.cloud.artifactregistry import ArtifactRegistryClient, ListRepositoriesRequest
project = "<YOUR PROJECT>"
location = "<YOUR LOCATION>"
arc = ArtifactRegistryClient()
request = ListRepositoriesRequest(
parent=f"projects/{project}/locations/{location}",
)
# Make the request to list artifact registry repositories
paged_result = arc.list_repositories(request=request)
for repository in paged_result:
# Get docker images for each repository
images = arc.list_docker_images(parent=repository.name)
for image in images:
# For each image, get the size
image_details = arc.get_docker_image(name=image.name)
print(f"name: {image.name} size: {image_details.image_size_bytes}")
I'm going to close this issue but please feel free to open a new issue if you have additional questions.
I ran into this same error with the NodeJS client. The issue is that this API requires you to pass in name
in the form projects/kkk-x-xxx-build-prod-xxxxxx/locations/australia-southeast1/repositories/docker-registry-repository/dockerImages/abc-pipeline-flex@sha256:2dd6956aa4f462badb7aa445f73092b19e55e2be2c03bee4ec230700963b3f55
rather than the form you use the repository with Docker.
In addition, as far as I can tell, it only lets you pass in the sha, not a tag. If you want to look up by tag you have to use the completely separate get_tag
API, like arc.get_tag(name='projects/kkk-x-xxx-build-prod-xxxxxx/locations/australia-southeast1/repositories/docker-registry-repository/packages/abc-pipeline-flex/tags/latest')
, which will give you back and object with a "version" that you then need extract the SHA from in order to pass to get_docker_image in the format above.
@glasser Thanks! I used your comment above and managed to stumble through this awkward situation using the Go SDK. I eventually added to our internal documentation:
Most people expect to supply a Docker Registry URL like: docker://us-central1-docker.pkg.dev/gcp-project/myrepo/myapp:mytag@sha256:2dd6956aa4f462badb7aa445f73092b19e55e2be2c03bee4ec230700963b3f55
Instead, we have to construct a valid Name
in a different format for each of GetTagRequest
, ListDockerImagesRequest
and GetDockerImageRequest
operations. GetTag
response returns a Tag
. ListDockerImages
and GetDockerImage
responses are composed of DockerImage
objects.
GetDockerImage
RPC API requires you to pass in a Name in the format projects/%s/locations/%s/repositories/%s/packages/%s@%s
. For example:
projects/gcp-project/locations/us-central1/repositories/myrepo/packages/myapp@sha256:2dd6956aa4f462badb7aa445f73092b19e55e2be2c03bee4ec230700963b3f55
ListDockerImages
RPC API wants Name in the format projects/%s/locations/%s/repositories/%s
, for example:
projects/gcp-project/locations/us-central1/repositories/myrepo
GetTag
RPC API wants Name in the format projects/%s/locations/%s/repositories/%s/packages/%s/tags/%s
, for example:
projects/gcp-project/locations/us-central1/repositories/myrepo/packages/myapp:mytag
If you have a Docker URL with a Docker Tag without the Docker SHA256, you can use GetTag
and from that response extract the Version. Then you can pass that Version SHA256 to GetDockerImage
.
projects/gcp-project/locations/us-central1/repositories/myrepo/packages/myapp@sha256:2dd6956aa4f462badb7aa445f73092b19e55e2be2c03bee4ec230700963b3f55
I've found that GetDockerImage RPC API actually requires the name format to be
projects/gcp-project/locations/us-central1/repositories/myrepo/dockerImages/myapp@sha256:2dd6956aa4f462badb7aa445f73092b19e55e2be2c03bee4ec230700963b3f55
Hi team,
I am trying to use python client to fetch metadata (like image size) of a docker images with
arc.get_docker_image
.I am expecting the following code could work:
However I got error:
Please give me some idea how to fetch the image size with program.