아래는 AWS CLI를 사용하여 모든 Amazon ECR 리포지토리를 조회한 후 각 리포지토리의 이미지 태그 변경 가능성(Image Tag Mutability)을 MUTABLE로 설정하는 예제 Bash 스크립트다.

#!/bin/bash
# 이 스크립트는 모든 Amazon ECR 리포지토리를 가져와 이미지 태그 변경 가능성을 MUTABLE로 설정한다.

repositories=$(aws ecr describe-repositories –query “repositories[].repositoryName” –output text)

if [ -z “$repositories” ]; then echo “ECR 리포지토리를 찾을 수 없습니다.” exit 1 fi

for repo in $repositories; do echo “리포지토리 $repo의 이미지 태그 변경 가능성을 MUTABLE로 설정 중” aws ecr put-image-tag-mutability –repository-name “$repo” –image-tag-mutability MUTABLE | tee

if [ $? -eq 0 ]; then echo “$repo 업데이트 성공” else echo “$repo 업데이트 실패” fi done

설명

  • 리포지토리 조회: aws ecr describe-repositories로 JMESPath 쿼리를 사용하여 리포지토리 이름 목록 조회.
  • 리포지토리 없음 확인: $repositories 변수가 비어 있으면 메시지와 함께 종료.
  • 루프 및 변경 가능성 업데이트: 각 리포지토리 이름에 대해 aws ecr put-image-tag-mutability 호출.

이 스크립트는 모든 리포지토리가 이미지 태그에 대해 MUTABLE임을 보장하는 프로세스를 자동화하여 향후 업데이트나 태깅 변경을 가능하게 한다.