diff --git a/Dockerfile b/Dockerfile index b958477..f61ec11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN addgroup spring && useradd -g spring spring USER spring:spring # https://github.com/microsoft/ApplicationInsights-Java/releases -ADD --chown=spring:spring https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.19/applicationinsights-agent-3.4.19.jar /applicationinsights-agent.jar +ADD --chown=spring:spring https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.6.0/applicationinsights-agent-3.6.0.jar /applicationinsights-agent.jar COPY --chown=spring:spring docker/applicationinsights.json ./applicationinsights.json diff --git a/README.md b/README.md index 4a9ad80..485244a 100644 --- a/README.md +++ b/README.md @@ -1 +1,52 @@ # docker-base-template based on Java 17 +This image is based on `eclipse-temurin:17-jre` with applicationinsights agent v3.6.0. + +It is useful to run a SpringBoot application v2/v3. + +## How to use +``` Dockerfile +# +# Build +# +FROM maven:3.9.3-amazoncorretto-17@sha256:4ab7db7bd5f95e58b0ba1346ff29d6abdd9b73e5fd89c5140edead8b037386ff AS buildtime +WORKDIR /build +COPY . . +RUN mvn clean package -Dmaven.test.skip=true + +# +# Package stage +# +FROM --platform=linux/amd64 amazoncorretto:17.0.9-alpine3.18@sha256:df48bf2e183230040890460ddb4359a10aa6c7aad24bd88899482c52053c7e17 as builder +COPY --from=buildtime /build/target/*.jar application.jar +RUN java -Djarmode=layertools -jar application.jar extract + +# +# Run +# +FROM ghcr.io/pagopa/docker-base-springboot-openjdk17:v2.1.2@sha256:824a241756a32ac9eeef4585a3a266fb019d2c599337269b0c8b419de4c2df3e + +COPY --chown=spring:spring --from=builder dependencies/ ./ +COPY --chown=spring:spring --from=builder snapshot-dependencies/ ./ + +# https://github.com/moby/moby/issues/37965#issuecomment-426853382 +RUN true +COPY --chown=spring:spring --from=builder spring-boot-loader/ ./ +COPY --chown=spring:spring --from=builder application/ ./ +``` + + +## Application Insights Agent +The agent uses the configuration `/docker/applicationinsights.json`. +By default, the sampling is enabled + - dependency: 5% + - trace: 5% + - exception: 100% + - request: 100% + +If you want to customize the agent you can add your file in the `Dockerimage` + +``` Dockerfile +FROM ghcr.io/pagopa/docker-base-springboot-openjdk17:v2.1.2@sha256:824a241756a32ac9eeef4585a3a266fb019d2c599337269b0c8b419de4c2df3e +COPY --chown=spring:spring your/path/to/applicationinsights.json ./applicationinsights.json +``` + diff --git a/docker/applicationinsights.json b/docker/applicationinsights.json index 0d7f750..f205272 100644 --- a/docker/applicationinsights.json +++ b/docker/applicationinsights.json @@ -4,20 +4,24 @@ "level": "INFO" }, "sampling": { - "percentage": 5 - }, - "preview": { - "sampling": { - "overrides": [ - { - "telemetryType": "exception", - "percentage": 100 - }, - { - "telemetryType": "request", - "percentage": 100 - } - ] - } + "percentage": 5, + "overrides": [ + { + "telemetryType": "dependency", + "percentage": 5 + }, + { + "telemetryType": "trace", + "percentage": 5 + }, + { + "telemetryType": "exception", + "percentage": 100 + }, + { + "telemetryType": "request", + "percentage": 100 + } + ] } }