是否可以使用特定的 docker 标签从 ECR 获取最新的映像,该标签从开发开始,如
developXXX
?
我可以通过以下方式查看存储库中的最新图像:
aws ecr describe-images --repository-name reponame --output text --region eu-west-1 --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | tr '\t' '\n' | tail -1
从所有获取的图像中匹配“开发”关键字并使用
tail -1
返回最新的图像。
aws ecr describe-images --repository-name reponame --output text --region eu-west-1 --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | grep -w "develop" | tail -1
您可以在
grep -w "develop"
部分更改适合您情况的逻辑
此查询将获取带有包含“develop”标签的最新图像。
--query 'reverse(sort_by(imageDetails, &imagePushedAt)).[[?imageTags[?contains(@,`develop`)]].[imagePushedAt,imageDigest,imageTags][0]]'
首先,它会进行排序,因此最近推送的图像位于第一个,然后选择带有包含“develop”标签的图像,然后选择第一个结果。如果它对您有用,您可能只想返回
imageDigest
并添加 --output text --no-paginate
,这样您只需获取字符串形式的 ID。