Files

44 lines
1.4 KiB
Docker

# ═══════════════════════════════════════════════════════════
# 🐍 OPHION - Java Instrumented App Dockerfile
# Example showing how to add OpenTelemetry to any Java app
# ═══════════════════════════════════════════════════════════
# Build stage
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /app
# Copy Maven/Gradle files (if using build tool)
COPY pom.xml* build.gradle* ./
# Copy source code
COPY src/ ./src/
# For simple example, compile directly
RUN mkdir -p target/classes && \
javac -d target/classes src/main/java/*.java
# Package as JAR
RUN cd target/classes && \
jar cfe ../app.jar Main .
# Runtime stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Download OpenTelemetry Java Agent
ARG OTEL_AGENT_VERSION=2.1.0
RUN wget -q https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${OTEL_AGENT_VERSION}/opentelemetry-javaagent.jar \
-O /opt/opentelemetry-javaagent.jar
# Copy the built application
COPY --from=builder /app/target/app.jar .
# Expose port
EXPOSE 8080
# Start with OpenTelemetry Java Agent
# The JAVA_TOOL_OPTIONS env var in docker-compose.yml enables the agent
CMD ["java", "-jar", "app.jar"]