Skip to content

Instantly share code, notes, and snippets.

@eyalkoren
Last active April 27, 2022 04:56
Show Gist options
  • Save eyalkoren/4df45f7032adb5479d19c570e148233b to your computer and use it in GitHub Desktop.
Save eyalkoren/4df45f7032adb5479d19c570e148233b to your computer and use it in GitHub Desktop.
PetClinic sample app with Elastic APM Agent
#Build application stage
FROM maven:3.8.5-jdk-11
WORKDIR /usr/src/java-code
RUN git clone https://github.com/spring-projects/spring-petclinic
WORKDIR /usr/src/java-code/spring-petclinic
RUN mvn -q -B package -DskipTests
RUN mkdir /usr/src/java-app
RUN cp -v /usr/src/java-code/spring-petclinic/target/*.jar /usr/src/java-app/app.jar
#build the agent
ARG JAVA_AGENT_BRANCH=master
ARG JAVA_AGENT_REPO=elastic/apm-agent-java
WORKDIR /usr/src/java-agent-code
RUN curl -L https://github.com/$JAVA_AGENT_REPO/archive/$JAVA_AGENT_BRANCH.tar.gz | tar --strip-components=1 -xz
RUN mvn -q -B package -DskipTests
RUN export JAVA_AGENT_BUILT_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec) \
&& cp -v /usr/src/java-agent-code/elastic-apm-agent/target/elastic-apm-agent-${JAVA_AGENT_BUILT_VERSION}.jar /usr/src/java-app/elastic-apm-agent.jar
FROM openjdk:11
RUN export
WORKDIR /app
COPY --from=0 /usr/src/java-app/*.jar ./
CMD java -javaagent:/app/elastic-apm-agent.jar\
-Dserver.port=${SERVER_PORT:-}\
-Delastic.apm.application_packages=org.springframework.samples.petclinic\
-Dserver.context-path=/petclinic/\
-Dspring.messages.basename=messages/messages\
-Dlogging.level.org.springframework=${LOG_LEVEL:-INFO}\
-Dsecurity.ignored=${SECURITY_IGNORED:-/**}\
-Dbasic.authentication.enabled=${AUTHENTICATION_ENABLED:-false}\
-Dserver.address=${SERVER_ADDRESS:-0.0.0.0}\
-jar /app/app.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment