This repo is used as an example of how Tilt can be used to manage tasks within a microservice monorepo. This is roughly styled to be similar to how we at SOON_ use Tilt.
This is the companion repo to our Tilt At SOON_ blog post.
There are two microservices (if you can even call them that):
image-service/- Provides/totallyRandomImagewhich gives you a "totally random" image.name-service/- Provides/namewhich gives you a random name from a list of names, as well as allows you to add names to the list.
Beyond that, there's a docker-compose.yaml file to provide a datastore-emulator container, as well as a UI for it.
Finally there is of course the Tiltfile which sets up the ever so wonderful Tilt for us.
Currently this example repo hasn't been made compatible with Windows (just use WSL), but should work on Linux and Mac.
Please install the following:
Then simply run tilt up && tilt down within your terminal. You can press Space within your terminal to open the Tilt UI in your browser.
Tilt is configured to do the following things:
-
Execute the
docker-compose.yamlfile. You can see each container individually in the "Unlabeled" section of the Tilt UI.- If you examine the
datastore-uiresource within Tilt, you'll see Tilt automatically displays a link above the log window so you don't need to keep the README up to date with the link - devs can discover it naturally in Tilt!
- If you examine the
-
Provides a generic way to define Go microservices. The Tiltfile has more comments on how this works.
-
For each service:
- A
:testresource is created, which will rungo test ./...anytime the source code or go mod files change.- This resource has a
Show Cover Profilebutton to easily access the go coverage visualiser.
- This resource has a
- A
:lintresource, which will run golangci-lint against the service when the source code changes. - A
:serveresource, which will run your service locally, and restart iw when the source code changes.- If configured with test requests, buttons will appear above the log window to easily perform them. Have a look at the name-service for example!
- Additionally a link to the main API endpoint will be added above the log window for easy discovery.
- A
Play around with it! Launch Tilt; mess around with the code and see how Tilt automatically performs tasks when you do so; see if this pre-configured Tilt workflow feels good to use; and maybe even try adding a new microservice or two into the setup.
e.g.
-
tilt up && tilt down. -
Press Space to open the UI.
-
Open the
name-service:serveresource. -
Use the
Add Namebutton to add a few names. -
Press the link above the log window, and refresh a few times to see your new names show up.
-
Open the
datastore-uiresource in Tilt. -
Press the link above the log window, and see that its storing the names for
name-service.