-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tanzu-java-web-app for TP for K8s (#520)
* Update tanzu-java-web-app for TP for K8s - also update the imported fragments to use DSL
- Loading branch information
Showing
22 changed files
with
187 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
engine { | ||
|
||
if (#includeBuildToolWrapper) { | ||
Include({"gradlew*", "gradle/**"}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+130 Bytes
(100%)
fragments/build-wrapper-gradle/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
fragments/build-wrapper-gradle/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
fragments/build-wrapper-maven/.mvn/wrapper/maven-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
engine { | ||
|
||
if (#includeBuildToolWrapper) { | ||
Include({"mvnw", "mvnw.cmd", ".mvn/**"}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
engine { | ||
applyTo("README.md") { | ||
UniquePath(strategy: FavorForeign) | ||
ReplaceText(regex: {pattern: "set BP_JVM_VERSION=.*", with: 'set BP_JVM_VERSION=' + #javaVersion}) | ||
} | ||
|
||
applyTo("pom.xml") { | ||
ReplaceText(regex: {pattern: "<java.version>.*<", with: '<java.version>' + #javaVersion + '<'}) | ||
} | ||
|
||
applyTo("build.gradle") { | ||
ReplaceText(regex: {pattern: "sourceCompatibility = .*", with: 'sourceCompatibility = ''' + #javaVersion + ''''}) | ||
} | ||
|
||
applyTo("build.gradle.kts") { | ||
ReplaceText(regex: {pattern: "(?<unmodified>JavaVersion\.VERSION_)(\d+)", with: '${unmodified}' + #javaVersion}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,143 @@ | ||
# tanzu-java-web-app | ||
|
||
This is a sample of a Java Spring app that works with Tilt and the Tanzu Application Platform. | ||
This is a sample of a Java Spring web app for the Tanzu Platform for Kubernetes. | ||
|
||
## Dependencies | ||
1. [kubectl CLI](https://kubernetes.io/docs/tasks/tools/) | ||
2. [Tilt version >= v0.23.2](https://docs.tilt.dev/install.html) | ||
3. Tanzu CLI and the apps plugin v0.2.0 which are provided as part of [Tanzu Application Platform](https://network.tanzu.vmware.com/products/tanzu-application-platform) | ||
4. A cluster with Tanzu Application Platform, and the "Default Supply Chain", plus its dependencies. This supply chains is part of [Tanzu Application Platform](https://network.tanzu.vmware.com/products/tanzu-application-platform). | ||
## Building and running the app locally | ||
|
||
## Application Live View | ||
The workload is set up by default to autoconfigure the actuators. This results in that the Spring Actuators are available at TCP port 8081 and will be used by Application Live View. | ||
Application Live View allows you see all health metrics in the TAP GUI. If you would like to have the Actuators available at TCP port 8080 you can set the | ||
annotation `apps.tanzu.vmware.com/auto-configure-actuators` to `false`. | ||
### Prerequisites | ||
In order to further develop this application the following tools needs to be setup: | ||
- Java Development Kit (https://bell-sw.com/libericajdk/) | ||
- Visual Studio Code or IntelliJ IDEA as Integrated Development Environment (IDE) | ||
|
||
## Building with local source | ||
### Build the app | ||
|
||
You can build using source from either a Git repository or from source on your local disk. | ||
The instructions below use the latter option, where you build using the source from your local disk. | ||
This is specified by adding a `--local-path` option providing the path for the source, and a `--source-image` option providing the OCI repository (e.g. `registry.io/user/tanzu-java-web-app-source`) to use for publishing the local source code. | ||
In order to compile the application code: | ||
|
||
You can set this as an environment variable before running any of the commands below using: | ||
```sh | ||
#IF(#buildTool == "gradle") | ||
./gradlew build | ||
#ENDIF | ||
#IF(#buildTool == "maven") | ||
./mvnw package | ||
#ENDIF | ||
``` | ||
|
||
### Run the app | ||
|
||
```sh | ||
#IF(#buildTool == "gradle") | ||
./gradlew bootRun | ||
#ENDIF | ||
#IF(#buildTool == "maven") | ||
./mvnw spring-boot:run | ||
#ENDIF | ||
``` | ||
|
||
### Accessing the running app | ||
|
||
You can use [curl](https://curl.se/) command: | ||
|
||
```sh | ||
curl localhost:8080 | ||
``` | ||
|
||
Or, you can use [HTTPie](https://httpie.io/): | ||
|
||
```sh | ||
http -b :8080 | ||
``` | ||
|
||
You should see the following text: | ||
|
||
``` | ||
Greetings from Spring Boot + Tanzu! | ||
``` | ||
|
||
## Configuring your Tanzu Platform build environment | ||
|
||
### Prerequisites | ||
|
||
1. Tanzu CLI and the apps plugin v0.2.0 which are provided as part of [Tanzu Platform](https://docs.vmware.com/en/VMware-Tanzu-Platform/index.html). Installation instructions can be found at [VMware Tanzu Platform Product Documentation - Before you begin](https://docs.vmware.com/en/VMware-Tanzu-Platform/SaaS/create-manage-apps-tanzu-platform-k8s/getting-started-deploy-app-to-space.html#before-you-begin-0). | ||
|
||
2. You have access to a space for your project, and you have used `tanzu login` to authenticate and configure your current Tanzu context, and you have set your project and space using `tanzu project use` and `tanzu space use` respectively. | ||
|
||
### Configure an image registry to use for building the app | ||
|
||
Before you can build your app, you need to specify the registry where the resulting image from the build can be stored. | ||
|
||
```sh | ||
tanzu build config --containerapp-registry REGISTRY | ||
``` | ||
|
||
> Where `REGISTRY` is your container image registry location. For example, `my-registry.io/my-corp-apps/{name}` or `docker.io/<your-docker-id>/{name}` if you use Docker Hub. Note that use of literal `{name}` is required, and it will be replaced with your apps name when you build. | ||
## Configuring your app environment | ||
|
||
Change to the root directory of your generated app. | ||
|
||
### Initialize the ContainerApp | ||
|
||
```sh | ||
tanzu app init | ||
``` | ||
|
||
### Configure the JDK version | ||
|
||
You need to specify the JDK version to be used for the app: | ||
|
||
```sh | ||
tanzu app config build non-secret-env set BP_JVM_VERSION=17 | ||
``` | ||
|
||
### Configure for native build with GraalVM | ||
|
||
If you would like the build to use GraalVM for compipling native image then use the following comands: | ||
|
||
```sh | ||
tanzu app config build non-secret-env set BP_NATIVE_IMAGE=true | ||
tanzu app config build non-secret-env set BP_MAVEN_ACTIVE_PROFILES=native | ||
``` | ||
|
||
### Configure HTTP Ingress Routing | ||
|
||
If you want to expose your application with a domain name and route traffic from the domain name to the deployed application, see [Adding HTTP Routing to an Application](https://docs.vmware.com/en/VMware-Tanzu-Platform/SaaS/create-manage-apps-tanzu-platform-k8s/how-to-ingress-to-app.html). | ||
|
||
### Building and deploying the app to Tanzu Platform for Kubernetes in one step | ||
|
||
Change to the root directory of your generated app. | ||
|
||
Run this command to build and deploy the app: | ||
|
||
```sh | ||
export SOURCE_IMAGE=registry.io/user/tanzu-java-web-app-source | ||
tanzu deploy | ||
``` | ||
|
||
## Deploying the sample for TAP | ||
### Using separate build and deploy commands | ||
|
||
Change to the root directory of your generated app. | ||
|
||
#### Building from local source | ||
|
||
You can build using source on your local disk. | ||
|
||
To build the app you can run this command: | ||
|
||
```sh | ||
tanzu build --output-dir ./prebuilt | ||
``` | ||
|
||
#### Deploying the app to Tanzu Platform for Kubernetes | ||
|
||
Start the app deployment by running: | ||
|
||
```sh | ||
tanzu apps workload create tanzu-java-web-app \ | ||
--file ./config/workload.yaml \ | ||
--local-path . \ | ||
--source-image "${SOURCE_IMAGE}" | ||
tanzu deploy --from-build ./prebuilt | ||
``` | ||
|
||
## Running the sample on TAP using Tilt for live update | ||
### Scale the number of instances | ||
|
||
You can use the IDE plugins for VSCode or IntelliJ IDEA to enable live update. You can also use the command line following these steps. | ||
Run this command to scale to 1 instance: | ||
|
||
1. Set the environment variable mentioned above specifying the repository to use for the source image. This is where the local source code will be written. As an example, use `export SOURCE_IMAGE=registry.io/user/tanzu-java-web-app-source`. | ||
2. Start `Tilt` by running `tilt up` | ||
> If you see an "Update error" message like the one below, then just follow the instructions and allow that context: | ||
``` | ||
Stop! tap-beta2 might be production. | ||
If you're sure you want to deploy there, add: | ||
allow_k8s_contexts('tap-beta2') | ||
to your Tiltfile. Otherwise, switch k8s contexts and restart Tilt. | ||
``` | ||
3. You can hit the spacebar to open the Tilt UI in a browser. | ||
```sh | ||
tanzu app scale tanzu-java-web-app --instances=1 | ||
``` |
Oops, something went wrong.