0

so far in my buildspec.yml file I can create a docker image and store it in the ECR repository (I am using codepipeline). My question is how do I deploy it to my ECS instance through the buildspec.yml using the aws cli commands?

4

1 回答 1

0

我正在共享buildspec.yaml文件看看

version: 0.1
phases:
  pre_build:
    commands:
      - echo Setting timestamp for container tag
      - echo `date +%s` > timestamp
      - echo Logging into Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
  build:
    commands:
      - echo Building and tagging container
      - docker build -t $REPOSITORY_NAME .
      - docker tag $REPOSITORY_NAME $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$REPOSITORY_NAME:$BRANCH-`cat ./timestamp`
  post_build:
    commands:
      - echo Pushing docker image
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$REPOSITORY_NAME:$BRANCH-`cat ./timestamp`
      - echo Preparing CloudFormation Artifacts
      - aws s3 cp s3://$ECS_Bucket/$ECS_SERVICE_KEY task-definition.template
      - aws s3 cp s3://$ECS_Bucket/$ECS_SERVICE_PARAMS_KEY cf-config.json
artifacts:
  files:
    - task-definition.template
    - cf-config.json

您可以为 ECS 实例编辑此更多命令,我有返回模板用于云形成。

您可以编写简单的 awscli 命令来创建集群并拉取图像检查此 aws 文档:https ://docs.aws.amazon.com/cli/latest/reference/ecs/index.html

分享我自己的 git 查看更多信息:https ://github.com/harsh4870/ECS-CICD-pipeline

于 2019-03-12T04:45:07.010 回答