-
Notifications
You must be signed in to change notification settings - Fork 14
/
build
executable file
·103 lines (79 loc) · 2.17 KB
/
build
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# Build RPMs with docker
set -euo pipefail
export LC_ALL=C
DOCKER_PKG_DIR="/pkg"
DOCKER_RPMBUILD_DIR="${DOCKER_PKG_DIR}/rpmbuild"
SCRIPT_DIR=$(dirname $(readlink -f $0))
HOST_RPMBUILD_DIR="${SCRIPT_DIR}/rpmbuild"
PACKAGER="$(basename "${0}")"
DEBUG="no"
# Usage
usage() {
cat << _EOF_
Usage:
${PACKAGER} [-d] BUILD_IMAGE_NAME:BUILD_IMAGE_TAG [BUILD_RPM_OPTIONS]
Options:
-d Debug mode
BUILD_RPM_OPTIONS
build-rpm options (default: -a -bi -o yes)
Environment variables:
BUILD_HOSTNAME: container host name
Build for AlmaLinux 9:
${PACKAGER} almalinux:9
Build for AlmaLinux 8:
${PACKAGER} almalinux:8
Build for CentOS 7:
${PACKAGER} centos:7
_EOF_
}
build() {
local BUILD_IMAGE="${1}"
shift
local BUILD_RPM_OPTIONS="${@:--a -bi -o yes}"
local BUILD_IMAGE_NAME=$(echo ${BUILD_IMAGE} | cut -d':' -f 1)
local BUILD_IMAGE_TAG=$(echo ${BUILD_IMAGE} | cut -d':' -f 2)
local MODULE_VERSION=$(echo ${BUILD_IMAGE} | cut -d':' -f 3)
local BUILD_IMAGE="${BUILD_IMAGE_NAME}:${BUILD_IMAGE_TAG}"
local BUILD_HOSTNAME="${BUILD_HOSTNAME:-${HOSTNAME}}"
local DOCKER_OPTIONS=""
local BUILD_CMD="${DOCKER_PKG_DIR}/setup && ${DOCKER_PKG_DIR}/build-rpm ${BUILD_RPM_OPTIONS}"
if [[ "${DEBUG}" = "yes" ]]; then
echo "# Manual Build: ${BUILD_CMD}"
DOCKER_OPTIONS="-it"
BUILD_CMD="/bin/bash"
fi
# Update build image
docker pull ${BUILD_IMAGE}
# Build
docker run \
--name ${BUILD_HOSTNAME} \
-h "${BUILD_HOSTNAME}" \
-v "${SCRIPT_DIR}":$(dirname ${DOCKER_RPMBUILD_DIR}) \
--rm=true \
${DOCKER_OPTIONS} \
${BUILD_IMAGE} \
/bin/bash -c "${BUILD_CMD}"
}
# Main
main() {
[[ $# -lt 1 ]] && usage && exit 1
while getopts dh OPT; do
case "${OPT}" in
"d" )
DEBUG="yes" ;;
"h" )
usage
exit 0
;;
* )
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
build "${@}"
}
[[ ${#BASH_SOURCE[@]} = 1 ]] && main "${@}"