Skip to content

Commit

Permalink
Merge pull request #615 from qld-gov-au/QOLDEV-833-autoscaling-ami
Browse files Browse the repository at this point in the history
QOLDEV-833 improve autoscaling AMI handling
  • Loading branch information
ThrawnCA authored Dec 6, 2024
2 parents ee71096 + 496ead4 commit 68b108b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion build-CKAN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,21 @@ run-deployment () {
}

create-amis () {
ANSIBLE_EXTRA_VARS="$ANSIBLE_EXTRA_VARS timestamp=`date -u +%Y-%m-%dT%H:%M:%SZ`"
run-playbook "AMI-templates.yml" "state=absent"
# 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" --output text)
if [ "$IMAGE_IDS" != "" ]; then
echo "Found existing image(s): $IMAGE_IDS"
return 0
fi
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"
Expand Down
5 changes: 3 additions & 2 deletions create-AMI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@
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
shell: |
aws ssm put-parameter --type String --name "/config/CKAN/{{ Environment }}/app/{{ service_name_lower }}/{{ layer }}AmiId" --value "{{ new_image.image_id }}"
aws ssm put-parameter --overwrite --type String --name "/config/CKAN/{{ Environment }}/app/{{ service_name_lower }}/{{ layer }}AmiId" --value "{{ new_image.image_id }}"

0 comments on commit 68b108b

Please sign in to comment.