Amazon web services 如何将特定工件版本部署到AWS ECS,而无需在Cloudformation模板中硬编码其id
在基于Jenkins、Docker和Artifactory的CI管道中,我的组件被构建、容器化,然后以以下id发布到Artifactory: docker.artifacts.mycompany.com/my组件:{Unix timestamp} Jenkins的最后一个阶段还使用“最新”标记标记该工件: docker.artifacts.mycompany.com/my component:latest 通过此Cloudformation模板,此标记允许AWS ECS拾取工件(标记为“最新”)并进行部署:Amazon web services 如何将特定工件版本部署到AWS ECS,而无需在Cloudformation模板中硬编码其id,amazon-web-services,jenkins,continuous-integration,amazon-cloudformation,amazon-ecs,Amazon Web Services,Jenkins,Continuous Integration,Amazon Cloudformation,Amazon Ecs,在基于Jenkins、Docker和Artifactory的CI管道中,我的组件被构建、容器化,然后以以下id发布到Artifactory: docker.artifacts.mycompany.com/my组件:{Unix timestamp} Jenkins的最后一个阶段还使用“最新”标记标记该工件: docker.artifacts.mycompany.com/my component:latest 通过此Cloudformation模板,此标记允许AWS ECS拾取工件(标记为“最新”)
Parameters:
SourceInstanceRole:
Type: String
Description: The IAM role that the my-component instance will use
Default: Jenken-Automation
ImageRepository:
Type: String
Description: The name of the Docker repository which holds my-component Docker images
Default: docker.artifacts.mycompany.com
ImageName:
Type: String
Description: The name of the Docker image for my-component
Default: my-component
ImageVersion:
Type: String
Description: The version tag of my-component docker image in Artifactory
Default: latest
MyComponentTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Volumes:
- Name: no-volume
ContainerDefinitions:
- Name: !Ref ContainerName
Essential: true
Memory: !Ref Memory
MemoryReservation: !Ref MemoryReservation
Image: !Sub ${ImageRepository}/${ImageName}:${ImageVersion}
我需要远离这种方法,因为我希望能够指定用于部署的工件的任何版本,而不是“最新版本”。我的问题是:
如果不在Cloudformation模板中对映像版本进行硬编码,如何触发将特定工件版本部署到ECS?
e、 g.:docker.artifacts.mycompany.com/my component:1500436061您需要使用参数覆盖以编程方式更改CloudFormation模板中硬编码的默认值 例如,您的Jenkins构建可能有一个bash脚本,它使用AWS CLI使用以下命令部署CF模板:
aws cloudformation deploy --template-file mystack.yml --stack-name mystack
您可以为ImageVersion
变量指定替代,如下所示:
aws cloudformation deploy --template-file mystack.yml --stack-name mystack --parameter-overrides ImageVersion={Unix timestamp}
以下是使用CLI进行参数覆盖的文档:
如果您将AWS SDK用于任何语言,它也将具有参数覆盖功能。基本上,无论您使用何种机制以编程方式部署CF模板,都可以指定一个参数覆盖,将默认值更改为特定版本的自定义值