Tilt for local development
Introduction
This section will show you how to do local development using Tilt. Tilt eases local development by taking away the pain of time consuming Docker builds, watching files, and bringing environments up to date. The way Tilt works is based on a single Tiltfile present in your root project directory containing environment setup logic.
You will install the online boutique sample application on your local environment using Docker Desktop and Tilt.
The way you will use Tilt in this guide is based on configuration profiles. This approach has a major benefit - application logic is decoupled from configuration data. It means, you don't have to modify the base Tiltfile only if really required, or to add new functionality. Tilt automatically loads (if present) the configuration file (tilt_config.json
), and sets up the environment for you.
Based on your current requirements or needs, you just pick the appropriate tilt_config.json
file from the tilt-resources directory, and copy it alongside main Tiltfile.
Below is an example of such setup:
.
.
.
├── tilt-resources
│ ├── dev
│ │ └── tilt_config.json
│ └── local
│ └── tilt_config.json
├── Tiltfile
└── tilt_config.json
You need to copy only once the environment specific configuration file, and then run tilt up
from the root directory of your project:
- If you need a local environment setup -
cp tilt-resources/local/tilt_config.json <Tiltfile_directory>
. Then, runtilt up
, and see it in action. - If you need a remote development setup -
cp tilt-resources/dev/tilt_config.json <Tiltfile_directory>
. Then, runtilt up
, and see it in action.
Prerequisites
To complete this section you will need:
- Tilt already installed and working as explained in the Installing Required Tools -> Tilt section.
- Docker desktop already installed and running as explained in the Installing Required Tools -> Docker Desktop section.
- The
microservices-demo
GitHub repository already prepared as explained in the Preparing demo application GitHub repository section.
Local development with Tilt
-
Clone your
microservices-demo
repository if you haven't already (make sure to replace the<>
placeholders first): -
Change directory to
microservices-demo
folder: -
Switch your current Kubernetes config to
docker-desktop
:Note
This is required for local development as Tilt can be ran against a production Kubernetes cluster for example, and you can accidentally perform unwanted changes.
-
Within the current directory, copy the
local profile
configuration for Tilt:Note
Tilt configuration files will be excluded from git commits by
.gitignore
settings. Each developer customizes his profile locally as desired, and should not impact other team members. -
Bring the
microservices-demo
local environment up using Tilt:You should see the following output:
-
Press the
Space
bar to open Tilt's UI:Note
Please note that from the top left you can switch between
Table
andDetail
view.Detail
view offers a lot more information on what Tilt is doing such as logs from all Kubernetes resources. -
Open a web browser and point to localhost:9090. You should see the online boutique welcome page:
Live Updates with Tilt
Tilt has the ability to reload and rebuild resources at the right time. Every code change triggers Tilt to automatically rebuild local docker images, and roll out new versions of your application pods.
Follow steps below to watch Tilt doing live updates for your application:
-
Change directory to your local clone of the
microservices-demo
project directory (if not already). Then, open thesrc/frontend/templates/home.html
file using a text editor of your choice (preferably with HTML lint support). For example, you can use VS Code: -
Next, change one of the
h3
tags to something different, such as: -
Navigate to Tilt's detailed view using the web interface. You should see that the
frontend
resource is being rebuilt. -
Finally, open a web browser and point to localhost:9090. You should see the updated online boutique welcome page with your changes:
Info
Due to browser cache the changes might not appear immediately and for this reason you can
hard refresh
your browser to see the changes. On modern browsers this can be achieved by pressingCommand
+Shift
+R
on macOS, andCtrl
+Shift
+R
for Linux systems.
Next, you will learn how to perform remote development for the same set of microservices, using the Kubernetes environment created in the Set up Development DOKS section.