# === Build-Phase: Jekyll kompiliert die statische Website ===
FROM ruby:3.2-alpine AS builder

RUN apk add --no-cache build-base

WORKDIR /site

COPY Gemfile ./
RUN bundle install

COPY . .

RUN bundle exec jekyll build

# === Serve-Phase: nginx + ImageMagick fuer Thumbnails ===
FROM nginx:alpine

# Nginx als Root laufen lassen, um Berechtigungsprobleme mit Nextcloud-Dateien zu vermeiden
RUN sed -i 's/user  nginx;/user  root;/g' /etc/nginx/nginx.conf

RUN apk add --no-cache imagemagick

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /site/_site /usr/share/nginx/html
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Leere Bildverzeichnisse anlegen (werden durch Volumes ueberschrieben)
RUN mkdir -p /usr/share/nginx/html/images/fulls \
             /usr/share/nginx/html/images/thumbs

EXPOSE 80

ENTRYPOINT ["/entrypoint.sh"]
