TDENG-546: documented how I deployed spring-petclinic to Azure App Service

This commit is contained in:
shanewidanagama 2023-01-09 10:44:07 -05:00
parent c7d1095408
commit 347fb9569e
2 changed files with 80 additions and 39 deletions

34
deploy-az-app-service.ps1 Normal file
View file

@ -0,0 +1,34 @@
<# Description: The series of commands I used in the Azure Cloud Shell to deploy Azure App Service for
spring-petclinic. For reference to recreate a resource group and deploy spring-petclinic in the future if
the existing resource group gets removed. You can't execute this ps1 file due to multiple user inputs needed
during the Azure Maven plugin config step and JDK 17 installation step.
Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-linux-development-environment-maven
#>
git clone https://github.com/kevdev424/spring-petclinic.git
cd spring-petclinic
<#
Azure Maven plugin config step:
When prompted with Subscription option, select the proper Subscription by entering the number printed at the line start.
When prompted with Web App option, select the default option, <create>, by pressing enter.
When prompted with OS option, select Linux by pressing enter.
When prompted with javaVersion option, select Java 17.
When prompted with Pricing Tier option, select B2 for Java dev/test workload (which is what I chose)
or P1v2 for production workload.
Finally, press enter on the last prompt to confirm your selections.
#>
mvn com.microsoft.azure:azure-webapp-maven-plugin:2.5.0:config
# Cloud shell uses Java 11 but Java 17 is needed to build and deploy spring-petclinic
# Downlaod and unzip JDK 17 and set JAVA_HOME to the unzipped directory.
cd ~
wget https://aka.ms/download-jdk/microsoft-jdk-17.0.5-linux-x64.tar.gz
tar zxvf microsoft-jdk-17.0.5-linux-x64.tar.gz
export JAVA_HOME=/home/<current user>/jdk-17.0.5+8
# Deploy the app to azure
cd spring-petclinic
mvn package azure-webapp:deploy

View file

@ -3,11 +3,12 @@
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic)
## Understanding the Spring Petclinic application with a few diagrams
<a href="https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application">See the presentation here</a>
## Running petclinic locally
Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). You can build a jar file and run it from the command line (it should work just as well with Java 11 or newer):
Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). You can build a jar file and run it from the command line (it should work just as well with Java 11 or newer):
```
git clone https://github.com/spring-projects/spring-petclinic.git
@ -30,6 +31,12 @@ Or you can run it from Maven directly using the Spring Boot Maven plugin. If you
> NOTE: If you prefer to use Gradle, you can build the app using `./gradlew build` and look for the jar file in `build/libs`.
## Deploying Petclinic
See deploy-az-app-service.ps1 for instructions on how to create a resource group and deploy spring-petclinic
to an Azure App Service.
A continous deployment pipeline has been implemented in .github/workflows/
## Building a Container
There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
@ -39,15 +46,15 @@ There is no `Dockerfile` in this project. You can build a container image (if yo
```
## In case you find a bug/suggested improvement for Spring Petclinic
Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
## Database configuration
In its default configuration, Petclinic uses an in-memory database (H2) which
gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console`
and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url.
A similar setup is provided for MySQL and PostgreSQL in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL.
You could start MySQL or PostgreSQL locally with whatever installer works for your OS, or with docker:
@ -72,48 +79,50 @@ There is a `petclinic.css` in `src/main/resources/static/resources/css`. It was
## Working with Petclinic in your IDE
### Prerequisites
The following items should be installed in your system:
* Java 11 or newer (full JDK not a JRE).
* git command line tool (https://help.github.com/articles/set-up-git)
* Your preferred IDE
* Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
not there, just follow the install process here: https://www.eclipse.org/m2e/
* [Spring Tools Suite](https://spring.io/tools) (STS)
* IntelliJ IDEA
* [VS Code](https://code.visualstudio.com)
- Java 11 or newer (full JDK not a JRE).
- git command line tool (https://help.github.com/articles/set-up-git)
- Your preferred IDE
- Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
not there, just follow the install process here: https://www.eclipse.org/m2e/
- [Spring Tools Suite](https://spring.io/tools) (STS)
- IntelliJ IDEA
- [VS Code](https://code.visualstudio.com)
### Steps:
1) On the command line
```
git clone https://github.com/spring-projects/spring-petclinic.git
```
2) Inside Eclipse or STS
```
File -> Import -> Maven -> Existing Maven project
```
1. On the command line
```
git clone https://github.com/spring-projects/spring-petclinic.git
```
2. Inside Eclipse or STS
Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`.
```
File -> Import -> Maven -> Existing Maven project
```
3) Inside IntelliJ IDEA
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`.
CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
3. Inside IntelliJ IDEA
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
4) Navigate to Petclinic
A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
Visit [http://localhost:8080](http://localhost:8080) in your browser.
4. Navigate to Petclinic
Visit [http://localhost:8080](http://localhost:8080) in your browser.
## Looking for something in particular?
|Spring Boot Configuration | Class or Java property files |
|--------------------------|---|
|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
| Spring Boot Configuration | Class or Java property files |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
| Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
| Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
## Interesting Spring Petclinic branches and forks
@ -123,18 +132,16 @@ GitHub org is the "canonical" implementation, currently based on Spring Boot and
[spring-petclinic](https://github.com/spring-petclinic). If you have a special interest in a different technology stack
that could be used to implement the Pet Clinic then please join the community there.
## Interaction with other open source projects
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
Here is a list of them:
| Name | Issue |
|------|-------|
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
| Name | Issue |
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility | [HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
# Contributing
@ -148,7 +155,7 @@ The Spring PetClinic sample application is released under version 2.0 of the [Ap
[spring-petclinic]: https://github.com/spring-projects/spring-petclinic
[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic
[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs
[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs
[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig
[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular
[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices