runeh / tirbi

Apache License 2.0
4 stars 0 forks source link

tirbi

Tirbi is a remote cache implementation that is compatible with the remote caching feature of turborepo. It supports storing cached assets on the file system, in memory, or in Google Cloud Storage bucket. Feel free to contribute other storage backends.

Tirbi can be used either as a command line server, or as a fastify plugin.

Quick start

Run tirbi server:

npx tirbi

This starts server that allows any authentication token and stores cached data in memory.

Run a build with turborepo that uses tirbi as cache:

yarn turbo run build \
     --team=not_used --token="anything" --remote-only \
     --api=http://localhost:8080

The turbo build should be loading and saving cached artifacts to the tirbi server.

Run tirbi --help to see the list of command line options.

The server can also be configured using environment variables:

fastify plugin

Tirbi exports a tirbiPlugin object that is a fastify plugin:

import fastify from 'fastify';
import { tirbiPlugin } from 'tirbi';

async function main() {
  const server = fastify({ logger: true });
  await server.register(tirbiPlugin, {
    storage: { kind: 'memory' },
    tokens: ['s3cr3t'],
  });
  await server.listen(3030, '0.0.0.0');
}

main();

Have a look in cli.ts to see how the tirbi CLI starts a server.

Reference

Interface describing the options of the fastify plugin.

TirbiOptions

StorageOptions

There are TypeScript types for the supported storage backends:

parseStorageUri

Parse a URI string to a StorageOptions object. Returns null if there if the URI is invalid, or uses an unknown scheme. This function will never throw an error.

tirbiPlugin

A fastify plugin. Takes a TirbiOptions argument.

Docker usage

The following dockerfile lets you run tirbi in docker:

FROM node:16-alpine3.14
RUN npm install -g tirbi
CMD ["tirbi"]

Use environment variables the control the settings of the server.

Compatibility

Tirbi has been tested with turborepo versions 1.2.1-1.2.16 and 1.3.0-1.3.1

Caveats

Misc

Liveness probe

The cli listens for requests to /healthz, end replies with a 204. This is useful if running in docker or other managed platforms that probes a service for its liveness status.

Pretty logs

To get nicely formatted logs on the command line, use pino-pretty:

tirbi | pino-pretty

yarn lint-staged

Publishing

Uses standard-version.

Can be invoked with yarn release.

After this is done, use the following:

git push --follow-tags origin main && npm publish --tag prerelease