docker_build

This script will build the ${namespace}/${repository} image, i.e. the project’s image.

The following parameters are supported:

d

the path to the Dockerfile ($PWD/Dockerfile if not given) to be used

n

do not use the cache when building the image

t

one of the two image’s tags (local if not given); the image will always be tagged with latest

This script will add the org.opencontainers.image.revision label to the image; its value is set via:

  1. the value of a specific CI environment variable (e.g. GITHUB_SHA or CI_COMMIT_SHA)

  2. the hash of the HEAD commit of the checked out branch; the suffix -next will be appended if the working tree is dirty.

This script will add the org.opencontainers.image.created label to the image with the creation timestamp of the HEAD commit of the checked out branch as its value; the current time will be used if the working tree is dirty. Alternatively, you can use the SOURCE_DATE_EPOCH environment variable to pass in the timestamp.

See the general Docker script usage notes.

Usage

$ scripts/docker/docker_build.sh
$ scripts/docker/docker_build.sh -n

$ scripts/docker/docker_build.sh -d scripts/docker/Dockerfile
...
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:latest
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:local
...

$ scripts/docker/docker_build.sh -d scripts/docker/Dockerfile -t example
...
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:latest
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:example
...
"org.opencontainers.image.created":"2024-05-05T11:05:50Z"
...
"org.opencontainers.image.revision":"46cca5eff61eabb008ed43e81988e6a9099aa469"
...

$ touch dirty-repo
$ SOURCE_DATE_EPOCH=0 scripts/docker/docker_build.sh -d scripts/docker/Dockerfile -t 1.2.3
...
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:latest
 => => naming to docker.io/sdavids-shell-misc/sdavids-shell-misc-docker:1.2.3
...
"org.opencontainers.image.created":"1970-01-01T00:00:00Z"
...
"org.opencontainers.image.revision":"46cca5eff61eabb008ed43e81988e6a9099aa469-next"
...

Prerequisites