From 601b5251abccb272dd671e7f04b949d4ae2b807c Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 23 May 2024 16:44:23 +1000 Subject: [PATCH] x86 compatibility --- packer/variables.pkrvars.hcl | 4 +- packer/x86_64-hashibox.pkr.hcl | 92 +++++++++++++++++++ scenarios/nomad-only-quickstart/hashibox.yaml | 83 +++++++++++++++++ 3 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 packer/x86_64-hashibox.pkr.hcl create mode 100644 scenarios/nomad-only-quickstart/hashibox.yaml diff --git a/packer/variables.pkrvars.hcl b/packer/variables.pkrvars.hcl index ff9805b..c490f2a 100644 --- a/packer/variables.pkrvars.hcl +++ b/packer/variables.pkrvars.hcl @@ -1,2 +1,2 @@ -consul_version = "enterprise-1.18.2" -nomad_version = "enterprise-1.7.7" +consul_version = "1.18" +nomad_version = "1.7" \ No newline at end of file diff --git a/packer/x86_64-hashibox.pkr.hcl b/packer/x86_64-hashibox.pkr.hcl new file mode 100644 index 0000000..b21d708 --- /dev/null +++ b/packer/x86_64-hashibox.pkr.hcl @@ -0,0 +1,92 @@ +packer { + required_plugins { + qemu = { + version = ">= 1.1.0" + source = "github.com/hashicorp/qemu" + } + } +} + +variable "consul_version" { + type = string + default = "1.18" + description = "Consul version to install" +} + +variable "nomad_version" { + type = string + default = "1.7" + description = "Nomad version to install" +} + +variable "fedora_iso_url" { + type = string + default = "https://fedora.mirror.digitalpacific.com.au/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2" + description = "Fedora Cloud Image URL - qcow2 format" +} + +variable "fedora_iso_checksum" { + type = string + default = "file:https://fedora.mirror.digitalpacific.com.au/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-40-1.14-x86_64-CHECKSUM" + description = "Checksum in the packer format of the cloud image" +} + +source "qemu" "hashibox" { + iso_url = "${var.fedora_iso_url}" + iso_checksum = "${var.fedora_iso_checksum}" + + headless = true + + disk_compression = true + disk_size = "5G" + disk_interface = "virtio" + disk_image = true + + format = "qcow2" + vm_name = "c-${var.consul_version}-n-${var.nomad_version}.qcow2" + boot_command = [] + net_device = "virtio-net" + + output_directory = ".artifacts/qemu/c-${var.consul_version}-n-${var.nomad_version}" + + accelerator = "hvf" + + cpus = 8 + memory = 5120 + + + qemuargs = [ + ["-cdrom", "userdata/cidata.iso"], + ["-monitor", "none"], + ["-no-user-config"] + ] + + communicator = "ssh" + shutdown_command = "echo fedora | sudo -S shutdown -P now" + ssh_password = "fedora" + ssh_username = "fedora" + ssh_timeout = "10m" +} + + +build { + sources = ["source.qemu.hashibox"] + + provisioner "shell" { + environment_vars = [ + "CONSUL_VERSION=${var.consul_version}", + "NOMAD_VERSION=${var.nomad_version}" + ] + inline = [ + "sudo dnf clean all", + "sudo dnf install -y unzip wget", + "sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo", + "sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin", + + "sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo", + "sudo dnf install -y consul-$CONSUL_VERSION* nomad-$NOMAD_VERSION* containernetworking-plugins", + + "sudo systemctl disable docker consul nomad" + ] + } +} diff --git a/scenarios/nomad-only-quickstart/hashibox.yaml b/scenarios/nomad-only-quickstart/hashibox.yaml new file mode 100644 index 0000000..f6c17e2 --- /dev/null +++ b/scenarios/nomad-only-quickstart/hashibox.yaml @@ -0,0 +1,83 @@ +images: + # Try to use a local image first. + - location: ~/artifacts/qemu/c-1.18-n-1.7.7/c-1.18-n-1.7.7.qcow2 + +mounts: [] +containerd: + system: false + user: false +provision: + - mode: system # configure Nomad + script: | + #!/bin/bash + function setConfig { + local mode=$1 + local cluster=$2 + + # Set the config files accordingly + if [[ $mode == "server" ]]; then + cat <<-EOF > /etc/nomad.d/nomad.hcl + data_dir = "/opt/nomad/data" + bind_addr = "0.0.0.0" + + server { + #license_path = "/etc/nomad.d/license.hclic" + enabled = true + bootstrap_expect = 1 + + server_join { + retry_join = ["lima-$cluster-srv-01.internal"] + } + } + datacenter = "$cluster" + + client { + enabled = true + servers = ["lima-$cluster-srv-01.internal"] + } + EOF + + elif [[ $mode == "client" ]]; then + cat <<-EOF > /etc/nomad.d/nomad.hcl + data_dir = "/opt/nomad/data" + bind_addr = "0.0.0.0" + datacenter = "$cluster" + + client { + enabled = true + servers = ["lima-$cluster-srv-01.internal"] + } + EOF + else + echo "Invalid mode for setConfig" + fi + } + + + # Check if the environment variable 'MODE' is set + if [[ -n $MODE ]]; then + echo "MODE is set to: $MODE" + else + echo "MODE is not set." + fi + + # Check if the environment variable 'CLUSTER' is set + if [[ -n $CLUSTER ]]; then + echo "CLUSTER is set to: $CLUSTER" + else + echo "CLUSTER is not set." + fi + + setConfig $MODE $CLUSTER + - mode: + script: | + systemctl enable --now docker + systemctl enable --now nomad + - mode: user + script: | + #!/bin/sh + nomad -autocomplete-install +networks: + - lima: user-v2 +vmType: qemu +