Browse Source

packer: Use jq to compose templates

Michael Aldridge 4 years ago
parent
commit
e9dea2d32c

+ 1 - 0
packer/.gitignore

@@ -2,3 +2,4 @@ output_*
 packer_cache
 crash.log
 *.box
+templates/

+ 12 - 0
packer/Makefile

@@ -0,0 +1,12 @@
+TEMPLATES=templates/digitalocean-glibc64.json templates/vagrant-glibc64.json
+
+all: $(TEMPLATES)
+
+templates:
+	mkdir -p templates
+
+templates/digitalocean-glibc64.json: templates fragments/base-qemu-glibc64.json fragments/provisioner-cloud.json fragments/platform-digitalocean.json
+	jq -s 'add' fragments/base-qemu-glibc64.json fragments/provisioner-cloud.json fragments/platform-digitalocean.json > templates/digitalocean-glibc64.json
+
+templates/vagrant-glibc64.json: templates fragments/base-vbox-glibc64.json fragments/platform-vagrant.json
+	jq -s 'add' fragments/base-vbox-glibc64.json fragments/platform-vagrant.json > templates/vagrant-glibc64.json

+ 1 - 28
packer/templates/digitalocean-glibc64.json → packer/fragments/base-qemu-glibc64.json

@@ -22,32 +22,5 @@
       "type": "qemu",
       "vm_name": "DO-glibc64"
     }
-  ],
-  "post-processors": [
-    {
-      "image_description": "Packer import {{timestamp}}",
-      "image_name": "void-linux-{{user `release`}}",
-      "image_regions": "{{user `image_regions`}}",
-      "image_tags": [
-        "custom",
-        "packer"
-      ],
-      "space_name": "{{user `spaces_bucket`}}",
-      "spaces_region": "{{user `spaces_region`}}",
-      "type": "digitalocean-import"
-    }
-  ],
-  "provisioners": [
-    {
-      "execute_command": "echo 'void' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
-      "script": "scripts/cloud.sh",
-      "type": "shell"
-    }
-  ],
-  "variables": {
-    "image_regions": "{{env `IMAGE_REGIONS`}}",
-    "spaces_bucket": "{{env `SPACES_BUCKET`}}",
-    "spaces_region": "{{env `SPACES_REGION`}}",
-    "release": "{{env `RELEASE`}}"
-  }
+  ]
 }

+ 1 - 23
packer/templates/vagrant-glibc64.json → packer/fragments/base-vbox-glibc64.json

@@ -27,27 +27,5 @@
       ],
       "virtualbox_version_file": ".vbox_version"
     }
-  ],
-  "post-processors": [
-    [
-      {
-        "type": "vagrant"
-      },
-      {
-        "box_tag": "voidlinux/glibc64",
-        "type": "vagrant-cloud",
-        "version": "{{user `version`}}"
-      }
-    ]
-  ],
-  "provisioners": [
-    {
-      "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
-      "script": "scripts/vagrant.sh",
-      "type": "shell"
-    }
-  ],
-  "variables": {
-    "version": "{{env `RELEASE`}}"
-  }
+  ]
 }

+ 22 - 0
packer/fragments/platform-digitalocean.json

@@ -0,0 +1,22 @@
+{
+  "post-processors": [
+    {
+      "image_description": "Packer import {{timestamp}}",
+      "image_name": "void-linux-{{user `release`}}",
+      "image_regions": "{{user `image_regions`}}",
+      "image_tags": [
+        "custom",
+        "packer"
+      ],
+      "space_name": "{{user `spaces_bucket`}}",
+      "spaces_region": "{{user `spaces_region`}}",
+      "type": "digitalocean-import"
+    }
+  ],
+  "variables": {
+    "image_regions": "{{env `IMAGE_REGIONS`}}",
+    "spaces_bucket": "{{env `SPACES_BUCKET`}}",
+    "spaces_region": "{{env `SPACES_REGION`}}",
+    "release": "{{env `RELEASE`}}"
+  }
+}

+ 24 - 0
packer/fragments/platform-vagrant.json

@@ -0,0 +1,24 @@
+{
+  "post-processors": [
+    [
+      {
+        "type": "vagrant"
+      },
+      {
+        "box_tag": "voidlinux/glibc64",
+        "type": "vagrant-cloud",
+        "version": "{{user `version`}}"
+      }
+    ]
+  ],
+  "provisioners": [
+    {
+      "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
+      "script": "scripts/vagrant.sh",
+      "type": "shell"
+    }
+  ],
+  "variables": {
+    "version": "{{env `RELEASE`}}"
+  }
+}

+ 9 - 0
packer/fragments/provisioner-cloud.json

@@ -0,0 +1,9 @@
+{
+  "provisioners": [
+    {
+      "execute_command": "echo 'void' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
+      "script": "scripts/cloud.sh",
+      "type": "shell"
+    }
+  ]
+}