From 0a846341e4c0fe4ef3e850f629176572e87704fd Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 16 Jul 2025 19:22:37 -0500 Subject: [PATCH] feat: add typesense Dockerfile --- .typesense/Caddyfile | 15 +++++++++++++++ .typesense/Dockerfile | 22 ++++++++++++++++++++++ .typesense/scripts/start.sh | 9 +++++++++ .typesense/scripts/start_caddy.sh | 4 ++++ .typesense/scripts/start_typesense.sh | 4 ++++ 5 files changed, 54 insertions(+) create mode 100644 .typesense/Caddyfile create mode 100644 .typesense/Dockerfile create mode 100644 .typesense/scripts/start.sh create mode 100644 .typesense/scripts/start_caddy.sh create mode 100644 .typesense/scripts/start_typesense.sh diff --git a/.typesense/Caddyfile b/.typesense/Caddyfile new file mode 100644 index 0000000..1acf841 --- /dev/null +++ b/.typesense/Caddyfile @@ -0,0 +1,15 @@ +# global options +{ + admin off # theres no need for the admin api in railway's environment + persist_config off # storage isn't persistent anyway + auto_https off # railway handles https for us, this could in some cases cause issues if left enabled + # runtime logs + log { + output discard # theres no need for caddy's runtime logs + } +} + +# site block, listens on the $PORT environment variable, automatically assigned by railway +:{$PORT} { + reverse_proxy http://127.0.0.1:8118 +} \ No newline at end of file diff --git a/.typesense/Dockerfile b/.typesense/Dockerfile new file mode 100644 index 0000000..47eed07 --- /dev/null +++ b/.typesense/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:latest AS parallel + +# install 'parallel' for entrypoint script +RUN apk add --no-cache parallel + +FROM caddy:latest AS caddy + +# format caddyfile, image contains caddy binary +COPY Caddyfile ./ +RUN caddy fmt --overwrite Caddyfile + +FROM typesense/typesense:29.0 + +# copy caddyfile, caddy binary, parallel binary, and scripts from previous layers +COPY --from=caddy /srv/Caddyfile ./ +COPY --from=caddy /usr/bin/caddy /usr/bin/caddy +COPY --from=parallel /usr/bin/parallel /usr/bin/parallel +COPY --chmod=755 scripts/* ./ + +# run start.sh script +ENTRYPOINT ["/bin/sh"] +CMD ["start.sh"] \ No newline at end of file diff --git a/.typesense/scripts/start.sh b/.typesense/scripts/start.sh new file mode 100644 index 0000000..36568ad --- /dev/null +++ b/.typesense/scripts/start.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# exit as soon as a single command finishes (any status), kill the rest +parallel --ungroup --halt now,done=1 ::: \ + "./start_caddy.sh" \ + "./start_typesense.sh" + +# always exit with a failure status +false \ No newline at end of file diff --git a/.typesense/scripts/start_caddy.sh b/.typesense/scripts/start_caddy.sh new file mode 100644 index 0000000..a63e399 --- /dev/null +++ b/.typesense/scripts/start_caddy.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# replace process with caddy, redirect stderr to stdout +exec caddy run --config Caddyfile --adapter caddyfile 2>&1 \ No newline at end of file diff --git a/.typesense/scripts/start_typesense.sh b/.typesense/scripts/start_typesense.sh new file mode 100644 index 0000000..f2d4538 --- /dev/null +++ b/.typesense/scripts/start_typesense.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# replace process with server, always use 8118 port internally, caddy will proxy the railway-assigned port, localhost listen +exec /opt/typesense-server --api-address 127.0.0.1 --api-port 8118 \ No newline at end of file