diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c5b193f12 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use an official OpenJDK runtime as a parent image +FROM openjdk + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Maven wrapper and the pom.xml file +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ + +# Copy the project source code +COPY src ./src + +# Package the application +RUN ./mvnw package + +# Copy the JAR file to the app directory +COPY target/*.jar app.jar + +# Run the jar file +CMD ["java", "-jar", "app.jar"] + +# Expose the port the app runs on +EXPOSE 8080 \ No newline at end of file diff --git a/pom.xml b/pom.xml index a9bbd2959..975db3da4 100644 --- a/pom.xml +++ b/pom.xml @@ -139,6 +139,11 @@ jakarta.xml.bind-api + + + io.micrometer + micrometer-registry-prometheus + diff --git a/spring-petclinic.yml b/spring-petclinic.yml new file mode 100644 index 000000000..562732d97 --- /dev/null +++ b/spring-petclinic.yml @@ -0,0 +1,27 @@ +services: + petclinic: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + networks: + - custom-network + + prometheus: + image: prom/prometheus:latest + ports: + - "9090:9090" + volumes: + - prometheus_data:/prometheus + - ./prometheus.yml:/etc/prometheus/prometheus.yml + networks: + - custom-network + depends_on: + - petclinic + +volumes: + prometheus_data: + +networks: + custom-network: \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5d3eeed32..11113c06a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,3 +23,9 @@ logging.level.org.springframework=INFO # Maximum time static resources should be cached spring.web.resources.cache.cachecontrol.max-age=12h + +# Configure the Prometheus endpoint +management.endpoint.prometheus.enabled=true + +# Enable Prometheus metrics export +management.metrics.export.prometheus.enabled=true \ No newline at end of file