Get Started with Tanzu Developer Tools for IntelliJ

This topic guides you through getting started with Tanzu Developer Tools for IntelliJ.

Prerequisite

Install Tanzu Developer Tools for IntelliJ.

Configure Local Source Proxy or use a source image registry

Configure Local Source Proxy if you’re able to do so. For more information, see the Local Source Proxy documentation.

If you cannot use Local Source Proxy, use a source image registry. Before deploying a workload, you must authenticate with an image registry to store your source code. You can use the Docker CLI to authenticate or you can set environment variables that the Tanzu CLI can use to authenticate.

Docker CLI
To authenticate by using the Docker CLI, run:
docker login $REGISTRY_HOSTNAME -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
Tanzu CLI
To authenticate by using the Tanzu CLI, export environment variables by running:
export TANZU_APPS_REGISTRY_CA_CERT=PATH-TO-CA-CERT.nip.io.crt
export TANZU_APPS_REGISTRY_PASSWORD=USERNAME
export TANZU_APPS_REGISTRY_USERNAME=PASSWORD

CA_CERT is only needed for a custom or private registry.

For more information, see Workload creation fails due to authentication failure in Docker Registry.

Run Tanzu Developer Tools for IntelliJ

Run IntelliJ from a CLI, instead of through your operating system GUI, to avoid restricting the set of environment variables the app receives. This is especially relevant for macOS.

Limited environment variables can cause problems with cluster authentication for Tanzu Developer Tools for IntelliJ. For example, a common situation is that a sanitized PATH does not provide access to the gke-cloud-auth-plugin installed on your system. This makes Tanzu Developer Tools for IntelliJ unable to authenticate and access your GKE cluster.

This situation is complex and different things can go wrong depending on:

  • Precisely how you installed various cloud-related CLI tools
  • How you set environment variables
  • Your OS version
  • Which cloud provider and authentication method you are using

All of these problems are most easily avoided by running IntelliJ from a CLI. Run IntelliJ from a CLI in macOS by running:

open /Applications/IntelliJ\ IDEA.app

Set up Tanzu Developer Tools for IntelliJ

The extension makes use of the following files within your project:

  • workload.yaml
  • catalog-info.yaml
  • Tiltfile
  • .tanzuignore

You can create these files by using the instructions in this topic, or use the files in the View an example project section.

There are two ways to create these files:

  • Using the code snippets that Tanzu Developer Tools provide, which create templates in empty files that you then fill in with the required information.
  • Writing the files manually.

Create the workload.yaml file

You must include a file named workload.yaml in your project. For example, my-project/config/workload.yaml.

workload.yaml provides instructions to Supply Chain Choreographer about how to build and manage a workload. For more information, see Supply Chain Choreographer for Tanzu.

The Tanzu Developer Tools for IntelliJ extension requires only one workload.yaml file per project. workload.yaml must be a single-document YAML file, not a multi-document YAML file.

To create a workload.yaml file by using code snippets:

  1. Right-click the IntelliJ project explorer and then click New.
  2. Select the Tanzu workload.
  3. Add the filename workload.
  4. Fill in the template.

See the following workload.yaml example:

apiVersion: carto.run/v1alpa1
kind: Workload
metadata:
 name: APP-NAME
 labels:
   apps.tanzu.vmware.com/workload-type: WORKLOAD-TYPE
   app.kubernetes.io/part-of: APP-NAME
spec:
 source:
   git:
     url: GIT-SOURCE-URL
     ref:
       branch: GIT-BRANCH-NAME

Where:

  • APP-NAME is the name of your application. For example, my app.
  • WORKLOAD-TYPE is the type of workload for your app. For example, web. For more information, see Workload types.
  • GIT-SOURCE-URL is the Git source code URL for your app. For example, github.com/mycompany/myapp.
  • GIT-BRANCH-NAME is the branch of the Git source code you want to use. For example, main.

Alternatively you can use the Tanzu CLI to create a workload.yaml file. For more information, see Create or update a workload.

Create the catalog-info.yaml file

You must include a file named catalog-info.yaml in your project. For example, my-project/catalog/catalog-info.yaml.

catalog-info.yaml enables the workloads created with Tanzu Developer Tools for IntelliJ to be visible in Tanzu Developer Portal. For more information, see Overview of Tanzu Developer Portal.

