# BikeControl Arch Linux package builder.
#
# Separate from Dockerfile.builder on purpose: makepkg is Arch-specific, so the
# .pkg.tar.zst cannot be produced from the Ubuntu image that builds everything
# else. This is an *environment* image — it carries no source, so the same tag
# serves both CI (which checks the repo out at run time) and local use.
#
# Build and push:
#   docker build -f Dockerfile.arch -t gitea.tourolle.paris/dtourolle/bikecontrol-arch-builder:latest .
#   docker push gitea.tourolle.paris/dtourolle/bikecontrol-arch-builder:latest
#
# Local one-shot build of the package:
#   docker run --rm -v "$PWD:/app" -v "$PWD/dist:/out" \
#     gitea.tourolle.paris/dtourolle/bikecontrol-arch-builder:latest
FROM archlinux:latest

# base-devel brings makepkg, fakeroot and the rest of the packaging toolchain.
# The remainder are the PKGBUILD's makedepends plus what Tauri and btleplug link
# against: webkit2gtk-4.1/gtk3 for the shell, and dbus for BlueZ.
RUN pacman -Syu --noconfirm \
    base-devel git sudo \
    rust nodejs npm \
    webkit2gtk-4.1 gtk3 libayatana-appindicator \
    libsoup3 pkgconf openssl dbus bluez-libs \
    && pacman -Scc --noconfirm

# makepkg refuses to run as root. The passwordless sudo is for `makepkg -s`,
# which pacman-installs missing makedepends.
RUN useradd -m builder && \
    echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder

WORKDIR /app
RUN mkdir -p /out && chown builder:builder /out
VOLUME ["/out"]

# CI overrides this and runs the script itself (it must chown the checkout to
# `builder` first). The default is the local convenience path.
CMD ["bash", "-c", "chown -R builder:builder /app && sudo -u builder --preserve-env=OUTPUT_DIR OUTPUT_DIR=/out scripts/build-arch.sh --no-install"]
