Get started with Tanzu Developer Tools for VS Code

This topic guides you through getting started with VMware Tanzu Developer Tools for Visual Studio Code (VS Code).

Prerequisite

Install VMware Tanzu Developer Tools for Visual Studio Code.

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.

Set up Tanzu Developer Tools

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

workload.yaml provides instructions to the Supply Chain Choreographer about how to build and manage a workload.

The extension requires only one workload.yaml file per project. workload.yaml must be a single-document YAML file, not a multidocument YAML file.

Before beginning to write your workload.yaml file, ensure that you know:

  • The name of your application. For example, my app.
  • The workload type of your application. For example, web.
  • The GitHub source code URL. For example, github.com/mycompany/myapp.
  • The Git branch of the source code that you intend to use. For example, main.
Code snippets
To create a workload.yaml file by using code snippets:
  1. (Optional) Create a directory named config in the root directory of your project. For example, my project/config.
  2. Create a file named workload.yaml in the new config directory. For example, my project/config/workload.yaml.
  3. Open the new workload.yaml file in VS Code, enter tanzu workload in the file to trigger the code snippets, and either press Enter or left-click the tanzu workload text in the drop-down menu.

    A new file called workload dot yaml with the words tanzu workload written in it and an action menu showing tanzu workload.

  4. Fill in the template by pressing the Tab key.

Manual
To create your workload.yaml file manually, follow this 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.
  • WORKLOAD-TYPE is the type of this workload. For example, web.
  • GIT-SOURCE-URL is your GitHub source code URL.
  • GIT-BRANCH-NAME is the Git branch of your source code.

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

Create the catalog-info.yaml file

catalog-info.yaml enables the workloads of this project to appear in Tanzu Developer Portal.

Before beginning to write your catalog-info.yaml file, ensure that you:

  • Know the name of your application. For example, my app.
  • Have a description of your application ready.
Code snippets
To create a catalog-info.yaml file by using the code snippets:
  1. (Optional) Create a directory named catalog in the root directory of your project. For example, my project/catalog.
  2. Create a file named catalog-info.yaml in the new config directory. For example, my project/catalog/catalog-info.yaml.
  3. Open the new catalog-info.yaml file in VS Code, enter tanzu catalog-info in the file to trigger the code snippets, and then either press Enter or left-click the tanzu catalog-info text in the drop-down menu.

    A new file called catalog-info dot yaml with the words tanzu catalog-info written in it and an action menu showing tanzu catalog-info.

  4. Fill in the template by pressing the Tab key.

Manual
To create your catalog-info.yaml file manually, follow this 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 the description of your application

Create the Tiltfile file

The Tiltfile file provides the Tilt configuration to enable your project to Live Update on your Kubernetes cluster that has Tanzu Application Platform. The Tanzu Developer Tools extension requires only one Tiltfile per project.

Before beginning to write your Tiltfile file, ensure that you know:

  • The name of your application. For example, my app.
  • Whether you want to compile the source image from a local directory other than the project directory or otherwise leave the local path value unchanged. For more information, see local path in the glossary.
  • The path to your workload.yaml file. For example, config/workload.yaml.
  • The name of your current Kubernetes context, if the targeting Kubernetes cluster enabled by Tanzu Application Platform is not running on your local machine.
Code Snippets
To create a Tiltfile file by using the code snippets:
  1. Create a file named Tiltfile with no file extension in the root directory of your project. For example, my project/Tiltfile.
  2. Open the new Tiltfile file in VS Code and enter tanzu tiltfile in the file to trigger the code snippets, and then either press Enter or left-click the tanzu tiltfile text in the drop-down menu.

    A new file called Tiltfile with the words tanzu tiltfile written in it and an action menu showing tanzu tiltfile.

  3. Fill in the template by pressing the Tab key.

  4. If the targeting Kubernetes cluster enabled by Tanzu Application Platform is not running on your local machine, add a new line to the end of the Tiltfile template and enter:

    allow_k8s_contexts('CONTEXT-NAME')
    

    Where CONTEXT-NAME is the name of your current Kubernetes context.

Manual
To create a Tiltfile file manually, follow this example:
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 workload.yaml. For example, config/workload.yaml.
  • CONTEXT-NAME is the name of your current Kubernetes context. If your Kubernetes cluster enabled by Tanzu Application Platform is running locally on your local machine, you can remove the entire allow_k8s_contexts line. For more information, see the Tilt documentation.

Create a .tanzuignore file

The .tanzuignore file specifies the file paths to exclude from the source code image. When working with local source code, you can exclude files from the source code to be uploaded within the image. Directories must not end with the system path separator (/ or \). See this example. in GitHub.

View an example project

Before you begin, you need a container registry for the sample application.

You can view a sample application that demonstrates the necessary configuration files. There are two ways to obtain the sample application:

Application Accelerator
If your company has configured Application Accelerator, you can obtain the sample application there if it was not removed. To do so:
  1. Open Application Accelerator.
  2. Search for Tanzu Java Web App in Application Accelerator.
  3. Add the required configuration information and generate the application.
  4. Unzip the file and open the project in a VS Code workspace.
Clone from GitHub
To clone the sample application from GitHub:
  1. Run git clone to clone the tanzu-java-web-app repository from GitHub.
  2. Change into the tanzu-java-web-app directory.
  3. Open the Tiltfile and replace your-registry.io/project with your container registry.

Next steps

Use Tanzu Developer Tools for VS Code.

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