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:
- 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
- IMAGES_TO_DELETE=$( aws ecr list-images --region ap-northeast-2 --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )
- aws ecr batch-delete-image --region ap-northeast-2 --repository-name $ECR_REPO --image-ids "$IMAGES_TO_DELETE" || true
artifacts:
files:
- imagedefinitions.json