-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathbuild-layer.sh
More file actions
executable file
·74 lines (58 loc) · 2.76 KB
/
build-layer.sh
File metadata and controls
executable file
·74 lines (58 loc) · 2.76 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
#!/bin/bash
set -e
SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
## Get OTel version
echo "Info: Getting OTEL Version"
file="$SOURCEDIR/../.github/patches/versions"
version=$(awk -F'=v' '/OTEL_JAVA_INSTRUMENTATION_VERSION/ {print $2}' "$file")
echo "Found OTEL Version: ${version}"
# Exit if the version is empty or null
if [[ -z "$version" ]]; then
echo "Error: Version could not be found in ${file}."
exit 1
fi
## Clone and Patch the OpenTelemetry Java Instrumentation Repository
echo "Info: Cloning and Patching OpenTelemetry Java Instrumentation Repository"
git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.git
pushd opentelemetry-java-instrumentation
git checkout v${version} -b tag-v${version}
# This patch is for Lambda related context propagation
patch -p1 < "$SOURCEDIR"/patches/opentelemetry-java-instrumentation.patch
./gradlew publishToMavenLocal
popd
rm -rf opentelemetry-java-instrumentation
contrib_version=$(awk -F'=v' '/OTEL_JAVA_CONTRIB_VERSION/ {print $2}' "$file")
if [[ -n "$contrib_version" ]]; then
echo "Found OTEL Contrib Version: ${contrib_version}"
## Clone and Patch the OpenTelemetry Java contrib Repository
echo "Info: Cloning and Patching OpenTelemetry Java contrib Repository"
git clone https://github.com/open-telemetry/opentelemetry-java-contrib.git
pushd opentelemetry-java-contrib
git checkout v${contrib_version} -b tag-v${contrib_version}
# There is another patch in the .github/patches directory for other changes. We should apply them too for consistency.
patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-contrib.patch
./gradlew publishToMavenLocal
popd
rm -rf opentelemetry-java-contrib
fi
## Build the ADOT Java from current source
echo "Info: Building ADOT Java from current source"
pushd "$SOURCEDIR"/..
patch -p1 < "${SOURCEDIR}"/patches/aws-otel-java-instrumentation.patch
CI=false ./gradlew publishToMavenLocal -Prelease.version=${version}-adot-lambda1
popd
## Build ADOT Lambda Java SDK Layer Code
echo "Info: Building ADOT Lambda Java SDK Layer Code"
./gradlew build -PotelVersion=${version}
## Copy ADOT Java Agent downloaded using Gradle task and bundle it with the Lambda handler script
echo "Info: Creating the layer artifact"
mkdir -p "$SOURCEDIR"/build/distributions/
cp "$SOURCEDIR"/build/javaagent/aws-opentelemetry-agent*.jar "$SOURCEDIR"/build/distributions/aws-opentelemetry-javaagent.jar
cp otel-instrument "$SOURCEDIR"/build/distributions/otel-instrument
pushd "$SOURCEDIR"/build/distributions
zip -r aws-opentelemetry-java-layer.zip aws-opentelemetry-javaagent.jar otel-instrument
popd
## Cleanup
# revert the patch applied since it is only needed while building the layer.
echo "Info: Cleanup"
git restore ../dependencyManagement/build.gradle.kts