buildimage
Build Docker images from git source for use in Kubernetes deployments. The build images can be tagged with configurable values. The recomended way is to tag it with the tree hash for the docker folder. This is the way the example below use.
By using the tree-hash the source code for building the image is traceable and you can create one complete commit for a change. If using commit hash, two commits is needed. One for the image change and one follow up for the deployment change (kustomize/helm/yaml).
The script uses a file named images.yaml to describe what images to build and what deployments to patch with new tags. Built images will also have some labels with metadata defined. The YAML file can use facts using the Jinja2 template format {{ name }}.
Installation
Install from PyPI:
pip install buildimage
Usage
Run the buildimage command in a directory containing an images.yaml file or specify the directory as an argument:
buildimage [OPTIONS] IMAGES_FILE
Exit codes:
- 0: Ok
- 1: Ok, but built images are dirty with local modifications
- 2: Fail
Options
--nopush: Skip pushing built images--image IMAGE: Only build named images (can be specified multiple times)IMAGES_FILE: Path to theimages.yamlfile (default: ./images.yaml)
Configuration
Create an images.yaml file in your project root with the following format:
images:
- name: "image name" (required)
directory: "build-directory" (required, relative to this images file)
dockerFile: "Dockerfile" (relative to directory)
target: "docker-file-target" (default is none)
tags: (required)
- "tree-{{treeHash}}" (first tag is later available as {{tag}})
- "latest"
labels:
- name: com.mydomain.repository
value: "{{repository}}"
buildArgs:
- name: "build-arg-name"
value: "build-arg-value"
deployments:
- path: "path/to/deployment.yaml"
match: "regex-to-match"
replace: "{{tag}}" (default value)
- kustomize: "../development/kustomize.yaml"
name: "{{name}}" (default value)
newTag: "{{tag}}" (default value)
Available Facts
The following facts are available for templating in images.yaml:
{{branch}}: Current Git branch{{commit}}: Hash for current HEAD commit{{login}}: Currently logged in user performing build{{name}}: Name of current image being built (without tags){{remote}}: Git remote name{{repositoryFull}}: Full repository URL{{repository}}: Repository URL without user info{{tag}}: Tag used for first built image tag (same as tag0. also tag[1..3] are available){{top}}: Top directory path (directory for this images.yaml file){{topTreeHash}}: Git tree hash of the top directory{{treeHash}}: Git tree hash of the image directory (per image)
Labels
Except the custom labels defined in the images.yaml file following labels will be added for the image:
org.opencontainers.image.topTreeHashorg.opencontainers.image.sourceorg.opencontainers.image.revisionorg.opencontainers.image.userorg.opencontainers.image.buildimage
Example
See the tests/docker/ directory for a complete example with test images and deployment updates.
TODO
- Add labels:
- org.opencontainers.image.base.digest
- org.opencontainers.image.base.name see https://github.com/opencontainers/image-spec/blob/main/annotations.md
- Tolerate when not working in a git repository or no remote configured.
Make release
- bumpver update --minor
- uv build
- uv publish
Metadata
Release files for buildimage 1.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| buildimage-1.9.0.tar.gz | 10.2 kB | Without provenance | Details for buildimage-1.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| buildimage-1.9.0-py3-none-any.whl | Python 3 | none | any | Details for buildimage-1.9.0-py3-none-any.whl |
Total release size: 21.5 kB
Release files / buildimage-1.9.0.tar.gz
| Download URL | buildimage-1.9.0.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52c172ee095bb6b2d6a42e40bf5878467837e5c51e07dee114245e9e42fea461
|
|
BLAKE2b-256 checksum How to use checksums |
2a86d160d86b809692aa8db8edf8a4f57e338922c42160909aff9c1e7119bd9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / buildimage-1.9.0-py3-none-any.whl
| Download URL | buildimage-1.9.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52c43f8120c4af71fa3d07c461657c883f841d0424982ec76427edc7932195e1
|
|
BLAKE2b-256 checksum How to use checksums |
d4c7b0f6d94ccb255a35d0bd4ae8d2af00c40dae4c0ca522866815ff9345a52d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for buildimage 1.9.0
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.