Skip to content

Commit

Permalink
make built image name/version smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpb committed Nov 6, 2024
1 parent c7e9eba commit 1caa288
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packer/openstack.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ data "git-commit" "cwd-head" { }
locals {
git_commit = data.git-commit.cwd-head.hash
timestamp = formatdate("YYMMDD-hhmm", timestamp())
image_version = var.image_version == "" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version
image_version = var.image_version == "auto" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version
image_name = replace(var.image_name, '/', '-')
}

# Path pointing to root of repository - automatically set by environment variable PKR_VAR_repo_root
Expand Down Expand Up @@ -157,14 +158,14 @@ variable "inventory_groups" {

variable "image_name" {
type = string
description = "Built image name"
description = "Built image name. Any '/' are replaced with '-'."
default = "openhpc"
}

variable "image_version" {
type = string
description = "Suffix for built image names. If not supplied a timestamp+git commit is used"
default = ""
description = "Suffix for built image names. Default special value 'auto' uses a timestamp+git commit"
default = "auto"
}

source "openstack" "openhpc" {
Expand Down Expand Up @@ -202,7 +203,7 @@ build {

source "source.openstack.openhpc" {
name = "rocky-latest"
image_name = "${var.image_name}-${local.image_version}"
image_name = join("-", [local.image_name, local.image_version])
}

provisioner "ansible" {
Expand Down

0 comments on commit 1caa288

Please sign in to comment.