diff --git a/pom.xml b/pom.xml index b6360bad55ace3faba438706dbd017912104ab18..d957af9a650b6bed5c2d454f4fee6322108e9304 100644 --- a/pom.xml +++ b/pom.xml @@ -56,9 +56,17 @@ <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> + <!-- Eureka client - Now conditionally activated based on profile --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> + <!-- Only active in non-cloud profiles --> + <exclusions> + <exclusion> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-loadbalancer</artifactId> + </exclusion> + </exclusions> </dependency> <!-- Database drivers --> @@ -67,7 +75,6 @@ <artifactId>postgresql</artifactId> <version>42.7.2</version> </dependency> - <!-- Removing MySQL dependency as PostgreSQL is the preferred DB for cloud deployment --> <!-- H2 Database for testing --> <dependency> @@ -155,4 +162,28 @@ </plugin> </plugins> </build> + + <!-- Add profiles section to control dependency behavior --> + <profiles> + <profile> + <id>cloud</id> + <dependencies> + <!-- In cloud profile, we exclude Eureka client --> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> + <scope>provided</scope> + <optional>true</optional> + </dependency> + </dependencies> + </profile> + + <profile> + <id>local</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <!-- Local profile uses default dependencies with Eureka enabled --> + </profile> + </profiles> </project> diff --git a/src/main/java/com/miage/glop/config/EurekaConfig.java b/src/main/java/com/miage/glop/config/EurekaConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..507d4a1b655f1ab294fb01956dfded98ce1f4431 --- /dev/null +++ b/src/main/java/com/miage/glop/config/EurekaConfig.java @@ -0,0 +1,16 @@ +package com.miage.glop.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * Eureka configuration that's only activated for non-cloud profiles. + * This ensures Eureka client is only used in local development. + */ +@Configuration +@EnableDiscoveryClient +@Profile("!cloud") // Only active when NOT in cloud profile +public class EurekaConfig { + // Configuration is handled through properties files +} diff --git a/src/main/resources/application-cloud.yml b/src/main/resources/application-cloud.yml index 25e8bacb3286012efc1e0284807f9eedce6f1ed9..ee18fa63d0f1bcfe4fc9ece77276c8adf36d3d9a 100644 --- a/src/main/resources/application-cloud.yml +++ b/src/main/resources/application-cloud.yml @@ -1,52 +1,45 @@ -server: - address: 0.0.0.0 - port: ${PORT:80} - error: - include-message: always - spring: - application: - name: user-management-service + main: + banner-mode: OFF datasource: - url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/userdb} - username: ${SPRING_DATASOURCE_USERNAME:postgres} - password: ${SPRING_DATASOURCE_PASSWORD:postgres} + url: jdbc:postgresql://172.29.32.3:5432/bdd_assure + username: dbuser + password: ComplexPassword123! driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: update + show-sql: true properties: hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect - format_sql: true + javax: + persistence: + validation: + mode: auto + application: + name: user-management-service +server: + address: 0.0.0.0 + port: ${PORT:8080} + +# Disable Eureka client for cloud deployment eureka: client: - serviceUrl: - defaultZone: https://eureka-service-682610574114.europe-west1.run.app/eureka/ - registryFetchIntervalSeconds: 30 - healthcheck: - enabled: true - register-with-eureka: true - fetch-registry: true - instance: - prefer-ip-address: true - hostname: ${K_SERVICE:user-management-service}.${K_REVISION:default}.${K_CONFIGURATION:default}.run.app - secure-port: ${PORT:80} - secure-port-enabled: true - non-secure-port-enabled: false - instance-id: ${spring.application.name}:${random.uuid} - ip-address: ${K_REVISION:localhost} - leaseRenewalIntervalInSeconds: 30 - leaseExpirationDurationInSeconds: 90 - metadataMap: - instanceId: ${spring.application.name}:${random.uuid} + enabled: false + register-with-eureka: false + fetch-registry: false + +# Direct service URLs for Cloud Run +insurance-service: + url: https://insurance-service-682610574114.europe-west1.run.app + +incident-service: + url: https://incident-service-682610574114.europe-west1.run.app + +invoice-service: + url: https://invoice-service-682610574114.europe-west1.run.app -management: - endpoints: - web: - exposure: - include: health,info - endpoint: - health: - show-details: always \ No newline at end of file +notification-service: + url: https://notification-service-682610574114.europe-west1.run.app