Skip to content

Commit

Permalink
[QOLDEV-833] ensure existing image IDs are applied to the ASG when found
Browse files Browse the repository at this point in the history
  • Loading branch information
ThrawnCA committed Dec 11, 2024
1 parent 2cdb913 commit 4e2f5b7
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions build-CKAN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,38 @@ create-amis () {
if [ "$IMAGE_VERSION" = "" ]; then
IMAGE_VERSION=`git rev-parse HEAD` || true
fi
if [ "$IMAGE_VERSION" != "" ]; then
echo "Checking for existing $ENVIRONMENT $INSTANCE_NAME images tagged with version ${IMAGE_VERSION}..."
IMAGE_IDS=$(aws ec2 describe-images --filters "Name=tag:Environment,Values=$ENVIRONMENT" "Name=tag:Service,Values=$INSTANCE_NAME" "Name=tag:Version,Values=$IMAGE_VERSION" --query "Images[].ImageId" --output text)
if [ "$IMAGE_IDS" != "" ]; then
echo "Found existing image(s): $IMAGE_IDS"
return 0
fi
if [ "$IMAGE_VERSION" = "" ]; then
AMI_NEEDED=1
else
for layer in Web Batch Solr; do
lowercase_layer=`echo $layer | tr '[:upper:]' '[:lower:]'`
echo "Checking for existing $ENVIRONMENT $INSTANCE_NAME $lowercase_layer image tagged with version ${IMAGE_VERSION}..."
IMAGE_ID=$(aws ec2 describe-images --filters "Name=tag:Environment,Values=$ENVIRONMENT" "Name=tag:Service,Values=$INSTANCE_NAME" "Name=tag:Version,Values=$IMAGE_VERSION" "Name=tag:Layer,Values=$lowercase_layer" --query "Images[].ImageId" --output text |tail -1 |tr -d '[:space:]')
if [ "$IMAGE_ID" = "" ]; then
AMI_NEEDED=1
else
echo "Found existing image(s): $IMAGE_ID"
aws ssm put-parameter --overwrite --type String --name "/config/CKAN/$ENVIRONMENT/app/$INSTANCE_SHORTNAME/${layer}AmiId" --value "$IMAGE_ID"
eval "${layer}_IMAGE_ID=$IMAGE_ID"
fi
done
fi
if [ "$AMI_NEEDED" != "1" ]; then
return 0
fi
run-playbook "AMI-templates.yml"
ANSIBLE_EXTRA_VARS="$ANSIBLE_EXTRA_VARS timestamp=`date -u +%Y-%m-%dT%H:%M:%SZ` image_version=$IMAGE_VERSION"
run-playbook "create-AMI" "layer=Batch" & BATCH_PID=$!
run-playbook "create-AMI" "layer=Web" & WEB_PID=$!
run-playbook "create-AMI" "layer=Solr"
wait $BATCH_PID
wait $WEB_PID
for layer in Batch Web Solr; do
if [ "${layer}_IMAGE_ID" != "" ]; then
run-playbook "create-AMI" "layer=$layer" & eval "${layer}_PID=$!"
fi
done
for layer in Batch Web Solr; do
PID=`eval "\$${layer}_PID"`
if [ "$PID" != "" ]; then
wait "$PID"
fi
done
run-playbook "AMI-templates.yml" "state=absent"
}

Expand Down

0 comments on commit 4e2f5b7

Please sign in to comment.