Skip to main content

Build Docker images for use in Kubernetes deployments

Project description

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 the images.yaml file (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.topTreeHash
  • org.opencontainers.image.source
  • org.opencontainers.image.revision
  • org.opencontainers.image.user
  • org.opencontainers.image.buildimage

Example

See the tests/docker/ directory for a complete example with test images and deployment updates.

TODO

Make release

  • bumpver update --minor
  • uv build
  • uv publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

buildimage-1.9.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

buildimage-1.9.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file buildimage-1.9.0.tar.gz.

File metadata

  • Download URL: buildimage-1.9.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for buildimage-1.9.0.tar.gz
Algorithm Hash digest
SHA256 52c172ee095bb6b2d6a42e40bf5878467837e5c51e07dee114245e9e42fea461
MD5 7d1ef0f77636681864cb1cf6fd39c02a
BLAKE2b-256 2a86d160d86b809692aa8db8edf8a4f57e338922c42160909aff9c1e7119bd9d

See more details on using hashes here.

File details

Details for the file buildimage-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: buildimage-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for buildimage-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52c43f8120c4af71fa3d07c461657c883f841d0424982ec76427edc7932195e1
MD5 2a209cde8af0f8f9032afc260adf5f94
BLAKE2b-256 d4c7b0f6d94ccb255a35d0bd4ae8d2af00c40dae4c0ca522866815ff9345a52d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page