# Utilisez une image Node.js
FROM node:20-alpine

# Créez le répertoire de l'application
WORKDIR /app

# Dépendances système AVANT npm install :
# - `python` (+ lien symbolique python3→python) : requis par le preinstall
#   de youtube-dl-exec (sinon "youtube-dl-exec needs Python" et build KO) ;
# - curl_cffi : bypass Cloudflare pour le scraper Rumble. Sans lui, les pages
#   /search/* de Rumble retournent 403 "Just a moment" et les blocs Rumble des
#   pages de thèmes restent vides.
RUN apk add --no-cache python3 py3-pip \
  && ln -sf /usr/bin/python3 /usr/bin/python \
  && pip install --no-cache --break-system-packages curl_cffi

# D'abord, copiez uniquement les fichiers nécessaires pour l'installation
COPY package*.json ./

# Installez les dépendances
RUN npm install --only=production

# Puis copiez le reste du code
COPY . .

# Construisez l'application Angular
RUN npm run build -- --configuration=production

# Exposez le port
EXPOSE 4000

# Commande de démarrage
CMD ["node", "server/index.mjs"]

# L'API écoute sur $PORT (4000 par défaut) : le healthcheck doit la viser
# (l'ancienne forme `http://localhost/` visait le port 80 et restait unhealthy).
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
  CMD wget -q -O /dev/null http://localhost:4000/api/health || exit 1

# FROM nginx:alpine

# # Install dos2unix
# RUN apk add --no-cache dos2unix

# # Copy and normalize entrypoint script
# COPY scripts/env-dump.sh /docker-entrypoint.d/env-dump.sh
# RUN dos2unix /docker-entrypoint.d/env-dump.sh \
#  && chmod +x /docker-entrypoint.d/env-dump.sh

# # Copy and normalize nginx config
# COPY config/nginx.conf /etc/nginx/nginx.conf
# RUN dos2unix /etc/nginx/nginx.conf

# # Copy built Angular app
# COPY dist /usr/share/nginx/html

# # Optional: ensure correct file ownership and permissions
# RUN mkdir -p /usr/share/nginx/html/assets \
#  && chown -R nginx:nginx /usr/share/nginx/html \
#  && chmod -R 755 /usr/share/nginx/html

