$ show brunojppb/turbo-cache-server
This is a standalone Rust web server that implements Turborepo's remote caching API. It acts as a sidecar process, typically started inside CI pipelines (GitHub Actions, GitLab, Kubernetes), that forwards artifact storage and retrieval requests to any S3-compatible object store (AWS S3, Cloudflare R2, RustFS). The server exposes a small set of REST endpoints: health check, artifact upload/download/head, event logging, and a team artifact listing stub. Artifacts are streamed directly from the HTTP body to S3 (and vice versa) without buffering into memory. Optional Bearer-token authentication uses constant-time comparison, and the server is instrumented with OpenTelemetry for distributed traces and system-level metrics (CPU, memory) that are exportable via OTLP. The repository also includes a GitHub Action wrapper (Node.js) that manages the binary lifecycleβstartup health polling, graceful shutdown, and log collectionβand a multi-stage Docker build that produces statically linked Linux binaries and a universal macOS binary. The architecture is a monolith (single binary) built with actix-web, with clear separation into modules for settings, storage, authentication, routes, and telemetry. All artifacts are scoped under a team prefix derived from the Turborepo client's query parameters.
The LLM identified 2 files worth highlighting for reuse:
Implements an actix-web middleware that optionally validates a Bearer token against a server-configured TURBO_TOKEN. When no token is configured, all requests pass through. Otherwise, it parses the Authorization header, verifies the Bearer scheme case-insensitively, and compares the token using constant-time comparison via the `subtle` crate to prevent timing-based enumeration. Errors are returned as JSON with an appropriate error message and the WWW-Authenticate header. This module is self-contained (depends only on actix-web, serde, secrecy, and subtle) and could be extracted into any actix-web project that needs a similar optional authentication guard.
Configures the entire telemetry stack: Bunyan-format JSON logging (to stdout and optionally a rolling file), log-to-trace bridging via tracing-log, and OpenTelemetry trace/metric export over OTLP (gRPC or HTTP). The module respects the OTEL_SDK_DISABLED environment variable to entirely suppress the OTLP layers. It also sets up three system metric gauges (CPU utilization, memory usage, virtual memory) using sysinfo and OpenTelemetry observable gauges, all annotated with the service name and version. The subscriber is assembled using tracing-subscriber's layered architecture, making it easy to add or remove sinks. This code is a reusable pattern for any Rust application that wants a production-ready telemetry setup with optional OTLP export, file logging, and process-level metrics.