diff --git a/src/ad/Dockerfile.elastic b/src/ad/Dockerfile.elastic index 92502994dd..a42a9cf9be 100644 --- a/src/ad/Dockerfile.elastic +++ b/src/ad/Dockerfile.elastic @@ -16,6 +16,22 @@ RUN ./gradlew installDist -PprotoSourceDir=./proto # ----------------------------------------------------------------------------- +# fetch latest published snapshot of the Elastic OpenTelemetry Java agent, using xq to parse XML +FROM debian:stable-slim AS intermediate +RUN <<-EOF + apt-get update && apt-get install -y curl xq + artifact='elastic-otel-javaagent' + base_url="https://central.sonatype.com/repository/maven-snapshots/co/elastic/otel/${artifact}" + snapshot_version="$(curl -s "${base_url}/maven-metadata.xml" | xq -e metadata/versioning/latest)" + snapshot_timestamp="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/timestamp)" + snapshot_buildnumber="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/buildNumber)" + curl \ + -o /opentelemetry-javaagent.jar \ + "${base_url}/${snapshot_version}/${artifact}-${snapshot_version%-SNAPSHOT}-${snapshot_timestamp}-${snapshot_buildnumber}.jar" +EOF + +# ----------------------------------------------------------------------------- + FROM eclipse-temurin:21-jre # ARG version=0.4.0 @@ -24,7 +40,9 @@ ARG _JAVA_OPTIONS WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/ ./ -ADD --chmod=644 https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=co.elastic.otel&a=elastic-otel-javaagent&v=LATEST /usr/src/app/opentelemetry-javaagent.jar + +COPY --from=intermediate /opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar + ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar ENV OTEL_INFERRED_SPANS_ENABLED=true ENV ELASTIC_OTEL_SPAN_STACK_TRACE_MIN_DURATION=2 diff --git a/src/fraud-detection/Dockerfile.elastic b/src/fraud-detection/Dockerfile.elastic index a6d57c2e7d..3d697b1763 100644 --- a/src/fraud-detection/Dockerfile.elastic +++ b/src/fraud-detection/Dockerfile.elastic @@ -8,13 +8,30 @@ RUN gradle shadowJar # ----------------------------------------------------------------------------- -FROM gcr.io/distroless/java17-debian11 +# fetch latest published snapshot of the Elastic OpenTelemetry Java agent, using xq to parse XML +FROM debian:stable-slim AS intermediate +RUN <<-EOF + apt-get update && apt-get install -y curl xq + artifact='elastic-otel-javaagent' + base_url="https://central.sonatype.com/repository/maven-snapshots/co/elastic/otel/${artifact}" + snapshot_version="$(curl -s "${base_url}/maven-metadata.xml" | xq -e metadata/versioning/latest)" + snapshot_timestamp="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/timestamp)" + snapshot_buildnumber="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/buildNumber)" + curl \ + -o /opentelemetry-javaagent.jar \ + "${base_url}/${snapshot_version}/${artifact}-${snapshot_version%-SNAPSHOT}-${snapshot_timestamp}-${snapshot_buildnumber}.jar" +EOF + +# ----------------------------------------------------------------------------- + +FROM gcr.io/distroless/java17-debian12:nonroot # ARG version=0.4.0 WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/build/libs/fraud-detection-1.0-all.jar ./ -ADD --chmod=644 https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=co.elastic.otel&a=elastic-otel-javaagent&v=LATEST /app/opentelemetry-javaagent.jar +COPY --from=intermediate /opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar + ENV JAVA_TOOL_OPTIONS=-javaagent:/app/opentelemetry-javaagent.jar ENV ELASTIC_OTEL_INFERRED_SPANS_ENABLED=true ENV ELASTIC_OTEL_SPAN_STACK_TRACE_MIN_DURATION=2 diff --git a/src/kafka/Dockerfile.elastic b/src/kafka/Dockerfile.elastic index 98b0e8da83..00c9e1f539 100644 --- a/src/kafka/Dockerfile.elastic +++ b/src/kafka/Dockerfile.elastic @@ -1,6 +1,23 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +# ----------------------------------------------------------------------------- + +# fetch latest published snapshot of the Elastic OpenTelemetry Java agent, using xq to parse XML +FROM debian:stable-slim AS intermediate +RUN <<-EOF + apt-get update && apt-get install -y curl xq + artifact='elastic-otel-javaagent' + base_url="https://central.sonatype.com/repository/maven-snapshots/co/elastic/otel/${artifact}" + snapshot_version="$(curl -s "${base_url}/maven-metadata.xml" | xq -e metadata/versioning/latest)" + snapshot_timestamp="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/timestamp)" + snapshot_buildnumber="$(curl -s "${base_url}/${snapshot_version}/maven-metadata.xml" | xq -e metadata/versioning/snapshot/buildNumber)" + curl \ + -o /opentelemetry-javaagent.jar \ + "${base_url}/${snapshot_version}/${artifact}-${snapshot_version%-SNAPSHOT}-${snapshot_timestamp}-${snapshot_buildnumber}.jar" +EOF + +# ----------------------------------------------------------------------------- FROM apache/kafka:3.7.0 @@ -9,7 +26,7 @@ USER root USER appuser -ADD --chown=appuser:appuser https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=co.elastic.otel&a=elastic-otel-javaagent&v=LATEST /tmp/opentelemetry-javaagent.jar +COPY --from=intermediate /opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar ENV OTEL_INFERRED_SPANS_ENABLED=false ENV ELASTIC_OTEL_SPAN_STACK_TRACE_MIN_DURATION=2