From ba48c6d0c148c102247b9ecc74fe3acfdacceab8 Mon Sep 17 00:00:00 2001 From: Carlos Roman Date: Thu, 14 Dec 2023 10:31:52 +0000 Subject: [PATCH] Added ability to change the final Docker image for misbehaving-jmx-server --- pom.xml | 2 +- tools/misbehaving-jmx-server/Dockerfile | 26 +++++++++++++++++-- tools/misbehaving-jmx-server/scripts/start.sh | 13 ++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100755 tools/misbehaving-jmx-server/scripts/start.sh diff --git a/pom.xml b/pom.xml index 18cd989b3..15b614823 100644 --- a/pom.xml +++ b/pom.xml @@ -200,7 +200,7 @@ org.testcontainers testcontainers - 1.18.0 + 1.19.3 test diff --git a/tools/misbehaving-jmx-server/Dockerfile b/tools/misbehaving-jmx-server/Dockerfile index 938e8c112..ae02c6e48 100644 --- a/tools/misbehaving-jmx-server/Dockerfile +++ b/tools/misbehaving-jmx-server/Dockerfile @@ -1,3 +1,6 @@ +# syntax=docker/dockerfile:1 +# Use by default the JDK image used to build the jar +ARG FINAL_JRE_IMAGE=base # Use the official JDK image as the base image FROM eclipse-temurin:17 AS base @@ -9,22 +12,41 @@ WORKDIR /app # Copy the pom.xml and Maven files and install the dependencies COPY .mvn .mvn/ COPY pom.xml mvnw mvnw.cmd ./ + +# Test containers bug doesn't seem to allow mount cache +# RUN --mount=type=cache,id=mavenCache,target=/root/.m2,sharing=locked \ RUN set -eu && \ ./mvnw dependency:resolve; # Copy the source code and build the JAR file COPY src/ src/ + +# Test containers bug doesn't seem to allow mount cache +# RUN --mount=type=cache,id=mavenCache,target=/root/.m2,sharing=locked \ RUN set -eu && \ ./mvnw clean package assembly:single; # Use the base image as the the final image -FROM base AS final +FROM ${FINAL_JRE_IMAGE} AS final # Set the working directory to /app WORKDIR /app +COPY scripts/start.sh /usr/bin/ + # Copy the JAR file from the Maven image to the final image COPY --from=build /app/target/misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar . +# RMI Port +EXPOSE 9090 + +# Control Port +EXPOSE 9091 + +# Supervisor Port +EXPOSE 9092 + # Run the supervisor class from the jar -CMD ["java", "-cp", "misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar", "org.datadog.supervisor.App"] \ No newline at end of file +ENTRYPOINT [ "/usr/bin/start.sh" ] + +CMD [ "org.datadog.supervisor.App" ] diff --git a/tools/misbehaving-jmx-server/scripts/start.sh b/tools/misbehaving-jmx-server/scripts/start.sh new file mode 100755 index 000000000..6fb93ebdb --- /dev/null +++ b/tools/misbehaving-jmx-server/scripts/start.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +set -f + +echo "Running $@" + +[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx128M -Xms128M" + +# shellcheck disable=SC2086 +java \ + ${JAVA_OPTS} \ + -cp misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar \ + "$@"