Skip to content

Commit 4cf7ab4

Browse files
authored
Merge pull request #571 from ShelbyZ/sync-stable
Rework sync_latest_image to handle stable tag
2 parents 7026fea + 96c9e49 commit 4cf7ab4

File tree

1 file changed

+35
-46
lines changed

1 file changed

+35
-46
lines changed

scripts/publish.sh

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ check_parameter() {
251251
fi
252252
}
253253

254+
sync_public_and_repo() {
255+
region=${1}
256+
account_id=${2}
257+
endpoint=${3}
258+
tag=${4}
259+
260+
docker pull public.ecr.aws/aws-observability/aws-for-fluent-bit:${tag}
261+
sha1=$(docker inspect --format='{{index .RepoDigests 0}}' public.ecr.aws/aws-observability/aws-for-fluent-bit:${tag})
262+
aws ecr get-login-password --region ${region}| docker login --username AWS --password-stdin ${account_id}.dkr.ecr.${region}.${endpoint}
263+
repoList=$(aws ecr describe-repositories --region ${region})
264+
repoName=$(echo $repoList | jq .repositories[0].repositoryName)
265+
if [ "$repoName" = '"aws-for-fluent-bit"' ]; then
266+
tagCount=$(aws ecr list-images --repository-name aws-for-fluent-bit --region ${region} | jq -r '.imageIds[].imageTag' | grep -c ${tag} || echo "0")
267+
if [ "$tagCount" = '1' ]; then
268+
docker pull ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${tag}
269+
sha2=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${tag})
270+
else
271+
sha2='repo_not_found'
272+
fi
273+
else
274+
sha2='repo_not_found'
275+
fi
276+
277+
match_two_sha $sha1 $sha2
278+
279+
if [ "$IMAGE_SHA_MATCHED" = "FALSE" ]; then
280+
aws ecr create-repository --repository-name aws-for-fluent-bit --image-scanning-configuration scanOnPush=true --region ${region} || true
281+
push_image_ecr public.ecr.aws/aws-observability/aws-for-fluent-bit:${tag} \
282+
${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${tag}
283+
fi
284+
}
285+
254286
sync_latest_image() {
255287
region=${1}
256288
account_id=${2}
@@ -263,54 +295,11 @@ sync_latest_image() {
263295
for arch in "${ARCHITECTURES[@]}"
264296
do
265297
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/aws-observability || echo "0"
266-
docker pull public.ecr.aws/aws-observability/aws-for-fluent-bit:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
267-
sha1=$(docker inspect --format='{{index .RepoDigests 0}}' public.ecr.aws/aws-observability/aws-for-fluent-bit:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB})
268-
aws ecr get-login-password --region ${region}| docker login --username AWS --password-stdin ${account_id}.dkr.ecr.${region}.${endpoint}
269-
repoList=$(aws ecr describe-repositories --region ${region})
270-
repoName=$(echo $repoList | jq .repositories[0].repositoryName)
271-
if [ "$repoName" = '"aws-for-fluent-bit"' ]; then
272-
imageTag=$(aws ecr list-images --repository-name aws-for-fluent-bit --region ${region} | jq -r '.imageIds[].imageTag' | grep -c ${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB} || echo "0")
273-
if [ "$imageTag" = '1' ]; then
274-
docker pull ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
275-
sha2=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB})
276-
else
277-
sha2='repo_not_found'
278-
fi
279-
else
280-
sha2='repo_not_found'
281-
fi
298+
sync_public_and_repo ${region} ${account_id} ${endpoint} "${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}"
282299

283-
match_two_sha $sha1 $sha2
284-
285-
if [ "$IMAGE_SHA_MATCHED" = "FALSE" ]; then
286-
aws ecr create-repository --repository-name aws-for-fluent-bit --image-scanning-configuration scanOnPush=true --region ${region} || true
287-
push_image_ecr public.ecr.aws/aws-observability/aws-for-fluent-bit:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB} \
288-
${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
289-
fi
300+
sync_public_and_repo ${region} ${account_id} ${endpoint} "${init}-${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}"
290301

291-
docker pull public.ecr.aws/aws-observability/aws-for-fluent-bit:"$init"-"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
292-
sha1_init=$(docker inspect --format='{{index .RepoDigests 0}}' public.ecr.aws/aws-observability/aws-for-fluent-bit:"$init"-"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB})
293-
repoList=$(aws ecr describe-repositories --region ${region})
294-
repoName=$(echo $repoList | jq .repositories[0].repositoryName)
295-
if [ "$repoName" = '"aws-for-fluent-bit"' ]; then
296-
imageTag=$(aws ecr list-images --repository-name aws-for-fluent-bit --region ${region} | jq -r '.imageIds[].imageTag' | grep -c "$init"-${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB} || echo "0")
297-
if [ "$imageTag" = '1' ]; then
298-
docker pull ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:"$init"-${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
299-
sha2_init=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:"$init"-${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB})
300-
else
301-
sha2_init='repo_not_found'
302-
fi
303-
else
304-
sha2_init='repo_not_found'
305-
fi
306-
307-
match_two_sha $sha1_init $sha2_init
308-
309-
if [ "$IMAGE_SHA_MATCHED" = "FALSE" ]; then
310-
aws ecr create-repository --repository-name aws-for-fluent-bit --image-scanning-configuration scanOnPush=true --region ${region} || true
311-
push_image_ecr public.ecr.aws/aws-observability/aws-for-fluent-bit:"$init"-"$arch"-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB} \
312-
${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:"$init"-${arch}-${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB}
313-
fi
302+
sync_public_and_repo ${region} ${account_id} ${endpoint} "${arch}-${AWS_FOR_FLUENT_BIT_STABLE_VERSION}"
314303
done
315304

316305
if [ "${account_id}" != "${classic_regions_account_id}" ]; then

0 commit comments

Comments
 (0)