github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/scripts/testing-setup/build-ami/packer.json.pkr.hcl (about)

     1  variable "ami_name" {
     2    type    = string
     3    default = "ami-bacalhau-latest"
     4  }
     5  
     6  variable "base_ami" {
     7    type    = string
     8    default = "ami-1853ac65"
     9  }
    10  
    11  variable "ssh_username" {
    12    type    = string
    13    default = "ubuntu"
    14  }
    15  
    16  # source blocks are generated from your builders; a source can be referenced in
    17  # build blocks. A build block runs provisioner and post-processors on a
    18  # source. Read the documentation for source blocks here:
    19  # https://www.packer.io/docs/templates/hcl_templates/blocks/source
    20  source "amazon-ebs" "builder_ebs_image" {
    21    ami_name                = format("%s-%s-%s", "bacalhau_latest_", regex_replace(timestamp(), "[- TZ:]", ""), uuidv4())
    22    instance_type           = "c6a.xlarge"
    23    region                  = "eu-west-1"
    24    shared_credentials_file = "~/.aws/credentials"
    25    source_ami              = "ami-01061ffae6ddd2896"
    26    force_deregister        = "true"
    27    force_delete_snapshot   = "true"
    28    ssh_pty                 = "true"
    29    ssh_timeout             = "20m"
    30    ssh_username            = "ubuntu"
    31  
    32    tags = {
    33      BuiltBy = "packer"
    34      Name    = format("%s-%s-%s", "bacalhau-latest", regex_replace(timestamp(), "[- TZ:]", ""), uuidv4())
    35    }
    36  }
    37  
    38  # a build block invokes sources and runs provisioning steps on them. The
    39  # documentation for build blocks can be found here:
    40  # https://www.packer.io/docs/templates/hcl_templates/blocks/build
    41  build {
    42    description = "Bacalhau image"
    43  
    44    sources = ["source.amazon-ebs.builder_ebs_image"]
    45  
    46    provisioner "shell" {
    47      inline = [ "cloud-init status --wait"]
    48    }
    49  
    50    provisioner "shell" {
    51      inline = [<<EOM
    52    mkdir -p /tmp/services
    53    mkdir -p /tmp/scripts
    54    EOM
    55      ]
    56    }
    57  
    58    provisioner "file" {
    59      destination = "/tmp/services"
    60      source      = "services/"
    61    }
    62  
    63    provisioner "file" {
    64      destination = "/tmp/scripts"
    65      source      = "scripts/"
    66    }
    67  
    68    provisioner "shell" {
    69      inline = [<<EOM
    70    sudo cp -R /tmp/services/* /etc/systemd/system
    71    sudo cp -R /tmp/scripts /usr/local/bin/ 
    72    sudo chmod +x /usr/local/bin/scripts/*
    73    mkdir -p /home/ubuntu/health_check
    74    touch /home/ubuntu/health_check/peer_token.html
    75    usermod -aG docker ubuntu &> /dev/null
    76    EOM
    77      ]
    78    }
    79  
    80    provisioner "shell" {
    81      expect_disconnect = true
    82      inline            = ["sudo /usr/local/bin/scripts/update_packages.sh"]
    83  
    84    }
    85  
    86    provisioner "shell" {
    87      inline = ["sudo /usr/local/bin/scripts/setup_node.sh"]
    88    }
    89  }