Mise en place docker + mise en place des settings (config ollama / 1min.ai)

This commit is contained in:
2026-04-21 06:51:41 +02:00
parent 8afb17a392
commit 4408c818f3
27 changed files with 1301 additions and 36 deletions

4
core/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
target/
.idea/
*.iml
.mvn/

12
core/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /build
COPY pom.xml .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn clean package -DskipTests -B
FROM eclipse-temurin:17-jre
WORKDIR /app
COPY --from=build /build/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -1,28 +1,37 @@
package com.loremind.infrastructure.web.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.Arrays;
/**
* Configuration CORS pour autoriser les requêtes depuis le Frontend Angular.
* Adaptateur d'infrastructure qui configure la politique CORS.
* Configuration CORS. Origines configurables via la propriete
* `app.cors.allowed-origins` (liste separee par virgules) ou l'env var
* APP_CORS_ALLOWED_ORIGINS. Defaut : Angular dev server + port Docker par defaut.
*/
@Configuration
public class CorsConfig {
@Value("${app.cors.allowed-origins:http://localhost:4200,http://localhost:8081}")
private String allowedOrigins;
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// Autoriser les requêtes depuis localhost:4200 (Angular dev server)
config.addAllowedOrigin("http://localhost:4200");
Arrays.stream(allowedOrigins.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.forEach(config::addAllowedOrigin);
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}

View File

@@ -0,0 +1,70 @@
package com.loremind.infrastructure.web.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
/**
* Proxy fin entre le frontend Angular et les endpoints /settings du Brain Python.
*
* Ce controller n'a aucune logique metier propre : il transfere les requetes
* telles-quelles. Raison d'etre : eviter d'exposer le Brain (port 8000) au
* navigateur et centraliser CORS sur Spring.
*
* Les payloads sont passes en Map<String,Object> pour rester tolerant aux
* evolutions du schema cote Brain (ajout de champs sans recompiler le Core).
*/
@RestController
@RequestMapping("/api/settings")
public class SettingsController {
private final RestTemplate restTemplate;
private final String brainBaseUrl;
public SettingsController(RestTemplate restTemplate,
@Value("${brain.base-url}") String brainBaseUrl) {
this.restTemplate = restTemplate;
this.brainBaseUrl = brainBaseUrl;
}
@GetMapping
public ResponseEntity<Map<String, Object>> getSettings() {
return forward(HttpMethod.GET, "/settings", null);
}
@PutMapping
public ResponseEntity<Map<String, Object>> updateSettings(@RequestBody Map<String, Object> patch) {
return forward(HttpMethod.PUT, "/settings", patch);
}
@GetMapping("/models/ollama")
public ResponseEntity<Map<String, Object>> listOllamaModels() {
return forward(HttpMethod.GET, "/models/ollama", null);
}
@GetMapping("/models/onemin")
public ResponseEntity<Map<String, Object>> listOneMinModels() {
return forward(HttpMethod.GET, "/models/onemin", null);
}
@SuppressWarnings({"rawtypes", "unchecked"})
private ResponseEntity<Map<String, Object>> forward(HttpMethod method, String path, Object body) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
ResponseEntity<Map> response = restTemplate.exchange(
brainBaseUrl + path, method, entity, Map.class);
return ResponseEntity.status(response.getStatusCode()).body((Map<String, Object>) response.getBody());
}
}