This topic guides you through starting to iterate on your first application on Tanzu Application Platform (commonly known as TAP). You deployed the app in the previous how-to Deploy your first application.
In the previous Getting started how-to topic, Deploy your first application, you deployed your first application on Tanzu Application Platform. Now that you have developed a skeleton workload, you are ready to begin to iterate on your new application and test code changes on the cluster.
Tanzu Developer Tools for IntelliJ is VMware Tanzu’s official IDE extension for IntelliJ. It helps you develop and receive fast feedback on your workloads running on the Tanzu Application Platform.
The IntelliJ extension enables live updates of your application while running on the cluster and allows you to debug your application directly on the cluster.
For information about installing the prerequisites and the Tanzu Developer Tools for IntelliJ extension, see Install Tanzu Developer Tools for IntelliJ.
ImportantUse Tilt v0.30.12 or later for the sample application.
To prepare to iterate on your application, you must:
Tanzu Live Update uses Tilt. This requires a suitable Tiltfile
to exist at the root of your project. Both Gradle and Maven projects are supported, but each requires a Tiltfile
specific to that type of project.
The Tanzu Java Web App accelerator allows you to choose between Maven and Gradle and includes a Tiltfile
. If you used the accelerator, your project is already set up correctly.
To verify your project is set up correctly, review the following requirements depending on your chosen build system.
If you are using Maven, your Tiltfile
must be similar to the following:
SOURCE_IMAGE = os.getenv("SOURCE_IMAGE", default='your-registry.io/project/tanzu-java-web-app-source')
LOCAL_PATH = os.getenv("LOCAL_PATH", default='.')
NAMESPACE = os.getenv("NAMESPACE", default='default')
k8s_custom_deploy(
'tanzu-java-web-app',
apply_cmd="tanzu apps workload apply -f config/workload.yaml --update-strategy replace --debug --live-update" +
" --local-path " + LOCAL_PATH +
" --source-image " + SOURCE_IMAGE +
" --namespace " + NAMESPACE +
" --yes --output yaml",
delete_cmd="tanzu apps workload delete -f config/workload.yaml --namespace " + NAMESPACE + " --yes",
container_selector='workload',
deps=['pom.xml', './target/classes'],
live_update=[
sync('./target/classes', '/workspace/BOOT-INF/classes')
]
)
k8s_resource('tanzu-java-web-app', port_forwards=["8080:8080"],
extra_pod_selectors=[{'carto.run/workload-name': 'tanzu-java-web-app', 'app.kubernetes.io/component': 'run'}])
If you are using Gradle, review the following requirements:
The Tiltfile
looks like a Maven Tiltfile except for some key differences in the deps=
and live-update=
sections:
...
deps=['build.gradle.kts', './build/classes/java/main', './build/resources/main'],
live_update=[
sync('./build/classes/java/main', '/workspace/BOOT-INF/classes'),
sync('./build/resources/main', '/workspace/BOOT-INF/classes')
]
...
The project must be built as an exploded JAR. This is not the default behavior for a Gradle-based build. For a typical Spring Boot Gradle project, you must deactivate the jar
task in the build.gradle.kts
file as follows:
...
tasks.named<Jar>("jar") {
enabled = false
}
After verifying your project has the required Tiltfile
and Maven or Gradle build support, you are ready to set up your development environment.
Open the Tanzu Java Web App as a project within your IntelliJ IDE by selecting File > Open, then selecting the Tanzu Java Web App folder and clicking Open. If you don’t have the Tanzu Java Web App you can obtain it by following the instructions in Generate a new project using an Application Accelerator, or from the Application Accelerator Samples GitHub page.
Confirm that your current Kubernetes context contains a default namespace. The Tanzu Panel, found by clicking Tanzu Panel at the bottom-left of the IntelliJ window, uses the default namespace associated with your current Kubernetes context to populate the workloads from the cluster.
Open the Terminal by clicking View > Terminal.
Ensure that your current context has a default namespace by running:
kubectl config get-contexts
This command returns a list of all of your Kubernetes contexts with an asterisk (*
) in front of your current context. Verify that your current context has a namespace in the namespace column.
If your current context does not have a namespace in the namespace column, run:
kubectl config set-context --current --namespace=YOUR-DEVELOPER-NAMESPACE
Where YOUR-DEVELOPER-NAMESPACE
is the namespace value you want to assign to your current Kubernetes context.
You are now ready to iterate on your application.
Apply the workload to see your application running on the cluster:
In the Project tab in IntelliJ, right-click any file under the application name tanzu-java-web-app
and click Tanzu > Apply Workload.
In the dialog box enter your Source Image, Local Path, and optionally a Namespace.
Customize the installation of Local Source Proxy.
If you don’t have Local Source Proxy configured, you can use the source image parameter instead. The source image value tells the Tanzu Developer Tools for IntelliJ extension where to publish the container image with your non-compiled source code, and what to name that image. The image must be published to a container image registry where you have write access. For example, gcr.io/myteam/tanzu-java-web-app-source
.
NoteSee the documentation for the registry you’re using to find out which steps are necessary to authenticate and gain push access.
For example, if you use Docker, see the Docker documentation, or if you use Harbor, see the Harbor documentation.
In the Local Path text box, provide the path to the directory containing the Tanzu Java Web App. The current directory is the default.
The local path value tells the Tanzu Developer Tools for IntelliJ extension which directory on your local file system to bring into the source image. For example, dot (.
) uses the working directory, or you can specify a full file path.
(Optional) In the Namespace text box, provide the namespace to be associated with the workload on the cluster. If you followed the steps to Prepare your IDE to iterate on your application earlier, you do not need to enter a namespace because IntelliJ uses the namespace you associated with your context.
Click the OK button.
The apply workload
command runs, which opens a terminal and shows you the output of the command. The apply workload
command can take a few minutes to deploy your application onto the cluster.
You can also use the Tanzu Panel to monitor your application as it’s being deployed to the cluster. The Tanzu Panel shows information about the workloads in the namespace associated with your current Kubernetes context. On the left side, it shows the workloads in the namespace. In the center, it shows the details of the Kubernetes resources for the running workloads.
Live Update allows you to save changes to your code and see those changes reflected within seconds in the workload running on the cluster.
To enable Live Update for your application:
Create a Run Configuration.
Tanzu Live Update - tanzu-java-web-app
.Tiltfile
in the Tanzu Java Web App project directory.Tanzu Java Web App
directory, select the Tiltfile
, and click Open. The Tiltfile
facilitates Live Update using Tilt.In the Local Path text box, provide the path to the directory containing the Tanzu Java Web App.
The local path value tells the Tanzu Developer Tools for IntelliJ extension which directory on your local file system to bring into the source image.
For example, /Users/developer/Documents/tanzu-java-web-app
.
Customize the installation of Local Source Proxy.
If you don’t have Local Source Proxy configured, you can use the source image parameter instead. The source image value tells the Tanzu Developer Tools for IntelliJ extension where to publish the container image with your non-compiled source code, and what to name that image. The image must be published to a container image registry where you have write access. For example, gcr.io/myteam/tanzu-java-web-app-source
.
NoteSee the documentation for the registry you’re using to find out which steps are necessary to authenticate and gain push access.
For example, if you use Docker, see the Docker documentation, or if you use Harbor, see the Harbor documentation.
Begin Live Updating the application on the cluster by doing one of the following:
In the Project tab of IntelliJ, right-click the Tiltfile
file under the application name tanzu-java-web-app
and click Run 'Tanzu Live Update - tanzu-java-web-app'.
Alternatively, click the Edit Run/Debug configurations drop-down menu in the top-right corner, select Tanzu Live Update - tanzu-java-web-app, and then click the green play button to the right of the Edit Run/Debug configurations drop-down menu.
The Run tab opens and displays the output from Tanzu Application Platform and from Tilt indicating that the container is being built and deployed.
On the Tanzu Panel tab, the status of Live Update is reflected under the tanzu-java-web-app
workload entry. Live update can take up to three minutes while the workload deploys and the Knative service becomes available.
NoteDepending on the type of cluster you use, you might see an error similar to the following:
ERROR: Stop! cluster-name might be production. If you're sure you want to deploy there, add: allow_k8s_contexts('cluster-name') to your Tiltfile. Otherwise, switch k8scontexts and restart Tilt.
Follow the instructions and add the line,
allow_k8s_contexts('cluster-name')
to yourTiltfile
.
When the Live Update task in the Run tab is successful, it resolves to Live Update Started
. Use the hyperlink at the top of the Run output following the words Tilt started on to view your application in your browser.
In the IDE, make a change to the source code. For example, in HelloController.java
, edit the string returned to say Hello!
and save.
(Optional) Build your project by clicking Build > Build Project if you do not have Build project automatically activated under Preferences > Build, Execution, Deployment > Compiler.
The container is updated when the logs stop streaming. Navigate to your browser and refresh the page.
View the changes to your workload running on the cluster.
Either continue making changes, or stop the Live Update process when finished. To stop Live Update navigate to the Run tab at the bottom left of the IntelliJ window and click the red stop icon on the left side of the screen.
Debug the cluster either on the application or in your local environment.
To debug the cluster:
Set a breakpoint in your code. For example, in HelloController.java
, set a breakpoint on the line returning text.
Create a Run Configuration.
Tanzu Debug Workload - tanzu-java-web-app
.workload.yaml
file in the Tanzu Java Web App project directory located at Config > workload.yaml.Select the folder icon on the right-side of the text box, navigate to the Tanzu Java Web App directory, select the workload.yaml
file and click the Open button. The workload.yaml
provides configuration instructions about your application to the Tanzu Application Platform.
In the Local Path text box, provide the path to the directory containing the Tanzu Java Web App.
The local path value tells the Tanzu Developer Tools for IntelliJ extension which directory on your local file system to bring into the source image. For example, /Users/developer/Documents/tanzu-java-web-app
.
Customize the installation of Local Source Proxy.
If you don’t have Local Source Proxy configured, you can use the source image parameter instead. The source image value tells the Tanzu Developer Tools for IntelliJ extension where to publish the container image with your non-compiled source code, and what to name that image. The image must be published to a container image registry where you have write access. For example, gcr.io/myteam/tanzu-java-web-app-source
.
NoteSee the documentation for the registry you’re using to find out which steps are necessary to authenticate and gain push access.
For example, if you use Docker, see the Docker documentation, or if you use Harbor, see the Harbor documentation.
(Optional) In the Namespace text box, provide the namespace to be associated with the workload on the cluster. If you followed the steps to Prepare your IDE to iterate on your application, you do not need to enter a namespace because IntelliJ uses the namespace you associated with your context.
Click Apply, and then click OK.
Obtain the URL for your workload:
In the center panel of the Tanzu Panel go to Workload/tanzu-java-web-app > Running Application > Service/tanzu-java-web-app.
Right-click the Service/tanzu-java-web-app
entry and select Describe.
In the resulting output, copy the value after Status > URL: that begins with https://tanzu-java-web-app...
. Make sure you copy the value from Status > URL: and not the value under Status > Address > URL.
Open your web browser and paste the URL you copied to access your workload.
In the Project tab of IntelliJ, right-click the workload.yaml
file under the application name tanzu-java-web-app
and select Run 'Tanzu Debug Workload - tanzu-java-web-app' to begin debugging the application on the cluster.
The Debug tab opens and displays a message that it has connected.
In your web browser, reload your workload. IntelliJ opens to show your breakpoint.
You can now use the resume program action, or stop debugging, in the Debug tab.
You can use the delete action to remove your application from the cluster as follows:
In the Project tab, right-click any file under the application name tanzu-java-web-app
and select Tanzu > Delete Workload.
Alternatively, right-click tanzu-java-web-app
in the TANZU WORKLOADS panel and select Delete Workload.
In the confirmation dialog box that appears, click OK to delete the application from the cluster.