summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2017-04-11 18:46:54 +0200
committerJonathan Bauer2017-04-11 18:46:54 +0200
commitdc2de921c387edf0c215b33109f0b6a255f753fd (patch)
treebb20b7e5ad8cba3aad721e304a0b562c9b8bfc17
parent[ubuntu] support root password via ROOTPW env (diff)
downloadpacker-templates-dc2de921c387edf0c215b33109f0b6a255f753fd.tar.gz
packer-templates-dc2de921c387edf0c215b33109f0b6a255f753fd.tar.xz
packer-templates-dc2de921c387edf0c215b33109f0b6a255f753fd.zip
introduce Makefile to simplify building templates
updated ubuntu/centos templates to fixed output names, moved manifest.json to builder's subfolder, updated README.md to reflect the changes
-rw-r--r--Makefile38
-rw-r--r--README.md41
-rw-r--r--centos-7.3-x86_64.json10
-rw-r--r--ubuntu-16.04-amd64.json14
4 files changed, 79 insertions, 24 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..012ccbb
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+# Simple Makefile to build packer templates
+# TODO:
+# - allow overriding packer variables
+# - check for hypervisors (and invalidate targets)
+# - provisioning logic
+BUILDERS = qemu vmware-iso virtualbox-iso
+TEMPLATES := $(basename $(filter-out base.json,$(wildcard *.json)))
+TARGETS := $(foreach builder, $(BUILDERS), $(foreach template, $(TEMPLATES), $(builder)/$(template)))
+PACKER_OPTS := -var-file=base.json
+
+.PHONY: all list clean
+all: list
+
+$(TARGETS):
+ifndef ROOTPW
+ $(error ROOTPW is not set)
+endif
+
+ $(info Building '$(@F)' with '$(@D)')
+ packer build -only=$(@D) \
+ $(PACKER_OPTS) \
+ -var='vm_name=$(@F)' \
+ $(@F).json
+
+list:
+ $(info Possible targets:)
+ @(for F in $(TARGETS); do echo -e "\t$$F" ; done)
+
+clean:
+ $(foreach builder,$(BUILDERS),rm -rf $(builder)/;)
+
+# convenience do-nothing targets for auto-complete
+qemu/ubuntu-16.04-amd64:
+qemu/centos-7.3-x86_64:
+virtualbox-iso/ubuntu-16.04-amd64:
+virtualbox-iso/centos-7.3-x86_64:
+vmware-iso/ubuntu-16.04-amd64:
+vmware-iso/centos-7.3-x86_64:
diff --git a/README.md b/README.md
index aefd6d9..295e3b0 100644
--- a/README.md
+++ b/README.md
@@ -15,24 +15,24 @@ The root password is expected to be in the ROOTPW environment variable.
The installation procedure will fail without it!
Basic usage:
+```shell
ROOTPW=<password> packer build -var-file=base.json <template>
-
-For the rest of the examples, the root password is expected to be exported.
+```
+For the rest of the examples, ROOTPW is assumed to be set in the environment.
## Usage: Creating base images
-Example: build Ubuntu 16.04.2 LTS template using qemu builder
+Example - Build Ubuntu 16.04.2 LTS template using qemu builder
+```shell
packer build -var-file=base.json -only=qemu ubuntu-16.04-amd64.json
-
+```
Debug:
+```shell
PACKER_LOG=1 PACKER_LOG_FILE=/var/log/packer.log \
packer build -debug -only=qemu -var-file=base.json ubuntu-16.04-amd64.json
-
+```
A successful build process would produce a disk image under:
- output-<distro>-<builder>-<timestamp>/packer-<distro>
-
-Example:
- output-ubuntu-qemu-1490876841/packer-ubuntu-amd64
+ <builder>/<template>, e.g. qemu/centos-7.3-x86_64
Additionally, the manifest post-processor creates a manifest.json file in
the working directory containing various information about the generated
@@ -54,9 +54,12 @@ Refer to those repos for more information. The simpliest way to initialize
the submodule is by cloning this repository with '--recursive'.
Build initramfs inside a previously created image:
+```shell
packer build -var-file=base.json \
-var='image_path='"$(jq -r '.builds[0].files[0].name' < manifest.json)"'' \
ansible-roles/run-playbook-only.json
+```
+(This expects 'manifest.json' to contain only one packer artifact.)
The path to the existing image is extracted using the jq tool and given as
'image_path' to the packer provisioning template run-playbook-only.json.
@@ -64,15 +67,27 @@ A successful build would provide the stage3 initramfs and the VM's kernel
in the ansible-roles/boot_files/ directory. Refer to systemd-init for more
information on how to setup a boot environment.
-The packer artifact is created as output-<timestamp>. This provisioned image
+The packer artifact is created in 'output-<timestamp>'. This artifact
contains all the development packages needed to build the initramfs, which
-can be discarded.
+can be discarded. Instead, the base image can be used as the main boot image.
+
+## Makefile
+
+A simple Makefile to build packer templates is provided for convenience.
+See a list of targets with `make list`.
+
+Example - Build CentOS 7.3 with qemu:
+```shell
+ make qemu/centos-7.3-x86_64
+```
## Notes
Variables set in base.json can be overriden using packer's '-var' options, e.g.:
+```shell
packer build -var-file=base.json -var='headless=true' <template>
-(Make sure you first include base.json before overriding a variable!)
+```
+Make sure you first include base.json before overriding a variable!
The partitioning of the virtual disk is done via kickstart/preseed files. Currently,
a simple partition scheme is used: separate boot partition, rest a the main system
@@ -81,7 +96,9 @@ supported, tested were currently xfs and btrfs. If you change the filesystem to
you need to adapt your boot configuration file (SLX_MOUNT_ROOT_OPTIONS).
While the qemu builder produces a qcow2 image, it can be further compressed using:
+```shell
virt-sparsify --compress <qcow2_file> <output_qcow2_file>
+```
## TL;DR
0) git clone --recursive git://git.openslx.org/openslx-ng/packer-templates
diff --git a/centos-7.3-x86_64.json b/centos-7.3-x86_64.json
index 7248dd0..34176c2 100644
--- a/centos-7.3-x86_64.json
+++ b/centos-7.3-x86_64.json
@@ -3,7 +3,7 @@
"iso_url": "http://mirrors.kernel.org/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1611.iso",
"iso_checksum": "f2f7367deb90a25822947660c71638333ca0eceeabecc2d631be6cd508c24494",
"iso_checksum_type": "sha256",
- "vm_name": "packer-centos-x86_64",
+ "vm_name": "centos-7.3-x86_64",
"http_dir": "http",
"kickstart_path": "centos-7.3/anaconda-ks.cfg",
"shutdown_command": "systemctl poweroff",
@@ -14,7 +14,7 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}",
+ "output_directory": "{{ build_type }}",
"vm_name": "{{ user `vm_name` }}",
"format": "qcow2",
"disk_size": "{{ user `disk_size` }}",
@@ -43,7 +43,7 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}",
+ "output_directory": "{{ build_type }}",
"vm_name": "{{ user `vm_name` }}",
"disk_size": "{{ user `disk_size` }}",
"headless": "{{ user `headless` }}",
@@ -70,7 +70,7 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}",
+ "output_directory": "{{ build_type }}",
"vm_name": "{{ user `vm_name` }}",
"disk_size": "{{ user `disk_size` }}",
"headless": "{{ user `headless` }}",
@@ -94,6 +94,6 @@
}],
"post-processors": [{
"type": "manifest",
- "output": "manifest.json"
+ "output": "{{ build_type }}/manifest.json"
}]
}
diff --git a/ubuntu-16.04-amd64.json b/ubuntu-16.04-amd64.json
index 79276fa..67842ed 100644
--- a/ubuntu-16.04-amd64.json
+++ b/ubuntu-16.04-amd64.json
@@ -3,7 +3,7 @@
"iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.2-server-amd64.iso",
"iso_checksum": "737ae7041212c628de5751d15c3016058b0e833fdc32e7420209b76ca3d0a535",
"iso_checksum_type": "sha256",
- "vm_name": "ubuntu-amd64",
+ "vm_name": "ubuntu-16.04-amd64",
"http_dir": "http",
"preseed_path": "ubuntu-16.04/preseed.cfg",
"shutdown_command": "systemctl poweroff",
@@ -14,7 +14,7 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "qemu/output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}",
+ "output_directory": "{{ build_type }}",
"vm_name": "{{ user `vm_name` }}",
"disk_size": "{{ user `disk_size` }}",
"format": "qcow2",
@@ -56,8 +56,8 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}",
- "vm_name": "packer-ubuntu-amd64",
+ "output_directory": "{{ build_type }}",
+ "vm_name": "{{ user `vm_name` }}",
"disk_size": "{{ user `disk_size` }}",
"headless": "{{ user `headless` }}",
"http_directory": "{{ user `http_dir` }}",
@@ -97,8 +97,8 @@
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
- "output_directory": "output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}",
- "vm_name": "packer-ubuntu-amd64",
+ "output_directory": "{{ build_type }}",
+ "vm_name": "{{ user `vm_name` }}",
"disk_size": "{{ user `disk_size` }}",
"headless": "{{ user `headless` }}",
"http_directory": "{{ user `http_dir` }}",
@@ -135,6 +135,6 @@
}],
"post-processors": [{
"type": "manifest",
- "output": "manifest.json"
+ "output": "{{ build_type }}/manifest.json"
}]
}