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/Dockerfileif not given) to be used n-
do not use the cache when building the image
p-
the target platform for the build (the platform of the BuildKit daemon where the build run is used if not given)
t-
one of the two image’s tags (
localif not given); the image will always be tagged withlatest
This script will add the org.opencontainers.image.revision label to the image; its value is set via:
-
the value of a specific CI environment variable (e.g.,
GITHUB_SHAorCI_COMMIT_SHA) -
the hash of the HEAD commit of the checked-out branch; the suffix
-nextwill 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"
...
$ scripts/docker/docker_build.sh -d scripts/docker/Dockerfile -t amd -p linux/amd64
$ docker inspect --format='{{.Os}}/{{.Architecture}}' de.sdavids/sdavids-shell-misc:amd
linux/amd64
$ scripts/docker/docker_build.sh -d scripts/docker/Dockerfile -t arm -p linux/arm64
$ docker inspect --format='{{.Os}}/{{.Architecture}}' de.sdavids/sdavids-shell-misc:arm
linux/arm64