Skip to content

Commit

Permalink
Split build based on build.sh presence
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Sep 21, 2024
1 parent 021d500 commit 34c3db5
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ fixture-kafka-go: fixtures/kafka-go
fixtures/%: LIBRARY=$*
fixtures/%:
$(MAKE) docker-build
docker build -t sample-app -f internal/test/e2e/$(LIBRARY)/Dockerfile .
if [ -f ./internal/test/e2e/$(LIBRARY)/build.sh ]; then \
./internal/test/e2e/$(LIBRARY)/build.sh; \
else \
cd internal/test/e2e/$(LIBRARY) && docker build --build-context ../../../../ -t sample-app . ;\
fi
kind create cluster
kind load docker-image otel-go-instrumentation sample-app
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
Expand All @@ -174,7 +178,7 @@ fixtures/%:
if [ -f ./internal/test/e2e/$(LIBRARY)/collector-helm-values.yml ]; then \
helm install test -f ./internal/test/e2e/$(LIBRARY)/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector; \
else \
helm install test -f .github/workflows/e2e/k8s/collector-helm-values.yml opentelemetry-helm-charts/opentelemetry-collector; \
helm install test -f .github/workflows/e2e/k8s/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector; \
fi
while : ; do \
kubectl get pod/test-opentelemetry-collector-0 && break; \
Expand Down
114 changes: 114 additions & 0 deletions internal/test/e2e/autosdk/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

usage() {
local progname
progname="$( basename "$0" )"

cat <<-EOF
Usage: $progname [OPTIONS]
Builds the SDK end-to-end testing docker image.
OPTIONS:
-t --tag Docker tag to use ["sample-app"]
-h --help Show this help message
EOF
}
parse_opts() {
# Make sure getopts starts at the begining
OPTIND=1
local deliminator option
local arg=
# Translate --gnu-long-options to -g (short options)
for arg
do
deliminator=""
case "$arg" in
--tag)
args="${args}-d "
;;
--help)
args="${args}-h "
;;
*)
[[ "${arg:0:1}" == "-" ]] || deliminator='"'
args="${args}${deliminator}${arg}${deliminator} "
;;
esac
done
# Reset the positional parameters to start parsing short options
eval set -- "$args"
while getopts ":t:h" option
do
case "$option" in
t)
readonly TAG="$OPTARG"
;;
h)
usage
exit 0
;;
*)
echo "Invalid option: -${option}" >&2
usage
exit 1
;;
esac
done
# Default values
[ -z "${TAG}" ] \
&& readonly TAG="sample-app"
return 0
}
build() {
local root_dir="$1"
local local_dir="$2"
local dockerfile="${local_dir}/Dockerfile"
local tag_arg
if [ ! -f "$dockerfile" ]; then
echo "Dockerfile does not exist: $dockerfile"
return 1
fi
if [ ! -d "$root_dir" ]; then
echo "Project root directory does not exist: $root_dir"
return 1
fi
if [ -n "$TAG" ]; then
tag_arg=("-t" "$TAG")
fi
(cd "$root_dir" && docker build "${tag_arg[@]}" -f "$dockerfile" .)
return 0
}
main() {
local root_dir script_dir
# Check dependencies
hash git 2>/dev/null\
|| { echo >&2 "Requrired git client not found"; exit 1; }
hash docker 2>/dev/null\
|| { echo >&2 "Requrired docker client not found"; exit 1; }
parse_opts "$@"
root_dir=$( git rev-parse --show-toplevel )
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
build "$root_dir" "$script_dir"
}
main "$@"

0 comments on commit 34c3db5

Please sign in to comment.