Creating a Custom MarkLogic AMI with Packer
22 September 2021 02:17 PM
|
|
SummaryPacker from HashiCorp is a provisioning tool, allowing for the automated creation of machine images, extending the ability to manage infrastructure to machine images. Packer supports a number of different image types including AWS, Azure, Docker, VirtualBox and VMWare. Packer can be used to create a customized MarkLogic Amazon Machine Image (AMI) which can then be deployed to AWS and used in a Cluster. We recommend using the official MarkLogic AMIs whenever possible, and making the necessary customizations to the official images. This ensures that MarkLogic Support is able to quickly diagnose any issues that may occur, as well as reducing the risk of running MarkLogic in a way that is not fully supported. The KB article, Customizing MarkLogic with Packer and Terraform, covers the process of customizing the official MarkLogic AMI using Packer. Setting Up PackerFor the purpose of this example, I will assume that you have already installed the AWS CLI, with the correct credentials, and you have installed Packer. Packer TemplatesA Packer template is a JSON configuration file that is used to define the image that we want to build. Templates have a number of keys available for defining the machine image, but the most commonly used ones are builders, provisioners and post-processors.
Creating a TemplateFor our example, we are going to take build from the official Amazon Linux 2 AMI, where we will install the required prerequisite packages, install MarkLogic, and apply some customizations before creating a new image. Defining VariablesVariables help make the build more flexible, so we will utilize a separate variables file,
{ "vpc_region": "us-east-1",
"vpc_id": "vpc-06d3506111cea30d0",
"vpc_public_sn_id": "subnet-03343e69ae5bed127",
"vpc_public_sg_id": "sg-07693eb077acb8635",
"instance_type": "t3.large",
"ssh_username": "ec2-user",
"ami_filter": "amzn2-ami-hvm-2.*-ebs",
"ami_owner": "amazon",
"binary_source": "./",
"binary_dest": "/tmp/",
"marklogic_binary": "MarkLogic-10.0-4.2.x86_64.rpm"
}
Here we've identified the instance details so our image can be launched, as well as the filter values, Creating Our TemplateNow that we have some of the specific build details defined, we can create our template,
{ "builders": [ { "type": "amazon-ebs", "region": "{{user `vpc_region`}}", "vpc_id": "{{user `vpc_id`}}", "subnet_id": "{{user `vpc_public_sn_id`}}", "associate_public_ip_address": true, "security_group_id": "{{user `vpc_public_sg_id`}}", "source_ami_filter": { "filters": { "virtualization-type": "hvm", "name": "{{user `ami_filter`}}", "root-device-type": "ebs" }, "owners": ["{{user `ami_owner`}}"], "most_recent": true }, "instance_type": "{{user `instance_type`}}", "ssh_username": "{{user `ssh_username`}}", "ami_name": "ml-{{isotime \"2006-01-02-1504\"}}", "tags": { "Name": "ml-packer" } } ], "provisioners": [ { "type": "shell", "script": "./marklogicInit.sh" }, { "destination": "{{user `binary_dest`}}", "source": "{{user `binary_source`}}{{user `marklogic_binary`}}", "type": "file" }, { "type": "shell", "inline": [ "sudo yum -y install /tmp/{{user `marklogic_binary`}}" ] } ] }
In the ProvisionersIn our example, we are using the Provisioning ScriptFor our custom image, we've determined that we need install Git, to create a symbolic link MarkLogic needs on Amazon Linux 2, and to setup /etc/marklogic.conf to disable the MarkLogic Managed Cluster feature, all of which we will do inside a script. We've named the script
#!/bin/bash -x
echo "**** Starting setup.sh ****"
echo "**** Creating LSB symbolic link ****"
sudo ln -s /etc/system-lsb /etc/redhat-lsb
echo "**** Installing Git ****"
sudo yum install -y git
echo "**** Setting Up /etc/marklogic.conf ****"
echo "export MARKLOGIC_MANAGED_NODE=0" >> /tmp/marklogic.conf
sudo cp /tmp/marklogic.conf /etc/
echo "**** Finishing setup.sh ****"
Executing Our BuildNow that we've completed setting up our build, it's time to use Packer to create the image.
packer build -debug -var-file=marklogic_vars.json marklogic_ami.json
Here you can see that we are telling Packer to do a build using The last part of the build output will print out the details of our new image: Wrapping UpWe have now created a customized MarkLogic AMI using Packer, which can be used to deploy a self managed cluster. Related Reading | |
|