Skip to content
Snippets Groups Projects
Commit d091fc9c authored by Abdellatif Kebraoui's avatar Abdellatif Kebraoui
Browse files

[FEAT] implement conditional Eureka client activation based on profiles for cloud deployment

parent ecc3261e
Branches
No related tags found
No related merge requests found
...@@ -56,9 +56,17 @@ ...@@ -56,9 +56,17 @@
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- Eureka client - Now conditionally activated based on profile -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <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> </dependency>
<!-- Database drivers --> <!-- Database drivers -->
...@@ -67,7 +75,6 @@ ...@@ -67,7 +75,6 @@
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.7.2</version> <version>42.7.2</version>
</dependency> </dependency>
<!-- Removing MySQL dependency as PostgreSQL is the preferred DB for cloud deployment -->
<!-- H2 Database for testing --> <!-- H2 Database for testing -->
<dependency> <dependency>
...@@ -155,4 +162,28 @@ ...@@ -155,4 +162,28 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </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> </project>
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
}
server:
address: 0.0.0.0
port: ${PORT:80}
error:
include-message: always
spring: spring:
application: main:
name: user-management-service banner-mode: OFF
datasource: datasource:
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/userdb} url: jdbc:postgresql://172.29.32.3:5432/bdd_assure
username: ${SPRING_DATASOURCE_USERNAME:postgres} username: dbuser
password: ${SPRING_DATASOURCE_PASSWORD:postgres} password: ComplexPassword123!
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
jpa: jpa:
hibernate: hibernate:
ddl-auto: update ddl-auto: update
show-sql: true
properties: properties:
hibernate: hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect 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: eureka:
client: client:
serviceUrl: enabled: false
defaultZone: https://eureka-service-682610574114.europe-west1.run.app/eureka/ register-with-eureka: false
registryFetchIntervalSeconds: 30 fetch-registry: false
healthcheck:
enabled: true # Direct service URLs for Cloud Run
register-with-eureka: true insurance-service:
fetch-registry: true url: https://insurance-service-682610574114.europe-west1.run.app
instance:
prefer-ip-address: true incident-service:
hostname: ${K_SERVICE:user-management-service}.${K_REVISION:default}.${K_CONFIGURATION:default}.run.app url: https://incident-service-682610574114.europe-west1.run.app
secure-port: ${PORT:80}
secure-port-enabled: true invoice-service:
non-secure-port-enabled: false url: https://invoice-service-682610574114.europe-west1.run.app
instance-id: ${spring.application.name}:${random.uuid}
ip-address: ${K_REVISION:localhost}
leaseRenewalIntervalInSeconds: 30
leaseExpirationDurationInSeconds: 90
metadataMap:
instanceId: ${spring.application.name}:${random.uuid}
management: notification-service:
endpoints: url: https://notification-service-682610574114.europe-west1.run.app
web:
exposure:
include: health,info
endpoint:
health:
show-details: always
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment