Deployment
Deployment covers the build process, asset embedding, and infrastructure requirements for running nara in production or development environments.
1. Purpose
Section titled “1. Purpose”- Ensure reproducible builds across different platforms (Linux, macOS, Nix).
- Bundle the Web UI and documentation into a single, standalone binary.
- Provide a standardized way to deploy naras to cloud providers like Fly.io or local hardware.
2. Conceptual Model
Section titled “2. Conceptual Model”- Monolith Binary: The
narabinary is self-contained, including all logic, embedded UI assets, and the documentation site. - Embedded Assets: Pre-compiled frontend files are baked into the Go binary at build time.
- Build Targets: Standardized
Makefiletargets for different build configurations.
Invariants
Section titled “Invariants”- Embedding: Web assets MUST be successfully built and present before the final Go compilation starts.
- Port Uniformity: A single HTTP port serves both the API and the Web UI.
- Reproducibility: Builds SHOULD produce consistent results across different environments.
3. External Behavior
Section titled “3. External Behavior”- The resulting binary can be run as a standalone service with no external dependencies (other than an optional MQTT broker).
- The Web UI is accessible immediately upon startup at the configured address.
- Documentation is served locally from the same binary at
/docs/.
4. Interfaces
Section titled “4. Interfaces”Build Targets (Makefile)
Section titled “Build Targets (Makefile)”make build: Compiles the standardbin/narabinary (requires web assets).make build-web: Compiles the Preact SPA and the Astro documentation site.make test: Runs the full Go test suite.make build-nix: Creates a reproducible build using the Nix package manager.
Runtime Environments
Section titled “Runtime Environments”- Fly.io: Supported via
fly.tomlfor easy cloud deployment. - NixOS: Supported via
nara.nixmodule. - Docker: Can be containerized as a single-binary alpine-based image.
5. Event Types & Schemas
Section titled “5. Event Types & Schemas”Deployment configuration (e.g., environment variables) affects the initial Configuration of the nara.
6. Algorithms
Section titled “6. Algorithms”Build Pipeline
Section titled “Build Pipeline”- Frontend: Compile the Preact SPA in
nara-web/using esbuild. - Docs: Build the Astro-based documentation in
docs/. - Staging: Collect all assets into
nara-web/public/. - Go Build: Use
go:embedto include thepublic/directory in thecmd/narabinary.
graph TD
A[npm run build: SPA] --> D[nara-web/public]
B[astro build: Docs] --> D
D --> E[go build: cmd/nara]
E --> F[bin/nara: Embedded Artifact]
7. Failure Modes
Section titled “7. Failure Modes”- Stale Assets: If
build-webis not run beforebuild, the binary will serve outdated or missing UI/docs. - Port Conflict: Multiple instances on the same host must be assigned unique ports via
-http-addr. - Incomplete Nix Closure: Missing dependencies in the Nix expression may lead to build failures in clean environments.
8. Security / Trust Model
Section titled “8. Security / Trust Model”- Supply Chain: Build dependencies (Go modules, npm packages) should be pinned to ensure consistent and secure builds.
- Sandboxing: Production deployments should run naras with minimal privileges.
9. Test Oracle
Section titled “9. Test Oracle”- Artifact Verification: Verifies that
bin/naraexists and is executable. - Embedded Asset Check: Confirms that
/(UI) and/docs/return valid content when the binary is run. - Health Check: Validates that the binary responds to standard orchestration health checks.
10. Open Questions / TODO
Section titled “10. Open Questions / TODO”- Implement a CI/CD pipeline that automatically builds and pushes multi-arch Docker images.
- Add support for automated “canary” deployments with coordinated soul migration.