Deploying a Typesense App
Introduction
Typesense is an open-source search engine optimized for instant, typo-tolerant search. This guide shows how to containerize Typesense with a Dockerfile, persist its data, secure the API key, and deploy it to Klutch.sh using TCP traffic.
Prerequisites
- GitHub repository containing your Dockerfile.
- Klutch.sh project ready in klutch.sh/app.
Project structure
.└── DockerfileSample Dockerfile
FROM typesense/typesense:latest
# Default Typesense portENV TYPESENSE_LISTEN_PORT=8108EXPOSE 8108Required environment variables
TYPESENSE_API_KEY– strong admin API key for read/write operations.TYPESENSE_DATA_DIR=/data– where Typesense stores data.TYPESENSE_LISTEN_PORT=8108– internal port (default).TYPESENSE_ENABLE_CORS=true– enable CORS if you serve from browsers.
Optional environment variables
TYPESENSE_PEERING_KEY– if clustering.TYPESENSE_DEFAULT_NUM_MEMORY_MAPPED_PAGES– tune memory-mapped pages.TYPESENSE_LOG_LEVEL– e.g.,infoorwarn.
Persistence
Attach a persistent volume for indexes and snapshots:
- Mount path:
/data - Size: based on index size and replication snapshots
Networking
- Protocol: TCP
- Internal port:
8108 - Clients connect to your TCP endpoint (e.g.,
example-app.klutch.sh:8000) while Klutch.sh routes to8108inside the container.
Health check (recommended)
curl -X GET "http://localhost:8108/health"Deployment on Klutch.sh
- Push your Dockerfile to GitHub.
- In klutch.sh/app, create a new app and select GitHub as the source.
- Klutch.sh automatically detects the Dockerfile in the repository root.
- Select TCP traffic and set the internal port to
8108. - Add environment variables for
TYPESENSE_API_KEY,TYPESENSE_DATA_DIR, and any tuning options. Mark sensitive values as secrets. - Attach a persistent volume at
/datasized for your search indexes. - Deploy. Connect your apps to
example-app.klutch.sh:8000with the API key in theX-TYPESENSE-API-KEYheader.
Verification
-
Health:
Terminal window curl "http://example-app.klutch.sh:8000/health" -
Create a sample collection:
Terminal window curl -X POST "http://example-app.klutch.sh:8000/collections" \-H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" \-H "Content-Type: application/json" \-d '{"name":"products","fields":[{"name":"title","type":"string"}]}'
Next steps
- Add read-only keys for client-side search.
- Configure snapshots and backups from the mounted
/datapath. - Tune memory mapping and replication if you scale out.