Skip to content

Commit

Permalink
[QOLDEV-833] add the ability to reuse AMIs instead of creating new ev…
Browse files Browse the repository at this point in the history
…ery time
  • Loading branch information
ThrawnCA committed Dec 5, 2024
1 parent ee71096 commit 09ef7bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion build-CKAN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ run-deployment () {
}

create-amis () {
ANSIBLE_EXTRA_VARS="$ANSIBLE_EXTRA_VARS timestamp=`date -u +%Y-%m-%dT%H:%M:%SZ`"
# try to match an existing image instead of creating a new one
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")
if [ "$IMAGE_IDS" != "" ]; then
return 0
fi
fi
ANSIBLE_EXTRA_VARS="$ANSIBLE_EXTRA_VARS timestamp=`date -u +%Y-%m-%dT%H:%M:%SZ` image_version=$IMAGE_VERSION"
run-playbook "AMI-templates.yml"
run-playbook "create-AMI" "layer=Batch" & BATCH_PID=$!
run-playbook "create-AMI" "layer=Web" & WEB_PID=$!
Expand Down
3 changes: 2 additions & 1 deletion create-AMI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@
Name: "{{ InstanceName }}-{{ timestamp | replace(':', '-') }}"
Environment: "{{ Environment }}"
Service: "{{ service_name }}"
Layer: "{{ layer | lower }}"
Division: "{{ Division }}"
Owner: "{{ Owner }}"
Version: "1.0"
Version: "{{ image_version | default('1.0') }}"
register: new_image

- name: Record AMI ID
Expand Down

0 comments on commit 09ef7bc

Please sign in to comment.