Skip to content

Commit 8206523

Browse files
lolgabcursoragent
andauthored
feat: add overwrite-only mode for ECR mirroring (#244)
Add a dedicated flag to mirror_to_ecr that updates an existing tag but fails when the target tag is missing in ECR. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4616a12 commit 8206523

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/jobs/mirror_to_ecr.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ parameters:
1919
description: If true then force mirroring the image even if it already exists in ECR
2020
type: boolean
2121
default: false
22+
overwrite_only_existing:
23+
description: If true then overwrite the image only when the target tag already exists in ECR. The job fails if the tag is missing.
24+
type: boolean
25+
default: false
2226
aws_profile:
2327
description: The AWS profile to be used
2428
type: string
@@ -67,7 +71,18 @@ steps:
6771
6872
echo "Mirroring ${SRC} to ${ECR_URL}/${MIRROR}..."
6973
REPO_DATA=$(aws ecr describe-images --repository-name=${MIRROR_NAME} --image-ids=imageTag=${MIRROR_TAG} ||: )
70-
if << parameters.force>> || [[ -z $REPO_DATA ]] ; then
74+
SHOULD_MIRROR=false
75+
if [[ -z $REPO_DATA ]] ; then
76+
if << parameters.overwrite_only_existing >> ; then
77+
echo "Mirror target ${MIRROR} does not exist in ECR and overwrite_only_existing is enabled."
78+
exit 1
79+
fi
80+
SHOULD_MIRROR=true
81+
elif << parameters.force >> || << parameters.overwrite_only_existing >> ; then
82+
SHOULD_MIRROR=true
83+
fi
84+
85+
if [[ "${SHOULD_MIRROR}" == "true" ]] ; then
7186
docker pull ${SRC}
7287
docker tag ${SRC} ${ECR_URL}/${MIRROR}
7388
docker push ${ECR_URL}/${MIRROR}

0 commit comments

Comments
 (0)