To create a catalog-info.yaml file by using the code snippets:

  1. Right-click the IntelliJ project explorer and then click New.
  2. Select the Tanzu Catalog.
  3. Add the filename catalog-info.
  4. Fill in the template.

See the following workload.yaml example:

apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
 name: APP-NAME
 description: APP-DESCRIPTION
 tags:
   - tanzu
 annotations:
   'backstage.io/kubernetes-label-selector': 'app.kubernetes.io/part-of=APP-NAME'
spec:
 type: service
 lifecycle: experimental
 owner: default-team

Where:

  • APP-NAME is the name of your application.
  • APP-DESCRIPTION is a description of your application.

Create the Tiltfile file

In your project you must include a file named Tiltfile with no extension (no filetype), such as my-project/Tiltfile.

The Tiltfile provides the configuration for Tilt to enable your project to Live Update on the Tanzu Application Platform-enabled Kubernetes cluster. For more information, see the Tilt documentation.

The Tanzu Developer Tools for IntelliJ extension requires only one Tiltfile per project.

The following is an example Tiltfile:

# For multi-module projects, set the LOCAL_PATH to the project root.
# For example, if your Tiltfile's path is .../my-project/module1/Tiltfile, then set LOCAL_PATH = ".."
LOCAL_PATH = os.getenv("LOCAL_PATH", default='.')
NAMESPACE = os.getenv("NAMESPACE", default='default')

k8s_custom_deploy(
   'APP-NAME',
   apply_cmd="tanzu apps workload apply -f PATH-TO-WORKLOAD-YAMl --live-update" +
       " --local-path " + LOCAL_PATH +
       " --namespace " + NAMESPACE +
       " --yes >/dev/null" +
       " && kubectl get workload APP-NAME --namespace " + NAMESPACE + " -o yaml",
   delete_cmd="tanzu apps workload delete -f PATH-TO-WORKLOAD-YAML --namespace " + NAMESPACE + " --yes" ,
   deps=['pom.xml', './target/classes'],
   container_selector='workload',
   live_update=[
       sync('./target/classes', '/workspace/BOOT-INF/classes')
   ]
)

k8s_resource('APP-NAME', port_forwards=["8080:8080"],
   extra_pod_selectors=[{'carto.run/workload-name': 'APP-NAME', 'app.kubernetes.io/component': 'run'}])
allow_k8s_contexts('CONTEXT-NAME')

Where:

  • APP-NAME is the name of your application.
  • PATH-TO-WORKLOAD-YAML is the local file system path to your workload.yaml file. For example, config/workload.yaml.
  • CONTEXT-NAME is the name of your current Kubernetes context. If your Tanzu Application Platform-enabled Kubernetes cluster is running on your local machine, you can remove the entire allow_k8s_contexts line. For more information about this line, see the Tilt documentation.

If you want to compile the source image from a local directory other than the project directory, change the value of local path. For more information, see local path in the glossary.

Create the .tanzuignore file

In your project, you can include a file named .tanzuignore with no file extension. For example, my-project/.tanzuignore.

When working with local source code, .tanzuignore excludes files from the source code that are uploaded within the image. It has syntax similar to the .gitignore file.

For an example, see the .tanzuignore file in GitHub that is used for the sample Tanzu Java web app. You can use the file as it is or edit it for your needs.

View an example project

Before you begin, you need a container image registry to use the sample application. There are two ways to view a sample application that demonstrates the necessary configuration files.

Use Application Accelerator
If your company has configured Application Accelerator, you can obtain the sample application there if it was not removed. To view the example using Application Accelerator:
  1. Open Application Accelerator. The Application Accelerator location varies based on where your company placed it. Contact the appropriate team to learn its location.
  2. Search for Tanzu Java Web App in the Application Accelerator.
  3. Add the required configuration information and generate the application.
  4. Unzip the application and open the directory in IntelliJ.
Clone from GitHub
To clone the example from GitHub:
  1. Use git clone to clone the application-accelerator-samples repository from GitHub.
  2. Go to the tanzu-java-web-app directory.
  3. Open the Tiltfile and replace your-registry.io/project with your registry.

Next steps

Use Tanzu Developer Tools for IntelliJ.

check-circle-line exclamation-circle-line close-line
Scroll to top icon