-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathbuild_bundle.sh
More file actions
executable file
·98 lines (73 loc) · 3.02 KB
/
build_bundle.sh
File metadata and controls
executable file
·98 lines (73 loc) · 3.02 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env 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 2021 Datadog, Inc
set -o nounset -o pipefail -o errexit
log_info() {
local BLUE='\033[0;34m'
local RESET='\033[0m'
printf -- "%b%b%b\n" "${BLUE}" "${*}" "${RESET}" 1>&2
}
log_success() {
local GREEN='\033[0;32m'
local RESET='\033[0m'
printf -- "%b%b%b\n" "${GREEN}" "${*}" "${RESET}" 1>&2
}
log_error() {
local RED='\033[0;31m'
local RESET='\033[0m'
printf -- "%b%b%b\n" "${RED}" "${*}" "${RESET}" 1>&2
exit 1
}
# Move into the tools directory
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd $DIR
# Read the desired version
if [[ -z ${1:-} ]]; then
log_error "Must specify a desired version number"
elif [[ ! $1 =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
log_error "Must use a semantic version, e.g., 3.1.4"
else
VERSION=$1
fi
PYTHON_VERSION="${PYTHON_VERSION:-3.13}"
FORWARDER_PREFIX="aws-dd-forwarder"
FORWARDER_DIR="../.forwarder"
make_path_absolute() {
echo "$(
cd "$(dirname "$1")"
pwd
)/$(basename "$1")"
}
../trace_forwarder/scripts/build_linux_go_bin.sh
docker_build_zip() {
# Args: [python version] [zip destination]
zip_destination=$(make_path_absolute "${2}")
layer_destination=$(make_path_absolute "${3}")
# Install datadogpy in a docker container to avoid the mess from switching
# between different python runtimes.
temp_dir=$(mktemp -d)
docker buildx build --platform linux/arm64 --file "${DIR}/Dockerfile_bundle" -t "datadog-bundle:$1" .. --no-cache --build-arg "runtime=${PYTHON_VERSION}"
# Run the image by runtime tag, tar its generated `python` directory to sdout,
# then extract it to a temp directory.
docker run --platform linux/arm64 "datadog-bundle:${1}" tar cf - . | tar -xf - -C "${temp_dir}"
# Zip to destination, and keep directory structure as based in $temp_dir
(cd "${temp_dir}" && zip -q -r "${zip_destination}" ./)
rm -rf "${temp_dir}"
log_success "Done creating forwarder zip archive $zip_destination"
temp_dir=$(mktemp -d)
SUB_DIRECTORY=python
mkdir "${temp_dir}/${SUB_DIRECTORY}"
# Run the image by runtime tag, tar its generated `python` directory to sdout,
# then extract it to a temp directory.
docker run --platform linux/arm64 datadog-bundle:$1 tar cf - . | tar -xf - -C $temp_dir/$SUB_DIRECTORY
# Zip to destination, and keep directory structure as based in $temp_dir
(cd "${temp_dir}" && zip -q -r "${layer_destination}" ./)
log_success "Done creating layer zip archive $layer_destination"
}
rm -rf "${FORWARDER_DIR}"
mkdir "${FORWARDER_DIR}"
docker_build_zip "${PYTHON_VERSION}" "${FORWARDER_DIR}/${FORWARDER_PREFIX}-${VERSION}.zip" "${FORWARDER_DIR}/${FORWARDER_PREFIX}-${VERSION}-layer.zip"
log_success "Successfully created Forwarder bundle!"
ls "${FORWARDER_DIR}" | xargs -I _ echo "${FORWARDER_DIR}/_"