我在Amazon ECS(Amazon EC2 Container Registry)中运行了一个docker镜像。 docker镜像路径在任务定义中定义。
现在,在对代码进行编辑之后,Jenkins自动构建新映像并将其推送到Amazon存储库注册表,然后根据内部版本号获取新的PATH。
新网址就像
1234.dkr.ecr.ap-southeast-1.amazonaws.com/csr:13
旧网址就像
1234.dkr.ecr.ap-southeast-1.amazonaws.com/csr:12
现在我希望 Jenkins在CLI中运行一些命令告诉ECS有一个新图像应该在EC2实例上而不是旧版本上运行。
我正在阅读AWS CLI documentation,我遇到了aws ecs register-task-definition
和aws ecs run-task
等命令,但我不确定。
我不知道devops是如何做到这一点的?什么是正确的方法? 请帮忙。
一个简单的任务定义如下所示:
{
"networkMode": "bridge",
"taskRoleArn": null,
"containerDefinitions": [
{
"volumesFrom": [],
"memory": 512,
"extraHosts": [],
"linuxParameters": {
"capabilities": {
"add": null,
"drop": null
},
"devices": null,
"initProcessEnabled": null
},
"dnsServers": [],
"disableNetworking": null,
"dnsSearchDomains": [],
"portMappings": [
{
"hostPort": 9000,
"containerPort": 9000,
"protocol": "tcp"
},
{
"hostPort": 3306,
"containerPort": 3306,
"protocol": "tcp"
},
{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
},
{
"hostPort": 443,
"containerPort": 443,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": [],
"mountPoints": [],
"name": "phpfpm-nginx",
"ulimits": [],
"dockerSecurityOptions": [],
"environment": [
{
"name": "ERRORS",
"value": "1"
},
{
"name": "WEBROOT",
"value": "/data/www/public_html/"
}
],
"links": [],
"workingDirectory": null,
"readonlyRootFilesystem": false,
"image": "1234.dkr.ecr.ap-southeast-1.amazonaws.com/csr:13",
"command": [],
"user": null,
"dockerLabels": {},
"logConfiguration": null,
"cpu": 0,
"privileged": false,
"memoryReservation": null
}
],
"volumes": [],
"family": "ecscompose-CSR",
"placementConstraints": []
}