-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(INFRA-3587): migrate packer config and fix workflow
- Loading branch information
1 parent
d003d29
commit b1f928e
Showing
3 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
.github/packer/ubuntu-jammy-x86_64-public-ami.json.pkr.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
packer { | ||
required_plugins { | ||
amazon = { | ||
source = "github.com/hashicorp/amazon" | ||
version = "~> 1" | ||
} | ||
ansible = { | ||
source = "github.com/hashicorp/ansible" | ||
version = "~> 1" | ||
} | ||
} | ||
} | ||
|
||
variable "skip_create_ami" { | ||
type = string | ||
} | ||
|
||
variable "tag" { | ||
type = string | ||
} | ||
|
||
variable "version" { | ||
type = string | ||
default = "jammy-22.04" | ||
} | ||
|
||
data "amazon-ami" "autogenerated_1" { | ||
filters = { | ||
architecture = "x86_64" | ||
name = "ubuntu/images/*ubuntu-${var.version}-*-server-*" | ||
root-device-type = "ebs" | ||
virtualization-type = "hvm" | ||
} | ||
most_recent = true | ||
owners = ["099720109477"] | ||
region = "us-east-1" | ||
} | ||
|
||
locals { | ||
skip_create_ami = lower(var.skip_create_ami) == "true" ? true : false | ||
timestamp = regex_replace(timestamp(), "[- TZ:]", "") | ||
} | ||
|
||
source "amazon-ebs" "autogenerated_1" { | ||
ami_groups = ["all"] | ||
ami_name = "public-avalanche-ubuntu-${var.version}-${var.tag}-${local.timestamp}" | ||
instance_type = "c5.large" | ||
region = "us-east-1" | ||
skip_create_ami = local.skip_create_ami | ||
source_ami = "${data.amazon-ami.autogenerated_1.id}" | ||
ssh_username = "ubuntu" | ||
tags = { | ||
Base_AMI_Name = "{{ .SourceAMIName }}" | ||
Name = "public-avalanche-ubuntu-${var.version}-${var.tag}-${regex_replace(local.timestamp, "[- T:]", "")}" | ||
Release = "${var.version}" | ||
} | ||
} | ||
|
||
build { | ||
sources = ["source.amazon-ebs.autogenerated_1"] | ||
|
||
provisioner "shell" { | ||
inline = ["while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", "wait_apt=$(ps aux | grep apt | wc -l)", "while [ \"$wait_apt\" -gt \"1\" ]; do echo \"waiting for apt to be ready....\"; wait_apt=$(ps aux | grep apt | wc -l); sleep 5; done", "sudo apt-get -y update", "sudo apt-get install -y python3-boto3 golang"] | ||
} | ||
|
||
provisioner "ansible" { | ||
extra_arguments = ["-e", "component=public-ami build=packer os_release=jammy tag=${var.tag}"] | ||
playbook_file = ".github/packer/create_public_ami.yml" | ||
roles_path = ".github/packer/roles/" | ||
use_proxy = false | ||
} | ||
|
||
provisioner "shell" { | ||
execute_command = "sudo bash -x {{ .Path }}" | ||
script = ".github/packer/clean-public-ami.sh" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters