FROM archlinux:latest

RUN pacman -Syy --noconfirm archlinux-keyring
RUN rm -fr /etc/pacman.d/gnupg
RUN pacman-key --init
RUN pacman-key --populate archlinux

# Provide relevant binaries
RUN pacman -Sy --noconfirm \
    btrfs-progs \
    cryptsetup \
    e2fsprogs \
    git \
    make \
    python \
    python-uv \
    restic \
    rsync \
    sudo

# Create a new user with a group that is not the username. This is required to
# ensure that resetting the ownership of restic's backup repository uses the
# correct group. Using the username as group was a bug causing backups to fail
# for some users.
RUN groupadd testgroup
RUN groupadd sudo
RUN useradd -ms /bin/bash -g testgroup testuser

# Ensure sudo group users are not asked for a password when using sudo command
# by ammending sudoers file.
# See https://dev.to/emmanuelnk/using-sudo-without-password-prompt-as-non-root-docker-user-52bg
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN gpasswd -a testuser sudo

USER testuser
ENV USER=testuser

# Setup production dependencies
WORKDIR /project
RUN touch README.md  # Content is not relevant for this Dockerfile
COPY --chmod=555 dockerfiles/entrypoint.sh ./
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-install-project

COPY examples/ examples/
COPY src/ src/
RUN uv sync --frozen

ENTRYPOINT ["./entrypoint.sh"]
