Skip to content

Commit a9a230d

Browse files
committed
Deployment Script: Refactor
1 parent 01c20de commit a9a230d

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

.github/workflows/release.yml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,18 @@ jobs:
5252
REGISTRY_ID=${REGISTRY_ID%%.*}
5353
echo "REGISTRY_ID=$REGISTRY_ID" >> $GITHUB_ENV
5454
55-
IMAGE_INFO=$(aws ecr describe-images --repository-name ${{ vars.PINGPONG_SRV_REPO }} --registry-id $REGISTRY_ID --image-ids imageTag=${{ env.SRV_VERSION }} >/dev/null 2>&1)
56-
if [ $? -ne 0 ] || [ -z "$IMAGE_INFO" ]; then
57-
# The image doesn't exist
58-
echo "SRV_IMAGE_STATUS=DOES_NOT_EXIST" >> $GITHUB_ENV
59-
echo "Server Image with tag ${{ env.SRV_VERSION }} does not exist in the ECR repository."
60-
else
61-
# Image exists, now check if it has the ENVIRONMENT tag
62-
if echo "$IMAGE_INFO" | grep -q ${{ env.ENVIRONMENT }}; then
55+
# Check if the image with SRV_VERSION tag exists
56+
if aws ecr describe-images --repository-name ${{ vars.PINGPONG_SRV_REPO }} --registry-id $REGISTRY_ID --image-ids imageTag=${{ env.SRV_VERSION }} >/dev/null 2>&1; then
57+
if aws ecr describe-images --repository-name ${{ vars.PINGPONG_SRV_REPO }} --registry-id $REGISTRY_ID --image-ids imageTag=${{ env.ENVIRONMENT }} >/dev/null 2>&1; then
6358
echo "SRV_IMAGE_STATUS=EXISTS_WITH_ENV_TAG" >> $GITHUB_ENV
6459
echo "Server Image with tag ${{ env.SRV_VERSION }} exists and has the ${{ env.ENVIRONMENT }} tag in the ECR repository."
6560
else
6661
echo "SRV_IMAGE_STATUS=EXISTS_WITHOUT_ENV_TAG" >> $GITHUB_ENV
6762
echo "Server Image with tag ${{ env.SRV_VERSION }} exists but does not have the ${{ env.ENVIRONMENT }} tag in the ECR repository."
6863
fi
64+
else
65+
echo "SRV_IMAGE_STATUS=DOES_NOT_EXIST" >> $GITHUB_ENV
66+
echo "Server Image with tag ${{ env.SRV_VERSION }} does not exist in the ECR repository."
6967
fi
7068
shell: bash
7169

@@ -122,21 +120,20 @@ jobs:
122120
env:
123121
ENVIRONMENT: ${{ github.event.release.prerelease && 'stage' || 'prod' }}
124122
run: |
125-
IMAGE_INFO=$(aws ecr describe-images --repository-name ${{ vars.PINGPONG_WEB_REPO }} --registry-id ${{ env.REGISTRY_ID }} --image-ids imageTag=${{ env.WEB_VERSION }} >/dev/null 2>&1)
126-
if [ $? -ne 0 ] || [ -z "$IMAGE_INFO" ]; then
127-
# The image doesn't exist
128-
echo "WEB_IMAGE_STATUS=DOES_NOT_EXIST" >> $GITHUB_ENV
129-
echo "Server Image with tag ${{ env.WEB_VERSION }} does not exist in the ECR repository."
130-
else
131-
# Image exists, now check if it has the ENVIRONMENT tag
132-
if echo "$IMAGE_INFO" | grep -q ${{ env.ENVIRONMENT }}; then
123+
# Check if the image with WEB_VERSION tag exists
124+
if aws ecr describe-images --repository-name ${{ vars.PINGPONG_WEB_REPO }} --registry-id ${{ env.REGISTRY_ID }} --image-ids imageTag=${{ env.WEB_VERSION }} >/dev/null 2>&1; then
125+
if aws ecr describe-images --repository-name ${{ vars.PINGPONG_WEB_REPO }} --registry-id ${{ env.REGISTRY_ID }} --image-ids imageTag=${{ env.ENVIRONMENT }} >/dev/null 2>&1; then
133126
echo "WEB_IMAGE_STATUS=EXISTS_WITH_ENV_TAG" >> $GITHUB_ENV
134-
echo "Server Image with tag ${{ env.WEB_VERSION }} exists and has the ${{ env.ENVIRONMENT }} tag in the ECR repository."
127+
echo "Web Image with tag ${{ env.SRV_VERSION }} exists and has the ${{ env.ENVIRONMENT }} tag in the ECR repository."
135128
else
136129
echo "WEB_IMAGE_STATUS=EXISTS_WITHOUT_ENV_TAG" >> $GITHUB_ENV
137-
echo "Server Image with tag ${{ env.WEB_VERSION }} exists but does not have the ${{ env.ENVIRONMENT }} tag in the ECR repository."
130+
echo "Web Image with tag ${{ env.SRV_VERSION }} exists but does not have the ${{ env.ENVIRONMENT }} tag in the ECR repository."
138131
fi
132+
else
133+
echo "WEB_IMAGE_STATUS=DOES_NOT_EXIST" >> $GITHUB_ENV
134+
echo "Web Image with tag ${{ env.SRV_VERSION }} does not exist in the ECR repository."
139135
fi
136+
140137
shell: bash
141138

142139
- name: Tag web image for release

0 commit comments

Comments
 (0)