# ---- frontend ----
FROM node:22-alpine AS frontend
WORKDIR /app
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install
COPY frontend/ ./
RUN npm run build

# ---- backend ----
FROM rust:1-bookworm AS backend
WORKDIR /app
COPY Cargo.toml Cargo.lock* ./
COPY src ./src
COPY migrations ./migrations
RUN cargo build --release --bins

# ---- runtime (shared by api and worker) ----
FROM debian:bookworm-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends exiftool ca-certificates \
    && rm -rf /var/lib/apt/lists/*
RUN useradd --system --uid 1000 photos
WORKDIR /app
COPY --from=backend /app/target/release/server /app/target/release/worker /usr/local/bin/
COPY --from=frontend /app/dist /app/static
ENV STATIC_DIR=/app/static
USER photos
EXPOSE 8080
# The worker deployment overrides this with: command ["worker"]
CMD ["server"]
