github.com/ava-labs/avalanchego@v1.11.11/.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl (about)

     1  packer {
     2    required_plugins {
     3      amazon = {
     4        source  = "github.com/hashicorp/amazon"
     5        version = "~> 1"
     6      }
     7      ansible = {
     8        source  = "github.com/hashicorp/ansible"
     9        version = "~> 1"
    10      }
    11    }
    12  }
    13  
    14  variable "skip_create_ami" {
    15    type    = string
    16    default = "${env("SKIP_CREATE_AMI")}"
    17  }
    18  
    19  variable "tag" {
    20    type    = string
    21    default = "${env("TAG")}"
    22  }
    23  
    24  variable "version" {
    25    type    = string
    26    default = "jammy-22.04"
    27  }
    28  
    29  data "amazon-ami" "autogenerated_1" {
    30    filters = {
    31      architecture        = "x86_64"
    32      name                = "ubuntu/images/*ubuntu-${var.version}-*-server-*"
    33      root-device-type    = "ebs"
    34      virtualization-type = "hvm"
    35    }
    36    most_recent = true
    37    owners      = ["099720109477"]
    38    region      = "us-east-1"
    39  }
    40  
    41  locals {
    42    skip_create_ami = var.skip_create_ami == "True"
    43    timestamp = regex_replace(timestamp(), "[- TZ:]", "") 
    44    clean_name = regex_replace(timestamp(), "[^a-zA-Z0-9-]", "-")
    45  }
    46  
    47  source "amazon-ebs" "autogenerated_1" {
    48    ami_groups      = ["all"]
    49    ami_name        = "public-avalanche-ubuntu-${var.version}-${var.tag}-${local.timestamp}"
    50    instance_type   = "c5.large"
    51    region          = "us-east-1"
    52    skip_create_ami = local.skip_create_ami
    53    source_ami      = "${data.amazon-ami.autogenerated_1.id}"
    54    ssh_username    = "ubuntu"
    55    tags = {
    56      Base_AMI_Name = "{{ .SourceAMIName }}"
    57      Name          = "public-avalanche-ubuntu-${var.version}-${var.tag}-${local.clean_name}"
    58      Release       = "${var.version}"
    59    }
    60  }
    61  
    62  build {
    63    sources = ["source.amazon-ebs.autogenerated_1"]
    64  
    65    provisioner "shell" {
    66      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"]
    67    }
    68  
    69    provisioner "ansible" {
    70      extra_arguments = ["-e", "component=public-ami build=packer os_release=jammy tag=${var.tag}"]
    71      playbook_file   = ".github/packer/create_public_ami.yml"
    72      roles_path      = ".github/packer/roles/"
    73      use_proxy       = false
    74    }
    75  
    76    provisioner "shell" {
    77      execute_command = "sudo bash -x {{ .Path }}"
    78      script          = ".github/packer/clean-public-ami.sh"
    79    }
    80  
    81  }