Project

General

Profile

Actions

Stage4 - Generating base images with packer

Overall build process could look like this:
  • Base: Create base installations with packer
  • Dev run: Setup dev environment via ansible and compile/build/package the needed components
  • After dev run: Extract them and throw away that layer
  • Prod run: Install the built components into the same base image

Reference OS installations

First step is to generate fresh OS installations from installation ISOs with packer. This requires the packer template and a kickstart/preseed file to automate the installer.

Ideally, the images built this way are kept generic enough to be usable as base image for different runtime environments (bwLP, HPC, ...). Only one requirement must be met to use these as Stage4 images with our dracut dnbd3 module, namely a fixed name for the partition label of the root partition inside the created container. In the following examples, the main partition to install the system to is named SLX_SYS. This label is needed during the initramfs, in order to detect the rootfs partition within the dnbd3 image. Creating a custom partitioning scheme is supported by both preseed and kickstart mechanisms. Note that for the CentOS ISO, the KCL argument "inst.gpt" is needed to allow the installer to create GPT partitions for disks under 2TB. The filesystem type is also chosen here, currently only testing with ext4. TODO is to check btrfs support for snapshotting features?

  • create GPT partition label for the root partition within the created image container
  • install packages needed for ansible - this will be needed to provision the base image later on

See Packer Templates for indepth examples.

Templates

The packer-templates repository contains packer templates for Ubuntu 16.04.2 LTS and CentOS 7.3. Read the README for instructions on where to get packer and how to use the templates. Since the VM configuration (CPU, RAM, disk size, ...) is kept separately from the distro's templates as base.json. This should be included in every packer call when using the provided templates!

The templates currently create GPT partitions during the partitioning step of the installer and assigns the label SLX_SYS to the root partition. This is later needed during the stage3 to configure the label of the root partition using the config file's option SLX_SYSTEM_PARTITION_IDENTIFIER.

Usage

Example for the ubuntu template:

packer build -only=qemu -var-file=base.json ubuntu-16.04-amd64.json

If all goes well, this will create a qocw2 disk image in, e.g, output-ubuntu-amd64-qemu-1489595343/packer-ubuntu-amd64, which can bw exported as is to the DNBD3 server.

Debug:

PACKER_LOG=1 PACKER_LOG_PATH=/var/log/packer.log packer build -debug -only=qemu -var-file=base.json ubuntu-16.04-amd64.json

The '-debug' flag will tell packer to wait for input after each internal step. This is great for debugging purposes.

Provisioning

Base images should be general-purpose images, installing usecase specific functionality should be done via different provisioning schemes. The base images generated by packer should only contain the most critical and basic packages (in particular, no graphical interface!).
The only common tasks between various usecases is building the initramfs. This should be implemented in the form of an ansible role/playbook that is always executed on the freshly built images, independently of the distribution.

To not bloat the base image with development packages, a special provisioning run to just setup the required dev packages and build the initramfs (and get the kernel) should be done separately from provisioning the main image.
This could be generalized in a development run, to build components needed for regular operations and extract them out of the VM - the dev layer created hereby can then be thrown away.
The built components can be installed in a fresh cow-layer of the base image. This helps keep clean production system, without any unneeded dev packages. Obviously, the runtime dependencies for the built components needs to be taken care of!

bwLehrpool

WIP:
  • create desktop-like images by installing a desktop session like xfce4/gnome/...
  • mltk'ize the image
    • special dracut target
    • rework some core functions (REQUIRED_PACKAGES, REQUIRED_BINARIES)

Updated by Jonathan Bauer about 7 years ago · 21 revisions