Building custom lxd
images can be done in 2022 with Infrastructure as Code principles using Packer & it's lxd plugin.
In the top level of my $PACKER_CONFIG_DIR
I configured the required plugins in plugins.pkr.hcl
& installed them with packer init .
In my ~/.bashrc
I set:
export PACKER_CONFIG_DIR=~/path/to/config/dir
export PACKER_CACHE_DIR=/path/to/cache/on/tmpfs
Looking at this Terraform repo which uses packer
to build the lxd
images was helpful (the packer-plugin-lxd
repo shows a json
builder block) In packer 1.7.0+
you should use HCL format:
# $PACKER_CONFIG_DIR/lxd/ubuntu-2204-base.pkr.hcl
# packer build .
source "lxd" "ubuntu-2204-base" {
image = "images:ubuntu/22.04/amd64"
output_image = "ubuntu-2204-base"
publish_properties = {
description = "Base image for Ubuntu 22.04"
}
}
build {
sources = ["source.lxd.ubuntu-2204-base"]
provisioner "shell" {
inline = [
"apt-get install -q -y nftables iptables",
]
}
}
The above info was enough to generate local
LXD images:
+------------------+--------------+--------+-------------------------------------+--------------+-----------+----------+-------------------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | UPLOAD DATE |
+------------------+--------------+--------+-------------------------------------+--------------+-----------+----------+-------------------------------+
| ubuntu-2204-base | 0e9576339070 | no | Base image for Ubuntu 22.04 | x86_64 | CONTAINER | 198.49MB | Mar 21, 2022 at 4:06pm (UTC) |