Creating with Packer
To create a service image using Packer:
-
Install Packer:
- Download Packer from the official VK Cloud mirror.
- Extract the archive and add the path to the extracted file to the
Pathenvironment variable. - Run the
packercommand to verify that Packer has been installed successfully.
For detailed instructions, see the official Packer documentation.
-
Install OpenStack CLI and authenticate in the project.
-
Download a base OS image that supports working with cloud platforms.
The OS must meet the service image requirements.
The official OpenStack website provides links to images of some OSs that support working with cloud platforms.
-
Convert the base image to the
RAWformat:-
Install the qemu-img utility on your local computer.
Example of installing qemu-img for RHEL-based images (CentOS, AlmaLinux, Rocky Linux)sudo yum install qemu-imgExample of installing qemu-img for Debian-based images (Ubuntu)sudo apt install qemu-utils -
Run the command:
qemu-img convert -f qcow2 -O raw <INITIAL_IMAGE_NAME> <IMAGE_NAME>Here:
<INITIAL_IMAGE_NAME>— name of the original base image. For example,alt-p9-cloud-x86_64.qcow2.<IMAGE_NAME>— name of the base image in theRAWformat. For example,alt-p9-cloud-x86_64.raw.
-
-
Upload the base image in the
RAWformat to the cloud platform:openstack image create --private --container-format bare --disk-format raw --property store=s3 --file <IMAGE_PATH> <IMAGE_NAME>Here:
-
<IMAGE_PATH>— path to the base image. -
<IMAGE_NAME>— name of the base image in theRAWformat.The ID of the created image will be displayed in the cloud platform management console.
For detailed instructions, see the section Image import.
-
-
Configure the Packer file:
-
Write the network ID and the base image ID to the environment variables:
export NETWORK_ID=<NETWORK_ID>export SOURCE_IMAGE=<IMAGE_ID>Here:
<NETWORK_ID>— network ID. The value is displayed in the cloud platform management console on the page with the list of networks.<IMAGE_ID>— base image ID. The value is displayed in the cloud platform management console on the page with the list of images. If a ready-made base image is used, specify the ID from the section The target_os argument.
-
Create a
<FILE_NAME>.pkr.hclfile. For example,altlinux.pkr.hcl. -
In the file, describe the configuration of the VM on which the service image will be based (for syntax, see the official Packer website).
Example of a VM configuration with the Alt Linux P9 OS and deployment of an image-based application from an Ansible playbookundefined
-
Network ID
variable "network_id" {type = stringdefault = "${env("NETWORK_ID")}"validation {condition = length(var.network_id) > 0error_message = <<EOFThe NETWORK_ID environment variable must be set.EOF}}
Base image ID
variable "source_image" {type = stringdefault = "${env("SOURCE_IMAGE")}"validation {condition = length(var.source_image) > 0error_message = <<EOFThe SOURCE_IMAGE environment variable must be set.EOF}}
Creating a VM from the base image
source "openstack" "altlinux" {flavor = "STD3-2-6"image_name = "Alt-Linux-P9-Starter-Kit"source_image = "${var.source_image}"config_drive = "true"networks = ["${var.network_id}"]security_groups = ["default", "ssh"]ssh_username = "altlinux"use_blockstorage_volume = "true"volume_availability_zone = "MS1"}
Configuring the VM
build {sources = ["source.openstack.altlinux"]provisioner "shell" {execute_command = "sudo {{ .Path }}"inline = ["apt-get update","apt-get install -y irqbalance bash-completion bind-utils qemu-guest-agent cloud-utils-growpart","systemctl enable qemu-guest-agent"]}provisioner "ansible" {playbook_file = "provision.yml"user = "altlinux"sftp_command = "/usr/libexec/openssh/sftp-server -e"use_proxy = false}}```</div></div><info>If you need to send metrics to the Cloud Monitoring service, describe the installation of the monitoring agent in the VM configuration (for more details, see the section [VM system metrics](../../../ib_cloud_monitoring/ib_cloud_monitoring_vm)).</info>The OS username depends on the OS. The list of usernames is provided in the section [Connecting to a Linux VM](/en/computing/iaas/instructions/vm/vm-connect/vm-connect-nix).The default security group name depends on the SDN type:* `default` — in a cloud platform project based on OpenStack Neutron.* `default-sprut` — in a cloud platform project based on Sprut.<info>View the available security groups using the command:```console
openstack security group list
```</info>
-
Verify the created configuration:
packer validate <FILE_NAME>.pkr.hclHere
<FILE_NAME>.pkr.hclis the name of the Packer file. -
Create the service image in the cloud platform:
-
Start creating the service image:
packer build <PACKER_FILE>Here
<PACKER_FILE>is the name of the Packer file. -
Wait for the message about successful creation. The message will contain the ID of the service image.
Example of a message about successful creation of a service image==> Builds finished. The artifacts of successful builds are:--> openstack.altlinux: An image was created: c6320138-035f-40d8-XXXX-e814edb2ce5fHere
c6320138-035f-40d8-XXXX-e814edb2ce5fis the ID of the service image. -
Make sure that the service image is displayed in the cloud platform management console.
-