This topic guides you through getting started with VMware Tanzu Developer Tools for Visual Studio Code (VS Code).
Install VMware Tanzu Developer Tools for Visual Studio Code.
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 login $REGISTRY_HOSTNAME -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
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.
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:
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:
my app
.web
.github.com/mycompany/myapp
.main
.workload.yaml
file by using code snippets:
config
in the root directory of your project. For example, my project/config
.workload.yaml
in the new config directory. For example, my project/config/workload.yaml
.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.
Fill in the template by pressing the Tab key.
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.
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:
my app
.catalog-info.yaml
file by using the code snippets:
catalog
in the root directory of your project. For example, my project/catalog
.catalog-info.yaml
in the new config directory. For example, my project/catalog/catalog-info.yaml
.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.
Fill in the template by pressing the Tab key.
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 applicationAPP-DESCRIPTION
is the description of your applicationThe 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:
my app
.local path
value unchanged. For more information, see local path in the glossary.workload.yaml
file. For example, config/workload.yaml
.Tiltfile
with no file extension in the root directory of your project. For example, my-project/Tiltfile
.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.
Fill in the template by pressing the Tab key.
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.
# 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 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.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.
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:
Tanzu Java Web App
in Application Accelerator.git clone
to clone the tanzu-java-web-app repository from GitHub.tanzu-java-web-app
directory.your-registry.io/project
with your container registry.