Skip to content

Commit 4b4ed9e

Browse files
committed
Add a helper docker-build.sh script for manual builds
1 parent c472f90 commit 4b4ed9e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

docker-build.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is used to build a Docker image for Icinga 2.
4+
5+
# Action defines the type of build to perform. It can be one of:
6+
#
7+
# - load: Build the image for the building platform and load it into the local Docker engine image storage.
8+
# - push: Build the image for all specified platforms and push them to the Docker registry (icinga/icinga2:<TAG>).
9+
# - cache: Build the image for all specified platforms using the default Buildx's exporter (cacheonly) and will just
10+
# create a cache for each platform. There will be no images that you can use but any subsequent build will use the
11+
# cache and speed up the build process.
12+
#
13+
# If no action is provided, it defaults to "load", and any specified platforms will be ignored.
14+
ACTION="${1:-load}"
15+
# Tag defines the tag to use for the built image. If not provided, it defaults to "test".
16+
# The resulting image will be tagged as "icinga/icinga2:<TAG>".
17+
TAG="${2:-test}"
18+
# Platform defines the platforms to build the image for. It defaults to "linux/amd64,linux/arm64/v8".
19+
PLATFORM="${3:-linux/amd64,linux/arm64/v8}"
20+
21+
if ! command -v docker &> /dev/null; then
22+
echo "Docker is not installed. Please install Docker to build the image." >&2
23+
exit 1
24+
fi
25+
26+
if ! command -v docker buildx &> /dev/null; then
27+
echo "Docker Buildx is not installed. Please install Docker Buildx to build the image." >&2
28+
exit 1
29+
fi
30+
31+
# Set up the buildx command with the specified platform.
32+
BuildX=(docker buildx build --platform "${PLATFORM}")
33+
BUILD_ARGS=(-t "icinga/icinga2:${TAG}" -f Containerfile .)
34+
35+
# Check the action and perform the appropriate build command.
36+
case "$ACTION" in
37+
push)
38+
"${BuildX[@]}" --push "${BUILD_ARGS[@]}"
39+
;;
40+
load)
41+
docker buildx build --load "${BUILD_ARGS[@]}"
42+
;;
43+
cache)
44+
"${BuildX[@]}" "${BUILD_ARGS[@]}"
45+
;;
46+
*)
47+
echo "Unknown action: ${ACTION}. Valid actions are: local, push, all." >&2
48+
exit 1
49+
esac

0 commit comments

Comments
 (0)