errordeveloper / imagine

a high-level container image build tool
Other
7 stars 0 forks source link
continuous-delivery continuous-integration docker docker-image-automation docker-image-registry docker-images

imagine - a high-level container image build tool

It is a (slightly) opinionated tool for bulding images with docker buildx bake, it currently implements a few basic commands.

Things imagine has opinions about:

Historically, docker build always needed custom automation logic. The author of imagine has replicated various implementation between a multitude of projects. This tool was born as docker buildx bake was released, which offers huge improvements, however it (rightly) stops short of being opinionated. So imagine offers a few simple feature on top of it by generating JSON build manifests.

How it works?

Main commands

Tagging and Rebuilding

imagine has two tagging modes:

At present git tree hash format is a full-lenght SHA1, while git revision is a short SHA1 (git rev-parse --short). This may change in the future, it may also be possible to pass tag prefix or a custom image tag.

When there changes to any of the checked-in files, -wip suffix is appended. When the build is not a base branch (can be set with --base-brach and defaults to master), a -dev suffix is appended. This behaviour can be controlled with --without-tag-suffix.

Images are rebuilt only when there is no remote image in at least one of the given registries. With git revsion tagging mode this means only new revisions are re-built, and with git tree hash mode it means that new images are built only whenever there are changes to the given subdirectory that defines the image.

A rebuild can be force with --force, or when either of the suffices (-dev and/or -wip) had been appended to the image.

Testing

If you have tests defined in FROM ... as test section of your Dockerfile, you can use --test flag to run those tests.

Examples

First, you need to make sure to setup a BuildKit instance:

builder="$(docker buildx create)"

You can use any pre-existing BuildKit instance (check docker buildx ls), but you cannot use the default docker driver, as it only suppors a limited set of buildx features.

And, pick your username, e.g.:

username=errordeveloper

To build an image that takes examples/alpine subdircorey as input, run:

imagine build \
  --builder "${builder}" \
  --registry "docker.io/${username}" \
  --registry "quay.io/${username}" \
  --name imagine-alpine-example \
  --base ./examples/alpine \

To build an image that is defined by entier repository, run:

imagine build \
  --builder "${builder}" \
  --registry "docker.io/${username}" \
  --registry "quay.io/${username}" \
  --name imagine-imagine-example \
  --root \
  --base ./ \
  --dockerfile ./examples/imagine/Dockerfile