forked from elastic/apm-agent-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docker.sh
executable file
·75 lines (63 loc) · 2.4 KB
/
build_docker.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
#!/usr/bin/env bash
# See full documentation in the "Creating and publishing Docker images" section
# of CONTRIBUTING.md
set -euxo pipefail
if ! command -v docker
then
echo "ERROR: Building Docker image requires Docker binary to be installed" && exit 1
elif ! docker version
then
echo "ERROR: Building Docker image requires Docker daemon to be running" && exit 1
fi
readonly RELEASE_VERSION=${1}
readonly SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
readonly PROJECT_ROOT=$SCRIPT_PATH/../../
readonly NAMESPACE="observability"
set +e
FILE=$(ls -A ${PROJECT_ROOT}elastic-apm-agent/target/*.jar | grep -E "elastic-apm-agent-[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?.jar" )
set -e
if [ -n "${FILE}" ]
then
# We have build files to use
echo "INFO: Found local build artifact. Using locally built for Docker build"
cp "${FILE}" "${PROJECT_ROOT}apm-agent-java.jar" || echo "INFO: No locally built image found"
elif [ ! -z ${SONATYPE_FALLBACK+x} ]
then
echo "INFO: No local build artifact and SONATYPE_FALLBACK. Falling back to downloading artifact from Sonatype Nexus repository for version $RELEASE_VERSION"
if ! command -v curl
then
echo "ERROR: Pulling images from Sonatype Nexus repo requires cURL to be installed" && exit 1
fi
curl -L -s -o apm-agent-java.jar \
"https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.apm&a=elastic-apm-agent&v=$RELEASE_VERSION"
else
echo "ERROR: No suitable build artifact was found. Re-running this script with the SONATYPE_FALLBACK variable set to true will try to use the Sonatype artifact for the latest tag"
exit 1
fi
ls -l apm-agent-java.jar
echo "INFO: Starting Docker build for version $RELEASE_VERSION"
for DOCKERFILE in "Dockerfile" "Dockerfile.wolfi" ; do
DOCKER_TAG=$RELEASE_VERSION
if [[ $DOCKERFILE =~ "wolfi" ]]; then
DOCKER_TAG="${RELEASE_VERSION}-wolfi"
fi
docker build -t docker.elastic.co/$NAMESPACE/apm-agent-java:$DOCKER_TAG \
--platform linux/amd64 \
--build-arg JAR_FILE=apm-agent-java.jar \
--build-arg HANDLER_FILE=apm-agent-lambda-layer/src/main/assembly/elastic-apm-handler \
--file $DOCKERFILE .
if [ $? -eq 0 ]
then
echo "INFO: Docker image built successfully"
else
echo "ERROR: Problem building Docker image!"
fi
done
function finish {
if [ -f apm-agent-java.jar ]
then
echo "INFO: Cleaning up downloaded artifact"
rm apm-agent-java.jar
fi
}
trap finish EXIT