AWS ECR图像列表

时间:2016-11-30 07:32:30

标签: amazon-web-services docker amazon-ec2

我有一个ECR存储库设置,它现在包含两个带有顺序标签1和2的图像。我打算从此时开始自动推送docker镜像,我的要求是当我下次推送图像时,它的标签应该是3,所以我必须以某种方式确定下一个数字应该是3,因为最新版本是2.我不想在本地保留这个版本。所以我需要来自ECR本身的这些信息。有什么想法吗?以下命令将给出存储库中所有图像的列表

aws ecr list-images 

2 个答案:

答案 0 :(得分:5)

感谢@Matt指出jq。安装jq后,以下命令将提供最新版本

aws ecr list-images --repository-name REPOSITORY_NAME | jq '.imageIds | map (.imageTag)|sort|.[]' | sort -r | head -1

答案 1 :(得分:1)

ECR ListImages API端点将列出存储库中的所有图像shasums和任何关联的标记。您也可filter向下TAGGEDconst _ = require('lodash') const Promise = require('bluebird') const AWS = require('aws-sdk') let config = { region: 'us-west-1', repo = 'myrepo' } const ecr = new AWS.ECR({region: config.region}) Promise.promisifyAll(ecr) ecr.listImagesAsync({ repositoryName: config.repo, filter: { tagStatus: 'TAGGED'} }) .then( data => { let img = _(data.imageIds).sortBy('imageTag').last() console.log(img.imageTag) })

它有一个Java SDK(但我不会用Java来处理,因此赢了很多帮助)。

Node.js Javascript非常简单,对返回的对象/数组/对象进行了一些lodash链处理。

npm init -y && npm install aws-sdk lodash bluebird --save

您可以使用

在当前目录中安装脚本的依赖项
aws ecr list-images

如果要处理shell中的.notification-wrapper { position: relative; left: -10px; font-size: 17px; line-height: 1.47; letter-spacing: 0.6px; } #notification-block { height: 150px; border-radius: 5px; margin: 60px 10px 5px 10px; background-color: #ffffff; } #notification-block h2 { margin-top: 45px; } #notification-block img { margin-top: 50px; } .notification-message { white-space: normal !important; } .read-more, .read-more a { float: right; font-weight: bold !important; font-size: 16px !important; color: black !important; text-decoration: none !important; }输出,请尝试jq

相关问题