-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcompile_bottlecap.sh
More file actions
executable file
·77 lines (61 loc) · 1.89 KB
/
compile_bottlecap.sh
File metadata and controls
executable file
·77 lines (61 loc) · 1.89 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
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2024 Datadog, Inc.
set -e
if [ -z "$ARCHITECTURE" ]; then
printf "[ERROR]: ARCHITECTURE not specified\n"
exit 1
fi
if [ -z "$FILE_SUFFIX" ]; then
printf "[WARNING] No FILE_SUFFIX provided, using ${ARCHITECTURE}\n"
FILE_SUFFIX=$ARCHITECTURE
fi
if [ -z "$ALPINE" ]; then
printf "[ERROR]: ALPINE not specified\n"
exit 1
else
printf "Alpine compile requested: ${ALPINE}\n"
fi
if [ -z "$FIPS" ]; then
printf "[ERROR]: FIPS not specified\n"
exit 1
else
printf "Fips compile requested: ${FIPS}\n"
fi
if [ "$ALPINE" = "0" ]; then
COMPILE_IMAGE=Dockerfile.bottlecap.compile
else
printf "Compiling for alpine\n"
COMPILE_IMAGE=Dockerfile.bottlecap.alpine.compile
fi
# Move into the root directory, so this script can be called from any directory
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT_DIR=$SCRIPTS_DIR/../..
cd $ROOT_DIR
BINARY_DIR=".binaries"
TARGET_DIR=$(pwd)/$BINARY_DIR
BINARY_PATH=$TARGET_DIR/compiled-bottlecap-$FILE_SUFFIX
mkdir -p $BINARY_DIR
cd $ROOT_DIR
docker_build() {
local arch=$1
local file=$2
if [ "$arch" == "amd64" ]; then
PLATFORM="x86_64"
else
PLATFORM="aarch64"
fi
docker buildx build --platform linux/${arch} \
--progress plain \
-t datadog/compile-bottlecap \
-f ./images/${file} \
--build-arg PLATFORM=$PLATFORM \
--build-arg FIPS="${FIPS}" \
. -o $BINARY_PATH
# Copy the compiled binary to the target directory with the expected name
# If it already exist, it will be replaced
cp $BINARY_PATH/bottlecap $TARGET_DIR/bottlecap-$FILE_SUFFIX
}
docker_build $ARCHITECTURE $COMPILE_IMAGE