There’s this degree of automation that I want to achieve and I can probably achieve it creating cloud-init scripts and put some shenanigans here and there but I don’t want to reinvent the wheel.
Is there like a repository of app images (wordpress, fancy app, you name it) out there where all you have to do is fill in some variables with the credentials you want and launch it on your LXD server?
Well, any tips welcome on automating deployments are welcome.
You’ll notice that the packer config references scripts and variables defined elsewhere. It’s very flexible. Here is the directory contents where this builder.pkr.hcl template lives.
builder.pkr.hcl # the HCL file shown above
git-script.sh
image-cleanup.sh
install_buildkite.sh # some scripts work on arch AND ubuntu, so they're shared
packages.archlinux.sh
packages.ubuntu_2004.sh # we have a few distro-specific scripts
packages.ubuntu_2104.sh
variables.pkr.hcl # has secrets! don't check it in
variables.pkr.hcl.example # copy example instead
This builds 3 images. After they are done, you will see them in lxc image list.
Packer leaves behind “intermediate” images. They don’t seem to be needed, and since they keep multiplying, I feel like they’re something besides the base images canonical hosts. Get rid of them by deleting images w/o aliases. Only do this if you’re sure you don’t need those blank images! That’s the case for my infra.
#!/bin/bash
set -e
# Packer leaves intermdiate images behind. They can be identified as the images w/o aliases. See `lxc image list`.
for fp in $(lxc image list --format json | jq -r '.[] | select(.aliases | length == 0) | .fingerprint')
do
lxc image delete $fp
done