Skip to content

Commit

Permalink
Adapt for ASA-E deployment (#69)
Browse files Browse the repository at this point in the history
* Adapt for ASA-E
  • Loading branch information
moarychan committed Nov 28, 2023
1 parent b4330bf commit 9696dae
Show file tree
Hide file tree
Showing 66 changed files with 19,039 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ generated/
setup-env-variables-azure.sh

# AZD
.azure
.azure
/spring-petclinic-frontend/npm-debug.log
/spring-petclinic-frontend/public/
/spring-petclinic-frontend/node_modules/
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@
<module>spring-petclinic-api-gateway</module>
</modules>
</profile>
<profile>
<!--
This profile file is used to configure and deploy applications to the Azure Spring Apps enterprise plan, only the following three applications are involved.
It's used for quickstart doc: https://learn.microsoft.com/azure/spring-apps/quickstart-deploy-microservice-apps
-->
<id>spring-apps-enterprise</id>
<modules>
<module>spring-petclinic-customers-service</module>
<module>spring-petclinic-vets-service</module>
<module>spring-petclinic-visits-service</module>
</modules>
</profile>
<profile>
<id>springboot</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -70,6 +71,7 @@ public WebClient.Builder loadBalancedWebClientBuilder() {
* @see <a href="https://github.com/spring-projects/spring-boot/issues/9785">#9785</a>
*/
@Bean
@Profile("!development")
RouterFunction<?> routerFunction() {
RouterFunction router = RouterFunctions.resources("/**", new ClassPathResource("static/"))
.andRoute(RequestPredicates.GET("/"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.api.application;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -26,6 +27,7 @@
*/
@Component
@RequiredArgsConstructor
@Profile("!development")
public class CustomersServiceClient {

private final WebClient.Builder webClientBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.api.application;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.samples.petclinic.api.dto.Visits;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -30,6 +31,7 @@
*/
@Component
@RequiredArgsConstructor
@Profile("!development")
public class VisitsServiceClient {

// Could be changed for testing purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.samples.petclinic.api.application.CustomersServiceClient;
import org.springframework.samples.petclinic.api.application.VisitsServiceClient;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
Expand All @@ -37,6 +38,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/gateway")
@Profile("!development")
public class ApiGatewayController {

private final CustomersServiceClient customersServiceClient;
Expand Down
30 changes: 30 additions & 0 deletions spring-petclinic-api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ spring:
filters:
- StripPrefix=2
---
spring:
config:
activate:
on-profile: development
cloud:
gateway:
routes:
- id: vets-service
uri: lb://vets-service
predicates:
- Path=/api/vet/**
filters:
- StripPrefix=2
- id: visits-service
uri: lb://visits-service
predicates:
- Path=/api/visit/**
filters:
- StripPrefix=2
- id: customers-service
uri: lb://customers-service
predicates:
- Path=/api/customer/**
filters:
- StripPrefix=2
- id: frontend
uri: http://localhost:3000
predicates:
- Path=/**
---
server:
port: 8080
spring:
Expand Down
1 change: 1 addition & 0 deletions spring-petclinic-frontend/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development
1 change: 1 addition & 0 deletions spring-petclinic-frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=production
1 change: 1 addition & 0 deletions spring-petclinic-frontend/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
47 changes: 47 additions & 0 deletions spring-petclinic-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Frontend for PetClinic project

This module is the frontend part of the PetClinic project, it provides the same features as the `spring-petclinic-api-gateway` module.
When deploying to Azure Spring Apps enterprise plan, you can use the managed component Spring Cloud Gateway on Azure Spring Apps, which is more efficient and cost-effective.

## Run locally

Please note that supporting services (Config and Discovery Server) must be started before any other application.

Enter the project root directory and open a terminal to start Config Server:

```shell
./mvnw spring-boot:run -pl spring-petclinic-config-server
```

Open a new terminal to start Discovery Server:

```shell
./mvnw spring-boot:run -pl spring-petclinic-discovery-server
```

For Customers, Vets, and Visits services, open new terminal in turn and execute the following commands:

```shell
./mvnw spring-boot:run -pl spring-petclinic-customers-service
./mvnw spring-boot:run -pl spring-petclinic-vets-service
./mvnw spring-boot:run -pl spring-petclinic-visits-service
```

For Gateway service, it's required to enable the Spring profile `deployment` to enable the static resource proxy, open a new terminal and execute the following command:

```shell
./mvnw spring-boot:run -Dspring-boot.run.profiles=default,development -pl spring-petclinic-api-gateway
```

Install [Node.js 16.20 LTS](https://nodejs.org/en/download/) if you don't have it already.

Enter the project `spring-petclinic-frontend` directory and open a new terminal to install dependencies and run the frontend:

```shell
npm install
npm run start
````

If everything goes well, you can access the PetClinic at given location:
* Gateway - http://localhost:8080
* Frontend - http://localhost:3000
Loading

0 comments on commit 9696dae

Please sign in to comment.