# JellyTau Arch Linux package builder.
#
# Tauri has no pacman bundle target, so we build a real .pkg.tar.zst with makepkg
# from packaging/arch/PKGBUILD. makepkg refuses to run as root, so we create a
# non-root `builder` user with passwordless sudo (for `makepkg -s` pacman calls).
#
#   docker build -f Dockerfile.arch -t jellytau-arch .
#   docker run --rm -v "$PWD/dist:/out" jellytau-arch
FROM archlinux:latest

RUN pacman -Syu --noconfirm \
    base-devel git sudo \
    rust cargo nodejs \
    webkit2gtk-4.1 mpv gtk3 libayatana-appindicator \
    libsoup3 pkgconf openssl \
    && pacman -Scc --noconfirm

# Bun is not in the official repos; install the upstream binary.
RUN curl -fsSL https://bun.sh/install | bash && \
    ln -s /root/.bun/bin/bun /usr/local/bin/bun

# Non-root build user with passwordless sudo for makepkg's dependency step.
RUN useradd -m builder && \
    echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder && \
    ln -sf /root/.bun/bin/bun /usr/local/bin/bun

WORKDIR /app
COPY . .
RUN chown -R builder:builder /app

USER builder
ENV OUTPUT_DIR=/out
RUN mkdir -p /out
VOLUME ["/out"]

# Default: build the package. Output lands in /out (mount it to collect the pkg).
CMD ["bash", "-c", "OUTPUT_DIR=/out scripts/build-arch.sh"]
