ECR Docker image Push Auto Scan

Hoju·2022년 8월 25일
0
post-custom-banner
version: 0.2

phases:
  install:
    commands:
      - pip3 uninstall -y awscli
      - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
      - unzip awscliv2.zip
      - sudo ./aws/install -i /usr/local/aws-cli -b /usr/local/bin --update
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - ECR_REPO=wsi-ecr-repo
      - REPOSITORY_URI=680360122082.dkr.ecr.ap-northeast-2.amazonaws.com/wsi-ecr-repo
      - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 680360122082.dkr.ecr.ap-northeast-2.amazonaws.com
  build:
    commands:
      - docker build -t wsi-ecr-repo:master .
      - docker tag wsi-ecr-repo:master 680360122082.dkr.ecr.ap-northeast-2.amazonaws.com/wsi-ecr-repo:master
  post_build:
    commands:
      - docker push $REPOSITORY_URI:master
      - printf '[{"name":"wsi-master-container","imageUri":"%s"}]' $REPOSITORY_URI:master > imagedefinitions.json
      - IMAGE_TO_TAGGED=$( aws ecr list-images --region ap-northeast-2 --repository-name $ECR_REPO --filter "tagStatus=TAGGED" --query 'imageIds[*]' --output text | awk '{print $1}' )
      - aws ecr start-image-scan --repository-name $ECR_REPO --image-id imageDigest=$IMAGE_TO_TAGGED --region ap-northeast-2
artifacts:
    files:
      - imagedefinitions.json
profile
Devops가 되고 싶은 청소년
post-custom-banner

0개의 댓글