From 1dee681c23ea0f931fedf799031da9c0f3ac73eb Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 07:17:00 +0000 Subject: [PATCH 1/9] feat : create native image --- .github/workflows/api-gateway.yml | 5 ++--- .../com/example/api/gateway/TestAPIGatewayApplication.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/api-gateway.yml b/.github/workflows/api-gateway.yml index 9961ef94..3a859f0f 100644 --- a/.github/workflows/api-gateway.yml +++ b/.github/workflows/api-gateway.yml @@ -44,9 +44,8 @@ jobs: - name: Build and analyze run: ./mvnw clean verify - - if: ${{ github.ref == 'refs/heads/main' }} - name: Build Image and push to docker + - name: Build Image and push to docker env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any DOCKER_PASSCODE: ${{secrets.DOCKER_PASSCODE}} - run: ./mvnw spring-boot:build-image -DskipTests -DCI_DOCKER_PASSWORD=${DOCKER_PASSCODE} -DCI_DOCKER_USERNAME=dockertmt -Dspring-boot.build-image.publish=true + run: ./mvnw -Pnative spring-boot:build-image -DskipTests -DCI_DOCKER_PASSWORD=${DOCKER_PASSCODE} -DCI_DOCKER_USERNAME=dockertmt -Dspring-boot.build-image.publish=true diff --git a/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java b/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java index 1e53bde6..d0b040b5 100644 --- a/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java +++ b/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java @@ -27,7 +27,7 @@ GenericContainer zipkinContainer() { @Bean @ServiceConnection(name = "redis") GenericContainer redisContainer() { - return new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.3-alpine")) + return new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.5-alpine")) .withExposedPorts(6379) .withReuse(true); } From 3059991d18cb3fcf7d2a14589d3fc158f6c56206 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 07:30:18 +0000 Subject: [PATCH 2/9] remove public where possible --- .../com/example/api/gateway/bootstrap/DataInitializer.java | 2 +- .../example/api/gateway/config/ApiGatewayConfiguration.java | 4 ++-- .../api/gateway/config/CircuitBreakerConfiguration.java | 2 +- .../java/com/example/api/gateway/config/LoggingFilter.java | 2 +- .../example/api/gateway/config/RateLimiterConfiguration.java | 2 +- .../java/com/example/api/gateway/config/SwaggerConfig.java | 2 +- .../example/api/gateway/config/WebClientConfiguration.java | 2 +- .../java/com/example/api/gateway/config/WebFluxConfig.java | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api-gateway/src/main/java/com/example/api/gateway/bootstrap/DataInitializer.java b/api-gateway/src/main/java/com/example/api/gateway/bootstrap/DataInitializer.java index 036dc895..410b3cb5 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/bootstrap/DataInitializer.java +++ b/api-gateway/src/main/java/com/example/api/gateway/bootstrap/DataInitializer.java @@ -13,7 +13,7 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli. import org.springframework.stereotype.Component; @Component -public class DataInitializer { +class DataInitializer { private static final Logger log = LoggerFactory.getLogger(DataInitializer.class); diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/ApiGatewayConfiguration.java b/api-gateway/src/main/java/com/example/api/gateway/config/ApiGatewayConfiguration.java index ce8cbb7c..20aa7d10 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/ApiGatewayConfiguration.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/ApiGatewayConfiguration.java @@ -11,8 +11,8 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli. import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -@Configuration -public class ApiGatewayConfiguration { +@Configuration(proxyBeanMethods = false) +class ApiGatewayConfiguration { @Bean RouteLocator gatewayRouter(RouteLocatorBuilder builder) { diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/CircuitBreakerConfiguration.java b/api-gateway/src/main/java/com/example/api/gateway/config/CircuitBreakerConfiguration.java index db68b898..fd15018d 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/CircuitBreakerConfiguration.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/CircuitBreakerConfiguration.java @@ -18,7 +18,7 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli. import org.springframework.security.crypto.password.PasswordEncoder; @Configuration(proxyBeanMethods = false) -public class CircuitBreakerConfiguration { +class CircuitBreakerConfiguration { @Bean PasswordEncoder passwordEncoder() { diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/LoggingFilter.java b/api-gateway/src/main/java/com/example/api/gateway/config/LoggingFilter.java index 99d1fea7..b7b7f413 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/LoggingFilter.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/LoggingFilter.java @@ -15,7 +15,7 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli. import reactor.core.publisher.Mono; @Component -public class LoggingFilter implements GlobalFilter { +class LoggingFilter implements GlobalFilter { private static final Logger log = LoggerFactory.getLogger(LoggingFilter.class); diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/RateLimiterConfiguration.java b/api-gateway/src/main/java/com/example/api/gateway/config/RateLimiterConfiguration.java index b885b2e8..21a25a4b 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/RateLimiterConfiguration.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/RateLimiterConfiguration.java @@ -12,7 +12,7 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. import reactor.core.publisher.Mono; @Configuration(proxyBeanMethods = false) -public class RateLimiterConfiguration { +class RateLimiterConfiguration { @Bean KeyResolver userKeyResolver() { diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/SwaggerConfig.java b/api-gateway/src/main/java/com/example/api/gateway/config/SwaggerConfig.java index 3e33fde0..8a4c56bc 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/SwaggerConfig.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/SwaggerConfig.java @@ -41,7 +41,7 @@ Licensed under MIT License Copyright (c) 2022-2023 Raja Kolli. security = @SecurityRequirement(name = "Authorization")) @SecurityScheme(type = SecuritySchemeType.HTTP, scheme = "basic", name = "Authorization") @AutoConfigureBefore(MultipleOpenApiSupportConfiguration.class) -public class SwaggerConfig { +class SwaggerConfig { @Bean @Lazy(value = false) diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/WebClientConfiguration.java b/api-gateway/src/main/java/com/example/api/gateway/config/WebClientConfiguration.java index c44d2ac4..85fcc275 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/WebClientConfiguration.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/WebClientConfiguration.java @@ -12,7 +12,7 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. import org.springframework.web.reactive.function.client.WebClient; @Configuration(proxyBeanMethods = false) -public class WebClientConfiguration { +class WebClientConfiguration { @Bean @LoadBalanced diff --git a/api-gateway/src/main/java/com/example/api/gateway/config/WebFluxConfig.java b/api-gateway/src/main/java/com/example/api/gateway/config/WebFluxConfig.java index 66a46254..73922a16 100644 --- a/api-gateway/src/main/java/com/example/api/gateway/config/WebFluxConfig.java +++ b/api-gateway/src/main/java/com/example/api/gateway/config/WebFluxConfig.java @@ -11,7 +11,7 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. import org.springframework.web.reactive.config.WebFluxConfigurer; @Configuration(proxyBeanMethods = false) -public class WebFluxConfig implements WebFluxConfigurer { +class WebFluxConfig implements WebFluxConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { From ddd8635db9ab650394e87cf6de6725dc438d0453 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 07:53:45 +0000 Subject: [PATCH 3/9] disable refreshscope --- api-gateway/src/test/resources/application-test.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 api-gateway/src/test/resources/application-test.properties diff --git a/api-gateway/src/test/resources/application-test.properties b/api-gateway/src/test/resources/application-test.properties new file mode 100644 index 00000000..a3cdf15d --- /dev/null +++ b/api-gateway/src/test/resources/application-test.properties @@ -0,0 +1 @@ +spring.cloud.refresh.enabled=false \ No newline at end of file From 3a1293b308145e6352fa25a6e1ff4acb8b0fa90e Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 07:56:22 +0000 Subject: [PATCH 4/9] disable refresh at application level --- api-gateway/src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/api-gateway/src/main/resources/application.yml b/api-gateway/src/main/resources/application.yml index b376374d..4da0b6de 100644 --- a/api-gateway/src/main/resources/application.yml +++ b/api-gateway/src/main/resources/application.yml @@ -17,6 +17,7 @@ spring: application: name: api-gateway cloud: + refresh.enabled: false gateway: discovery: locator: From ff56d4c8afdac2cd1d39cdb61dd534bdac85e7e4 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 14:04:13 +0530 Subject: [PATCH 5/9] bring config-server and service registry up for aot While building a project that contains Spring Cloud Config Client, you must make sure that the configuration data source that it connects to (such as, Spring Cloud Config Server, Consul, Zookeeper, Vault, and others) is available. For example, if you retrieve configuration data from Spring Cloud Config Server, make sure you have its instance running and available at the port indicated in the Config Client setup. This is necessary because the application context is being optimized at build time and requires the target environment to be resolved. --- .github/workflows/api-gateway.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/api-gateway.yml b/.github/workflows/api-gateway.yml index 3a859f0f..46335e1e 100644 --- a/.github/workflows/api-gateway.yml +++ b/.github/workflows/api-gateway.yml @@ -44,6 +44,13 @@ jobs: - name: Build and analyze run: ./mvnw clean verify + - name: Start up softwares via Docker Compose + run: | + cd deployment + docker compose up config-server naming-server -d + sleep 10 + docker ps -a + - name: Build Image and push to docker env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any From dea92769880cb72006f5d3fa063c51aa0a9cced1 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 14:07:32 +0530 Subject: [PATCH 6/9] Update api-gateway.yml --- .github/workflows/api-gateway.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/api-gateway.yml b/.github/workflows/api-gateway.yml index 46335e1e..244835ab 100644 --- a/.github/workflows/api-gateway.yml +++ b/.github/workflows/api-gateway.yml @@ -46,7 +46,7 @@ jobs: - name: Start up softwares via Docker Compose run: | - cd deployment + cd ..\deployment docker compose up config-server naming-server -d sleep 10 docker ps -a From 27e003f0e97422ed54f07423e1168fca63024fdb Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 14:19:08 +0530 Subject: [PATCH 7/9] corrected path --- .github/workflows/api-gateway.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/api-gateway.yml b/.github/workflows/api-gateway.yml index 244835ab..ce2ae1ab 100644 --- a/.github/workflows/api-gateway.yml +++ b/.github/workflows/api-gateway.yml @@ -46,7 +46,7 @@ jobs: - name: Start up softwares via Docker Compose run: | - cd ..\deployment + cd ../deployment docker compose up config-server naming-server -d sleep 10 docker ps -a From 012d5c999d9065b5b67c71892753bd54ae1d249f Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 14 Jul 2024 14:27:28 +0530 Subject: [PATCH 8/9] provide authentication details for connecting --- api-gateway/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-gateway/src/main/resources/application.yml b/api-gateway/src/main/resources/application.yml index 4da0b6de..b7342a9b 100644 --- a/api-gateway/src/main/resources/application.yml +++ b/api-gateway/src/main/resources/application.yml @@ -67,7 +67,7 @@ spring: - Path=/payment-service/** uri: lb://payment-service config: - import: "optional:configserver:${CONFIG_SERVER:http://localhost:8888}/" + import: "optional:configserver:${CONFIG_SERVER:http://docker-dev:docker-pass@localhost:8888}/" mustache: check-template-location: false webflux: From 56de7e37b8a9abd547b1629c65f350d748ae55c9 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 15 Nov 2024 16:20:35 +0000 Subject: [PATCH 9/9] fix : merge issue --- .../com/example/api/gateway/TestAPIGatewayApplication.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java b/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java index 149d479d..56055371 100644 --- a/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java +++ b/api-gateway/src/test/java/com/example/api/gateway/TestAPIGatewayApplication.java @@ -27,9 +27,8 @@ GenericContainer zipkinContainer() { @Bean @ServiceConnection(name = "redis") - GenericContainer redisContainer() { - return new GenericContainer<>(DockerImageName.parse("redis").withTag("7.4.0-alpine")) - .withExposedPorts(6379) + RedisContainer redisContainer() { + return new RedisContainer(DockerImageName.parse("redis").withTag("7.4.0-alpine")) .withReuse(true); }