Skip to content

Commit 3934ecb

Browse files
committed
make packer extra build directly configurable
1 parent 965e24a commit 3934ecb

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

docs/image-build.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,21 @@ Ansible in the appliance. This allows adding additional functionality into site-
5151
5252
To configure an "extra" image build, prepare a Packer variable definition file as described above but also including:
5353
54-
- `extra_image_name`: A string to add into the final image name.
55-
- `source_image` (or `source_image_name`): The UUID or name of the fat image to start from (which must already be present in OpenStack).
56-
- `groups`: A mapping with a key "openhpc-extra" (i.e. the name of this Packer build) with a list of Ansible inventory groups to put the build VM into.
57-
This defines the roles/functionality which are added to the image.
54+
- `extra_build_image_name`: A string to add into the final image name.
55+
- `source_image` or `source_image_name`: The UUID or name of the fat image to start from (which must already be present in OpenStack).
56+
- `extra_build_groups`: A list of Ansible inventory groups to put the build VM into, in addition to the `builder` group. This defines the roles/functionality
57+
which are added to the image.
58+
- `extra_build_volume_size`: A number giving the size in GB of the volume for the build VM's root disk and therefore the resulting image size.
59+
Note this assumes the default of `use_blockstorage_volume = true`.
5860
5961
E.g. to add the lustre client to an RockyLinux 9 image:
6062
6163
# environments/site/lustre.pkvars.hcl
6264
63-
extra_image_name = "lustre" # output image name will be like "openhpc-lustre-RL9-$timestamp-$commit"
65+
extra_build_image_name = "lustre" # output image name will be like "openhpc-lustre-RL9-$timestamp-$commit"
6466
source_image_name = "openhpc-ofed-RL9-240906-1041-32568dbb" # e.g. current StackHPC RL9 image
65-
groups = {
66-
openhpc-extra = ["lustre"] # only run lustre role during this extra build
67-
}
67+
extra_build_groups = ["lustre"] # only run lustre role during this extra build
68+
extra_build_volume_size = 15 # default non-CUDA build image size has enough free space
6869
6970
# ... define flavor, network, etc as normal
7071

packer/openstack.pkr.hcl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ variable "os_version" {
4848
# Must supply either source_image_name or source_image_id
4949
variable "source_image_name" {
5050
type = string
51+
default = null
5152
description = "name of source image"
5253
}
5354

@@ -132,6 +133,10 @@ variable "volume_size" {
132133
}
133134
}
134135

136+
variable "extra_build_volume_size" {
137+
type = number
138+
}
139+
135140
variable "image_disk_format" {
136141
type = string
137142
default = "qcow2"
@@ -154,7 +159,12 @@ variable "groups" {
154159
}
155160
}
156161

157-
variable "extra_image_name" {
162+
variable "extra_build_groups" {
163+
type = list(string)
164+
default = []
165+
}
166+
167+
variable "extra_build_image_name" {
158168
type = string
159169
description = "Infix for 'extra' build image name"
160170
default = "extra"
@@ -165,7 +175,7 @@ source "openstack" "openhpc" {
165175
flavor = var.flavor
166176
use_blockstorage_volume = var.use_blockstorage_volume
167177
volume_type = var.volume_type
168-
volume_size = var.volume_size[source.name]
178+
volume_size = lookup(var.volume_size, source.name, var.extra_build_volume_size)
169179
metadata = var.metadata
170180
instance_metadata = {ansible_init_disable = "true"}
171181
networks = var.networks
@@ -220,12 +230,12 @@ build {
220230
# Extended site-specific image, built on fat image:
221231
source "source.openstack.openhpc" {
222232
name = "openhpc-extra"
223-
image_name = "openhpc-${var.extra_image_name}-${var.os_version}-${local.timestamp}-${substr(local.git_commit, 0, 8)}"
233+
image_name = "openhpc-${var.extra_build_image_name}-${var.os_version}-${local.timestamp}-${substr(local.git_commit, 0, 8)}"
224234
}
225235

226236
provisioner "ansible" {
227237
playbook_file = "${var.repo_root}/ansible/fatimage.yml"
228-
groups = concat(["builder"], var.groups[source.name])
238+
groups = concat(["builder"], lookup(var.groups, source.name, var.extra_build_groups))
229239
keep_inventory_file = true # for debugging
230240
use_proxy = false # see https://www.packer.io/docs/provisioners/ansible#troubleshooting
231241
extra_arguments = [

0 commit comments

Comments
 (0)