~damien/infrastructure

58f3107d9e85b414292ff4b89943ce11f8f3def3 — Damien Radtke 3 months ago 745cdef
Some small image updates
2 files changed, 33 insertions(+), 6 deletions(-)

M packer/image.pkr.hcl
A tools/new-server
M packer/image.pkr.hcl => packer/image.pkr.hcl +18 -6
@@ 32,6 32,11 @@ variable "vault_version" {
  default = "1.7.3"
}

variable "cfssl_version" {
  type = string
  default = "1.6.0"
}

locals {
  timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}


@@ 39,11 44,12 @@ locals {
source "linode" "cluster-image" {
  image             = "linode/opensuse${var.opensuse_version}"
  image_description = <<EOF
	  openSUSE Leap ${var.opensuse_version}
	  Consul ${var.consul_version}
	  Nomad ${var.nomad_version}
	  Vault ${var.vault_version}
  EOF
openSUSE Leap ${var.opensuse_version}
Consul ${var.consul_version}
Nomad ${var.nomad_version}
Vault ${var.vault_version}
CFSSL ${var.cfssl_version}
EOF
  image_label       = "cluster-image-${local.timestamp}"
  instance_label    = "cluster-imaging-${local.timestamp}"
  instance_type     = "g6-nanode-1"


@@ 60,6 66,9 @@ build {
    inline = [
      "zypper --non-interactive install wget jq firewalld moreutils",
      "update-ca-certificates --verbose",
      "mkdir /etc/consul.d",
      "mkdir /etc/nomad.d",
      "mkdir /etc/vault.d",
    ]
  }



@@ 139,7 148,10 @@ build {
  }

  provisioner "shell" {
    inline = ["wget --quiet -O /usr/local/bin/cfssl https://pkg.cfssl.org/R1.2/cfssl_linux-amd64; chmod +x /usr/local/bin/cfssl"]
    inline = [
      "wget --quiet -O /usr/local/bin/cfssl https://github.com/cloudflare/cfssl/releases/download/v${var.cfssl_version}/cfssl_${var.cfssl_version}_linux_amd64",
      "chmod +x /usr/local/bin/cfssl",
    ]
  }
}


A tools/new-server => tools/new-server +15 -0
@@ 0,0 1,15 @@
#!/usr/bin/env bash

image="$(linode-cli --json images list --is_public false \
	| jq 'map(select(.label | startswith("cluster-image-"))) | sort_by(.label) | reverse | .[0]')"

echo "Creating new server with image $(echo "${image}" | jq -r .label):"
echo ""
echo "${image}" | jq -r .description

linode-cli linodes create \
	--type g6-nanode-1 \
	--region ca-central \
	--image "$(echo "${image}" | jq -r .id)" \
	--authorized_keys "$(cat ~/.ssh/id_rsa.pub)" \
	--root_pass "$(openssl rand -base64 32)"