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 add template to stand up instances for generating golden AMIs #540

Merged
merged 13 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.retry
templates/AMI-Template-Instances.cfn.yml
templates/chef.json
templates/chef-source.json
templates/cloudfront.cfn.yml
Expand Down
39 changes: 39 additions & 0 deletions AMI-templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Cloudformation Playbook
hosts: local
connection: local

pre_tasks:
- name: get basic_facts
set_fact:
basic_fact={{ item }}
# CKANSource={{ item.CKANSource }}
when: item.Environment == Environment
with_items: "{{ basic_facts }}"

- name: set facts to environment from basic_fact
set_fact: "{{ item.key }}={{ item.value }}"
with_dict: "{{ basic_fact }}"
when: basic_fact is defined

- name: kms alias fact
aws_kms_facts:
filters:
alias: "aws/ssm"
region: "{{ region }}"
register: ssmKeyFacts

- name: set KMS key from alias
set_fact:
SSMKey: "{{ ssmKeyFacts['keys'][0].key_arn }}"

- name: Generate Lambda file hash
shell: >
md5sum files/instanceSetupLambda.js | awk '{print substr($1, 1, 20)}'
register: hash_output
- set_fact:
instance_setup_source_hash: "{{ hash_output.stdout_lines[0] }}"

- include_vars: vars/AMI-template-instances.var.yml
roles:
- ansible_cloudformation
17 changes: 13 additions & 4 deletions files/instanceSetupLambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ function recordCompletion(event, success) {

exports.handler = async (event) => {
const instanceId = event['EC2InstanceId'];
/*
* Possible deployment types include:
* - 'setup': Full end-to-end configuration, from vanilla operating system to live instance.
* - 'deploy': Take a vanilla operating system and set up a warm instance, but do not make it active.
* - 'configure': Take a warm instance and make it active.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i see the options of
setup, deploy, configure.

I do not envision 'setup' doing everything. nor 'deploy' only making a 'warm' instance.

@chris-randall-qol and others, what is your thoughts on this.

I know this is from legacy deployPhase's we got from inheriting this codebase but i think its time to make it less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is from legacy deployPhase's we got from inheriting this codebase

Yes, those were the OpsWorks terms. We could change them, it would just mean a lot of renaming.

Note that the distinction between 'deploy' and 'configure' creating warm vs hot instances did not come from OpsWorks. It's just something that I've observed to be useful if we want to make custom images.

const deployPhase = 'phase' in event ? event['phase'] : 'setup';
if (!['setup', 'deploy', 'configure'].includes(deployPhase)) {
console.log("Invalid deployment phase '" + deployPhase + "', must be one of 'setup', 'deploy', 'configure'");
Expand Down Expand Up @@ -95,12 +101,15 @@ exports.handler = async (event) => {
} else {
recipePrefix = `datashades::${layer}`;
}
var runList = `recipe[${recipePrefix}-configure]`;
if (deployPhase !== 'configure') {
runList = `recipe[${recipePrefix}-deploy],${runList}`;
var runList = "";
if (deployPhase !== 'deploy') {
runList = `recipe[${recipePrefix}-configure]`;
}
if (deployPhase === 'setup') {
runList = `recipe[${recipePrefix}-setup],${runList}`;
runList = `,${runList}`;
}
if (deployPhase !== 'configure') {
runList = `recipe[${recipePrefix}-setup],recipe[${recipePrefix}-deploy]${runList}`;
}

await ssm.send(new SendCommandCommand({
Expand Down
Loading