# koopa-silverbullet — SilverBullet on CachyOS base + server binary
# Build on koopa (x86_64):
#   bash ~/koopa-admin-log/scripts/notes/build.sh
#   → localhost/koopa-silverbullet:cachyos
#
# Base: docker.io/cachyos/cachyos (Arch-derived). App binary from upstream
# silverbullet-server-linux-x86_64 release (not the Alpine ghcr image).

ARG CACHYOS_IMAGE=docker.io/cachyos/cachyos:latest
FROM ${CACHYOS_IMAGE}

ARG SB_VERSION=2.10.0
ARG SB_ZIP_URL=https://github.com/silverbulletmd/silverbullet/releases/download/${SB_VERSION}/silverbullet-server-linux-x86_64.zip

ENV SB_HOSTNAME=0.0.0.0 \
    SB_FOLDER=/space \
    SB_PORT=3000 \
    SB_NAME=SilverBullet \
    TZ=Europe/Zurich \
    PATH=/usr/local/bin:$PATH

# catatonit = Arch/CachyOS container init (tini not in repos)
RUN pacman -Syu --noconfirm --needed \
      bash curl git openssh catatonit unzip \
 && pacman -Scc --noconfirm \
 && rm -rf /var/cache/pacman/pkg/* /tmp/*

# Fetch + install server binary (build-time; no Deno in image)
RUN curl -fsSL "$SB_ZIP_URL" -o /tmp/sb.zip \
 && unzip -o /tmp/sb.zip -d /tmp \
 && install -m 755 /tmp/silverbullet /silverbullet \
 && /silverbullet --version || true \
 && rm -rf /tmp/sb.zip /tmp/silverbullet

COPY entrypoint.sh /docker-entrypoint.sh
RUN chmod 755 /docker-entrypoint.sh \
 && mkdir -p /space

EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
  CMD curl -fsS "http://127.0.0.1:${SB_PORT}/.instance" || exit 1

WORKDIR /space
ENTRYPOINT ["/usr/bin/catatonit", "--", "/docker-entrypoint.sh"]
