-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
build.sh
executable file
·107 lines (90 loc) · 2.96 KB
/
build.sh
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
103
104
105
106
107
#!/bin/bash
set -eux
# Never rely on PWD so we can invoke from anywhere
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Allow us to specify in the caller or pass variables
FLB_DISTRO=${FLB_DISTRO:-}
FLB_OUT_DIR=${FLB_OUT_DIR:-}
FLB_NIGHTLY_BUILD=${FLB_NIGHTLY_BUILD:-}
FLB_JEMALLOC=${FLB_JEMALLOC:-On}
# Use this to pass special arguments to docker build
FLB_ARG=${FLB_ARG:-}
while getopts "v:d:b:t:o:" option
do
case "${option}"
in
d) FLB_DISTRO=${OPTARG};;
o) FLB_OUT_DIR=${OPTARG};;
*) echo "Unknown option";;
esac
done
if [ -z "$FLB_DISTRO" ]; then
echo "$@"
echo "Usage: build.sh -d DISTRO"
echo " ^ "
echo " | ubuntu/20.04"
exit 1
fi
# Prepare output directory
if [ -n "$FLB_OUT_DIR" ]; then
out_dir=$FLB_OUT_DIR
else
out_dir=$(date '+%Y-%m-%d-%H_%M_%S')
fi
volume="$SCRIPT_DIR/packages/$FLB_DISTRO/$out_dir/"
mkdir -p "$volume"
# Info
echo "FLB_DISTRO => $FLB_DISTRO"
echo "FLB_OUT_DIR => $FLB_OUT_DIR"
MAIN_IMAGE="flb-$FLB_DISTRO"
# We either have a specific Dockerfile in the distro directory or we have a generic multi-stage one for all
# of the same OS type:
# - ubuntu/Dockerfile
# - ubuntu/18.04/Dockerfile
# Use the specific one as an override for any special cases but try to keep the general multi-stage one.
# For the multistage ones, we pass in the base image to use.
#
IMAGE_CONTEXT_DIR="$SCRIPT_DIR/distros/$FLB_DISTRO"
if [[ ! -d "$SCRIPT_DIR/distros/$FLB_DISTRO" ]]; then
IMAGE_CONTEXT_DIR="$SCRIPT_DIR/distros/${FLB_DISTRO%%/*}"
FLB_ARG="$FLB_ARG --build-arg BASE_BUILDER=${FLB_DISTRO%%/*}-${FLB_DISTRO##*/}-base --target builder"
fi
if [[ ! -f "$IMAGE_CONTEXT_DIR/Dockerfile" ]]; then
echo "Unable to find $IMAGE_CONTEXT_DIR/Dockerfile"
exit 1
fi
# CMake configuration variables, override via environment rather than parameters
CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-/opt/fluent-bit/}
# This is required to ensure we set the defaults to off for 1.9 builds
FLB_TD=${FLB_TD:-Off}
echo "IMAGE_CONTEXT_DIR => $IMAGE_CONTEXT_DIR"
echo "CMAKE_INSTALL_PREFIX => $CMAKE_INSTALL_PREFIX"
echo "FLB_NIGHTLY_BUILD => $FLB_NIGHTLY_BUILD"
echo "FLB_JEMALLOC => $FLB_JEMALLOC"
export DOCKER_BUILDKIT=1
# Build the main image - we do want word splitting
# shellcheck disable=SC2086
if ! docker build \
--build-arg CMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \
--build-arg FLB_NIGHTLY_BUILD="$FLB_NIGHTLY_BUILD" \
--build-arg FLB_JEMALLOC="$FLB_JEMALLOC" \
--build-arg FLB_TD="$FLB_TD" \
$FLB_ARG \
-t "$MAIN_IMAGE" \
-f "$IMAGE_CONTEXT_DIR/Dockerfile" \
"$SCRIPT_DIR/.."
then
echo "Error building main docker image $MAIN_IMAGE"
exit 1
fi
# Compile and package
if ! docker run \
-v "$volume":/output \
"$MAIN_IMAGE"
then
echo "Could not compile using image $MAIN_IMAGE"
exit 1
fi
echo
echo "Package(s) generated at: $volume"
echo