0

在基于詹金斯,码头工人和Artifactory的一个CI管道,我的分量建成,集装箱,然后刊登了以下id来artifactory的部署特定的神器版本AWS ECS:如何在没有硬编码的ID在Cloudformation模板

docker.artifacts.mycompany.com/my-component:{Unix时间戳}

詹金斯的最后一个阶段,然后还标记,神器与 “最新” 标签:

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?

例如为:docker.artifacts.mycompany.com/my-component:1500436061

回答

1

您需要使用参数覆盖以编程方式更改您的CloudFormation模板硬编码的默认值。

因此,例如,或许你的詹金斯打造了一个使用AWS CLI使用如下命令部署CF模板bash脚本:

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的参数覆盖的文档:http://docs.aws.amazon.com/cli/latest/reference/cloudformation/deploy/index.html

如果你是我们对于任何语言的AWS SDK,它也将具有参数覆盖能力。基本上,无论您用于以编程方式部署CF模板的机制,还可以指定一个参数重写,将默认值更改为该特定版本的自定义值。

相关问题