This repo contains a almost-ready-to-use Debian VM image builder. A nixos version can be found in this branch.
-
edit the ansible playbook: you might want to remove that public key ;)
-
run the builder script:
./build.sh -o test.qcow2 -s5
By default, the image has a functional cloud-init environment and a ssh server.
The runner script allows you to quickly run the image locally:
./run.sh -i test.qcow2
you should be able to login locally:
ssh root@localhost -p50022
The qcow2 format is supported by many cloud providers as is. During boot, the image will use any cloud-init configuration available (ssh keys, network configuration, etc).
Personally, I like to shrink the image to the smallest possible size before uploading it:
$ virt-sparsify test.qcow2 test-sparse.qcow2 # you might need to run this as root
$ pigz test-sparse.qcow2
I use do-image-uploader to upload my images to DigitalOcean:
$ export DO_API_TOKEN=$(pass show do-tokens/personal)
$ do-image-uploader --image-file=test-sparse.qcow2.gz --region=fra1 --name=test-image --wait-until-available
The last configuration step runs the post-install script. By default, this script runs the ansible ansible playbook.