The Image Generator
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file image-generator-1.1.3.tar.gz
.
File metadata
- Download URL: image-generator-1.1.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3e40e053c7daa62c50238a3168a35eb58b552657b74805fcf8e57930c86f4ab |
|
MD5 | 0c344d9b877f41ccbdb26e7f23f90920 |
|
BLAKE2b-256 | 44e442966e6bcc5848baecf8c1f537b784873054857d5b632f9134675261ef5f |
File details
Details for the file image_generator-1.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: image_generator-1.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d117ca6ed34d0c10b3e510269485ff48f8393df86d05a0fcc6c5eba7106558b |
|
MD5 | 6e859c861b496c8ae35f320221b30051 |
|
BLAKE2b-256 | 18b358765a9ac4a4cfd274518904dd985dc7559bc9cf2944281661bfd037d9bf |