Package: image-generator
A python based generator for lxc images.It will read a configuration from a yaml file, starts a container
accordingly, copies and runs specific scripts and in the end creates a
lxc image.Prerequisitessudoaptupdate&&sudoaptinstall-ypython3-piplxdAfter the installation you will need to configure your lxd environment.
Depending on your desired image and scripts the container may need
internet connectivity, so make sure you activate NAT connectivity for
your containers:sudolxdinitNameofthestoragebackendtouse(dirorzfs)[default=dir]:WouldyoulikeLXDtobeavailableoverthenetwork(yes/no)[default=no]?yesAddresstobindLXDto(notincludingport)[default=all]:PorttobindLXDto[default=8443]:Trustpasswordfornewclients:Again:DoyouwanttoconfiguretheLXDbridge(yes/no)[default=yes]?DoyouwanttosetupanIPv4subnet?YesDefaultvaluesapplyfornextquestionsDoyouwanttosetupanIPv6subnet?NoInstall the image generator toolInstall via :pip3installimage-generatorHow to useIt is possible to run it in two way.single actionor withconfig file. The config file is a yaml file containing on the root a
list of action to be executed in order with some paramters.Eachactionhas specific parameters that are listed in the following
sectionConfigureYou have at least one lxc image already downloaded which you can find in
your local lxc image storelxcimagelistIf not, you can import an ubuntu image on the local image repo with the
following command:lxcimagecopyubuntu:16.04local:And take note of the fingerprint you need for the next steps.The config file should look like:connect:url:< The URL with port where to reach lxd engine ># Mandatorytrust-password:< The trust password you have set for the lxd environment ># Mandatorycreate-container:container-name:< The name of the container which will be created ># default: "image-generator"container-image-fingerprint:< The fingeprint of the image which will be used as base image for the container ># Mandatory; you do not need the complete image fingerprint, the one shown by lxc image list is enoughcopy-files:file-tarball:< Path to the tar archive containing all scripts you want to push on the image ># default: "./etc/files.tar"file-dest:< Path where to copy the content of the tar archive on the container ># default /root/files.tarexecute-script:script:< Which script to be executed ># Mandatoryclean-tmp-files:< remove the temporary files used for copying the tarball on the container># default: False# lxc always assumes you are in /root, thus take care if you use relative paths to the scripts herecreate-image:destination:< Path of the folder where the image will be saved ># default: "/tmp"alias:<additional alias to give to the created image># default: "Published by image-generator"name:<name of the result image># generated-image# if the destination does not yet contain the ending tar.gz it will be added automaticallyclean:container:< remove the container used for creating the lxc image># default: Trueimage-store:< remove the image created from the container from your local image store># default: True# You can (re)import the images anytime by lxc image import < Your path to the desired image.tar.gz > --alias < Your Alias here >RunNOTEif you get this error while running image generator:Traceback (most recent call last):
  File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale settingthen as a quick fix, you can run:exportLC_ALL=CCheck the helpimage-generator--helpusage:image-generator[-h][-fFILE][-d][-actionACTION][-paramsPARAMS][-dry]optionalarguments:-h,--helpshowthishelpmessageandexit-fFILE,--fileFILEthefilescenariowiththeactiontoexecute-d,--debugshowdebugprints-actionACTIONTheactiontoexecute-paramsPARAMSTheparameterstotheaction-dryRundryrunand then run itwith sudo:sudoimage-generator-f<PATH-TO-THE-CONFIGURATION-FILE>sudo rights are needed only because it is required by the process of
extracting the image downloaded from lxd.Test itfor testing it is possible to do a dry run by running:sudoimage-generator-f<PATH-TO-THE-CONFIGURATION-FILE>-dry--debugit will execute every step but the installation script and finally will
also delete the downloaded image.UninstallUninstall via :pip3uninstallimage-generator