###############################################################################
# PROJECT NAME CONFIGURATION
###############################################################################
# Name: fluffy-pancake
#
# IMPORTANT: Change "finpilot" above to your desired project name.
# This name should be used consistently throughout the repository in:
#   - Justfile: export image_name := env("IMAGE_NAME", "your-name-here")
#   - README.md: # your-name-here (title)
#   - artifacthub-repo.yml: repositoryID: your-name-here
#   - custom/ujust/README.md: localhost/your-name-here:stable (in bootc switch example)
#
# The project name defined here is the single source of truth for your
# custom image's identity. When changing it, update all references above
# to maintain consistency.
###############################################################################

###############################################################################
# MULTI-STAGE BUILD ARCHITECTURE
###############################################################################
FROM scratch AS ctx

# Kopiere die Build-Skripte und die neuen Konfigurations-Artefakte in den Kontext
COPY build /build
COPY configs /configs
COPY scripts /scripts

###############################################################################
# BASE IMAGE
###############################################################################
FROM quay.io/fedora/fedora-kinoite:44

### /opt (Unverändert)
# RUN rm /opt && mkdir /opt

###############################################################################
# EXECUTION STAGE
###############################################################################
# Hier werden die Skripte aus dem Kontext-Stage ausgeführt
RUN --mount=type=bind,from=ctx,source=/,target=/ctx \
    --mount=type=bind,from=ctx,source=/configs,target=/configs \
    --mount=type=bind,from=ctx,source=/scripts,target=/scripts \
    --mount=type=cache,dst=/var/cache \
    --mount=type=cache,dst=/var/log \
    --mount=type=tmpfs,dst=/tmp \
    for s in /ctx/build/*.sh; do echo "Running $s" && sh "$s" || exit 1; done

###############################################################################
# CONFIGURATION LAYER (Der "saubere" Teil)
###############################################################################

# 1. Kopiere die Filesystem-Fixes (tmpfiles.d)
# COPY erstellt die Zielpfade automatisch, falls sie noch nicht existieren.
COPY configs/bootc-fix.conf /etc/tmpfiles.d/

# 2. Kopiere den Systemd-Overrides (Update-Timer und -Service)
COPY configs/bootc-timer-override.conf /etc/systemd/system/bootc-fetch-apply-updates.timer.d/override.conf
COPY configs/bootc-override.conf /etc/systemd/system/bootc-fetch-apply-updates.service.d/override.conf

# 3. Kopiere das Benachrichtigungs-Skript
# Wichtig: Das Skript muss auf deinem Host bereits mit 'chmod +x' markiert sein!
COPY scripts/notify-bootc-user.sh /usr/bin/


###############################################################################
# LINTING
###############################################################################
RUN bootc container lint \
&& rm -rf /tmp/build /root/.cache/dnf/*  # Aufräumen nach Build


