-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild_ubi9.sh
More file actions
executable file
·66 lines (52 loc) · 1.62 KB
/
Copy pathbuild_ubi9.sh
File metadata and controls
executable file
·66 lines (52 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
usage() {
echo "Usage: $0 [--push] <collector-dir> <version>" >&2
echo " --push Push the image after building" >&2
echo " collector-dir Path to the collector (e.g. mitre-attack)" >&2
echo " version Image version tag" >&2
exit 1
}
PUSH=false
if [ "$1" = "--push" ]; then
PUSH=true
shift
fi
COLLECTOR_DIR="${1:?$(usage)}"
VERSION="${2:?$(usage)}"
# Resolve and validate
COLLECTOR_DIR="${COLLECTOR_DIR%/}"
if [ ! -d "${COLLECTOR_DIR}" ]; then
echo "Error: collector directory '${COLLECTOR_DIR}' does not exist." >&2
exit 1
fi
# Auto-compute COLLECTOR_CMD from directory name
MODULE_NAME=$(echo "${COLLECTOR_DIR}" | tr '-' '_')
COLLECTOR_CMD="${MODULE_NAME}.openaev_${MODULE_NAME}"
IMAGE="openaev/collector-${COLLECTOR_DIR}:${VERSION}-ubi9"
ENV_FILE="${COLLECTOR_DIR}/.build.env"
# Collector-specific overrides from env file (e.g. COLLECTOR_CMD)
if [ -f "${ENV_FILE}" ]; then
. "${ENV_FILE}"
fi
# Build argument list
set -- "$@" --platform "linux/amd64"
set -- -f "${SCRIPT_DIR}/Dockerfile_ubi9"
set -- "$@" --build-arg "COLLECTOR_CMD=${COLLECTOR_CMD}"
# Append remaining collector-specific overrides from env file as --build-arg flags
if [ -f "${ENV_FILE}" ]; then
eval set -- '"$@"' $(sed '/^$/d; /^#/d; /^COLLECTOR_CMD=/d; s/^/--build-arg /' "${ENV_FILE}")
fi
set -- "$@" -t "${IMAGE}"
set -- "$@" "${COLLECTOR_DIR}"
if command -v podman >/dev/null 2>&1; then
RUNTIME=podman
else
RUNTIME=docker
fi
${RUNTIME} build "$@"
if [ "${PUSH}" = true ]; then
echo "Pushing ${IMAGE}..."
${RUNTIME} push "${IMAGE}"
fi