Build and deploy an application from source

This topic describes how to build and deploy an application from source.

Before you begin

Before you can deploy an app in a Space, you must:

  • Install Tanzu CLI v1.3.0 or later. See Installing the Tanzu CLI.

  • Install the Tanzu CLI app-developer plugin group:

    tanzu plugin install --group vmware-tanzu/app-developer
    
  • Log in via Tanzu CLI

    tanzu login
    
  • Install either Podman or Docker for Docker-compatible runtime for building your application

    Important

    If you use Podman, you must export the DOCKER_HOST environment variable. For example: export DOCKER_HOST=unix://$(podman machine inspect --format '{{.ConnectionInfo.PodmanSocket.Path}}')

  • Create a Space to use as your target deployment environment. See Create an application environment using Spaces.

Overview of steps

The following provides an overview of the steps to build and deploy an application.

  1. Initialize a ContainerApp
  2. (Optional) Configure HTTP Ingress Routing
  3. Configure image registry
  4. Deploy your application

Initialize a ContainerApp

Before you build your application, your must initialize a ContainerApp for it. The ContainerApp defines default build and runtime configuration for your application and is used as an input to tanzu build. For more information about ContainerApps, see What is a ContainerApp.

To initialize a ContainerApp:

  1. Navigate to the root of your source code:

    cd YOUR-REPO-LOCATION
    
  2. Initialize the ContainerApp by running and accepting suggested defaults (by pressing “Enter”):

    tanzu app init
    

Configure HTTP Ingress Routing

If 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.

Configure an image registry

  1. Configure the container image registry where you want generated images to be pushed. Run:

    tanzu build config --containerapp-registry REGISTRY
    

    Where REGISTRY is your container image registry location. For example, my-registry.io/my-corp-apps/{name} or my-registry.io/{contact.businessunit}/app-{name}. Note that use of literal {name} is required. Use the following templating in the registry URL to prevent image collisions:

    • {name}: build command will substitute the name of your ContainerApp.
    • {contact.FIELD}: build command will substitute the value of spec.contact.FIELD from your ContainerApp.
  2. Log into your container image registry if you have not already done so. For example:

    docker login my-registry.io
    

Deploy your application

You have two options for deploying your application:

Option 1: Deploy the app

To deploy your application in your Space:

  1. Set the project you want to use:

    tanzu project use
    
  2. Set the Space to use for your deployment by running:

    tanzu space use
    
  3. Build and deploy your application with a single command by running:

    tanzu deploy
    

When you run tanzu deploy, the following occurs:

  • Your application is built into a container image.
  • The container image is pushed to the image registry location earlier.
  • The application is deployed to the Space that you’ve set as your context.

Option 2: Build and deploy the app separately

Alternatively, you can build and deploy your application in two separate steps.

You might want to do this if, for example, you want to run pre-deployment analysis on the build output or want to build and deploy and application from existing CI workflows.

To build and deploy your application:

  1. Set the project you want to use:

    tanzu project use
    
  2. Set the Space to use for your deployment by running:

    tanzu space use
    
  3. Build your application by running:

    tanzu build --output-dir DIR-PATH
    

    Where DIR-PATH is the location where you want the build output.

  4. Deploy your application by running:

    tanzu deploy --from-build DIR-PATH
    

    Where DIR-PATH is the same as the location you used in the tanzu build command.

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