Skip to main content

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.

Prerequisites

sudo apt update && sudo apt install -y python3-pip lxd

After 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:

sudo lxd init

Name of the storage backend to use (dir or zfs) [default=dir]:
Would you like LXD to be available over the network (yes/no) [default=no]? yes
Address to bind LXD to (not including port) [default=all]:
Port to bind LXD to [default=8443]:
Trust password for new clients:
Again:
Do you want to configure the LXD bridge (yes/no) [default=yes]?
   Do you want to setup an IPv4 subnet? Yes
      Default values apply for next questions
   Do you want to setup an IPv6 subnet? No

Install the image generator tool

Install via :

pip3 install image-generator

How to use

It is possible to run it in two way. single action or with config file. The config file is a yaml file containing on the root a list of action to be executed in order with some paramters.

Each action has specific parameters that are listed in the following section

Configure

You have at least one lxc image already downloaded which you can find in your local lxc image store

lxc image list

If not, you can import an ubuntu image on the local image repo with the following command:

lxc image copy ubuntu:16.04 local:

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 >               # Mandatory
  trust-password:             < The trust password you have set for the lxd environment >                    # Mandatory

create-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 enough

copy-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.tar

execute-script:
  script: < Which script to be executed >                                                       # Mandatory
  clean-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 here

create-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 automatically

clean:
  container: < remove the container used for creating the lxc image>                        # default: True
  image-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 >

Run

NOTE if 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 setting

then as a quick fix, you can run:

export LC_ALL=C

Check the help

image-generator --help
usage: image-generator [-h] [-f FILE] [-d] [-action ACTION] [-params PARAMS]
                       [-dry]

optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  the file scenario with the action to execute
  -d, --debug           show debug prints
  -action ACTION        The action to execute
  -params PARAMS        The parameters to the action
  -dry                  Run dryrun

and then run it with sudo:

sudo image-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 it

for testing it is possible to do a dry run by running:

sudo image-generator -f <PATH-TO-THE-CONFIGURATION-FILE> -dry --debug

it will execute every step but the installation script and finally will also delete the downloaded image.

Uninstall

Uninstall via :

pip3 uninstall image-generator

Metadata

Release files for image-generator 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for image-generator 1.1.3
File Size Uploaded Provenance
image-generator-1.1.3.tar.gz 14.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for image-generator 1.1.3
File Interpreter ABI Platform
image_generator-1.1.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.3 kB

Release files / image-generator-1.1.3.tar.gz

Download URL image-generator-1.1.3.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f3e40e053c7daa62c50238a3168a35eb58b552657b74805fcf8e57930c86f4ab
BLAKE2b-256 checksum
How to use checksums
44e442966e6bcc5848baecf8c1f537b784873054857d5b632f9134675261ef5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / image_generator-1.1.3-py2.py3-none-any.whl

Download URL image_generator-1.1.3-py2.py3-none-any.whl
Size 13.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9d117ca6ed34d0c10b3e510269485ff48f8393df86d05a0fcc6c5eba7106558b
BLAKE2b-256 checksum
How to use checksums
18b358765a9ac4a4cfd274518904dd985dc7559bc9cf2944281661bfd037d9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for image-generator 1.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page