Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOLDEV-833 improve autoscaling AMI handling #615

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}"
Loading