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 from the docker folder. This is the way the example below use.

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

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)
    dockerFile: "Dockerfile"
    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 used 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
  • {{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 standard 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

The deployments should be able to use {{tags[0]}} as fact

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.5.0.tar.gz (9.5 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.5.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: buildimage-1.5.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for buildimage-1.5.0.tar.gz
Algorithm Hash digest
SHA256 a64dd50b2f683633d3502b4e2653f26d586213d45ec1ba36851b5c92137b256d
MD5 e276cf60b03b0dd577f78e1c4906ddff
BLAKE2b-256 6f3af048ee84d45f7cfc5eb6462285dd0d50028ba2f93c6e73a8e4105ab1c550

See more details on using hashes here.

File details

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

File metadata

  • Download URL: buildimage-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for buildimage-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f237eef6bdca831fe7008acba5cac9e46910ae42de14f2562d0b0fa4dd8bb41
MD5 091b508f7961be1c5388ba23cb7b6bb9
BLAKE2b-256 224e63b7034d820562fee14ac81029bb17ba6bfd8110d626fbad2d9ca032d599

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