Editing image version, description from bash

Hi everyone,

I’m planning to use LXD to package and ship my software to remote servers. I made a bash file that packs the application code and installs necessary packages for a Django + angular application.

CONTAINER_NAME="django-server-$(date +"%Y-%m-%d--%I-%M-%p")"

lxc launch ubuntu-minimal:focal ${CONTAINER_NAME}
echo "Waiting container to wake up" #TODO make this into a while loop
sleep 10
echo "Placing files into the container"
lxc exec ${CONTAINER_NAME} -- sh -c "mkdir /home/ubuntu/django"
lxc exec ${CONTAINER_NAME} -- sh -c "mkdir /home/ubuntu/django/c2c"
lxc file push -r c2c/django_server/ ${CONTAINER_NAME}/home/ubuntu/django/c2c/
lxc file push -r c2c/C2CCommon/ ${CONTAINER_NAME}/home/ubuntu/django/c2c/
lxc file push Server.sh ${CONTAINER_NAME}/home/ubuntu/django/
lxc file push -r c2c/angular-webapp/dist/ ${CONTAINER_NAME}/var/www/
echo "Placed all files, now will install necessary packages"
lxc exec ${CONTAINER_NAME} -- sh -c "sudo apt-get update"
lxc exec ${CONTAINER_NAME} -- sh -c "sudo apt-get install -y python3-pip nginx"
lxc exec ${CONTAINER_NAME} -- sh -c "pip3 install -r /home/ubuntu/django/c2c/django_server/requirements.txt"

echo "Finished installation, now packing up the image"
lxc config set ${CONTAINER_NAME} image.description "django Server $(date +"%m/%d/%Y %I:%M%p")"
lxc config set ${CONTAINER_NAME} image.version "$(date +"%Y.%m.%d-%I.%M%p")"
lxc snapshot ${CONTAINER_NAME} current
lxc publish ${CONTAINER_NAME}/current --alias "django-server"
#lxc export ${CONTAINER_NAME} ./${CONTAINER_NAME}.tar.xz

here is my script if anyone wants to use it. However I’m having problems setting the image.version number and also the description. When I take the snapshot and publish it, the description from the base image is used, and the image.version and image.description that I set for the container is ignored.

Only command that I found to edit the image information is the following:

lxc image edit django-server

this spawns a vim console for me to manually edit the information, which is not usable for me because I want to automate all.

Does anyone know how to set the image information from bash?

Thanks.

1 Like

lxc image edit reads YAML from stdin, so you can pass it a mangled YAML representation of the image.

1 Like

If anyone needs it, this is a way to do it.

echo "Setting image versions"
export VERSION="$(date +"%m/%d/%Y %I:%M%p")"
envsubst '${VERSION}' < build/django-image-info.yaml > temp-version.yaml
cat temp-version.yaml | lxc image edit django-server

you can get the image-info.yaml from the image.