internal typesense server passing ipv6 to ipv4

I couldn’t find a complete example of running typesense internally which only supports ipv4. This example works so far and passed ipv6 to ipv4. I’m pretty new at this so if there is a glaring mistake let me know. I am able to connect from another app via the typesense python client. This is just to run a single server but if you are doing more you could probably figure it out.

  1. Set app name of internal typesense app and volume name for typesense data in fly.toml
  2. Set TYPESENSE_API_KEY environment variable for the typesense internal app using `flyctl secrets set -a the-name-of-your-fly-app TYPESENSE_API_KEY=yourapikey
  3. Set appropriate version of typesense docker image to use in Dockerfile, ie. FROM typesense/typesense:0.24.0.rcn21

Dockerfile

FROM typesense/typesense:0.24.0.rcn21
RUN apt-get update && apt-get install -y supervisor socat
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ENTRYPOINT ["/usr/bin/supervisord"]

supervisord.conf

[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
childlogdir=/var/log/supervisor
loglevel=debug

[program:socat]
command=socat TCP6-LISTEN:%(ENV_TYPESENSE_IP6PORT)s,bind=[::],reuseaddr,ipv6only=1,fork TCP4:127.0.0.1:%(ENV_TYPESENSE_IP4PORT)s

[program:typesense]
command=/opt/typesense-server --data-dir=%(ENV_TYPESENSE_DATA_DIR)s --api-key=%(ENV_TYPESENSE_API_KEY)s --api-address localhost --api-port=%(ENV_TYPESENSE_IP4PORT)s

fly.toml

app = "the-name-of-your-fly-app"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  dockerfile = "Dockerfile"

[env]
  TYPESENSE_DATA_DIR="/data"
  TYPESENSE_IP6PORT=8080
  TYPESENSE_IP4PORT=8062

[mounts]
  source="your_typesense_data_volume"
  destination="/data"

Hope this helps someone.

2 Likes

I realized after reading over this again that I should probably be logging to stdout so I will have to update it already.

I just heard about typesense after looking for an algolia alternative. Saw they supported docker, and immediately searched if anyone has tried it on fly.io. :sweat_smile:

If/when I give it a shot I’ll offer some feedback. Good to see this though!

@ianjosephwilson Looks like it’s under consideration, and a workaround is presented using 6tunnel.

Feature Request - Allow listen on ipv6 · Issue #579 · typesense/typesense

Got this working using the 6tunnel approach mentioned in the Typesense github issue.

For just one instance of Typesense, you just need to run this AFTER the typesense-server daemon is running:

6tunnel -6 -l :: 8108 127.0.0.1 8118

In this case, I have caddy as a reverse proxy dialing domains upstream to typesense.internal:8108.

Then in fly.toml:

[[services]]
internal_port = 8108
protocol = "tcp"

And then to start the Typesense server:

typesense-server --api-port=8118 --peering-port=8117 --data-dir=/data --api-key=secret

The rest of the instructions in the typesense github issue are for setting up a cluster and this should set you up to add more nodes when you’re ready. That’s when you’ll use the peering port.

1 Like

@kdevan ive been really struggling getting a HA cluster running. Did you ever venture in to trying to use this same method for a cluster?

Here was my attempt, anything seem glaringly obvious to you?