diff --git a/backend/Dockerfile b/backend/Dockerfile index 68e41d5..817d09f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,29 +1,37 @@ -FROM python:3.11-slim +# ---- Base ---- +FROM python:3.11-slim-bookworm -# Install ffmpeg + curl and download latest yt-dlp binary -RUN apt update && \ - apt install -y curl ffmpeg && \ - curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \ - chmod a+rx /usr/local/bin/yt-dlp && \ - apt clean && rm -rf /var/lib/apt/lists/* +# עדכון מערכת והתקנת FFmpeg (כולל ffprobe) +RUN apt-get update \ + && apt-get install -y --no-install-recommends ffmpeg \ + && rm -rf /var/lib/apt/lists/* -# Set working directory +# הגדרות סביבת עבודה בסיסיות +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_NO_CACHE_DIR=1 + +# ספריית האפליקציה WORKDIR /app -# Copy project files -COPY . . - -# Install Python dependencies +# התקנת תלויות +# (משתמש ב־requirements.txt שהבאת) +COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -# Create volume path (optional - will be mounted later in K8s) -RUN mkdir -p /music +# קבצי האפליקציה +COPY . . -# Declare env var for clean override later in Helm -ENV MUSIC_DIR=/music +# תיקיית המוזיקה (הקוד גם יוצר אותה, אבל נגדיר כ־VOLUME לנוחות) +VOLUME ["/app/music"] -# Expose FastAPI port +# פורט האפליקציה EXPOSE 8000 -# Start app -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] +# ריצה תחת משתמש לא־רות +RUN useradd -ms /bin/bash appuser && chown -R appuser:appuser /app +USER appuser + +# הפעלה +# אם תרצה workers: הוסף --workers 2 (או לפי הצורך) +ENTRYPOINT ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"] diff --git a/backend/__pycache__/config.cpython-310.pyc b/backend/__pycache__/config.cpython-310.pyc deleted file mode 100644 index cd0b255..0000000 Binary files a/backend/__pycache__/config.cpython-310.pyc and /dev/null differ diff --git a/backend/__pycache__/config.cpython-312.pyc b/backend/__pycache__/config.cpython-312.pyc deleted file mode 100644 index b05e2ab..0000000 Binary files a/backend/__pycache__/config.cpython-312.pyc and /dev/null differ diff --git a/backend/__pycache__/downloader.cpython-310.pyc b/backend/__pycache__/downloader.cpython-310.pyc deleted file mode 100644 index 665b4d1..0000000 Binary files a/backend/__pycache__/downloader.cpython-310.pyc and /dev/null differ diff --git a/backend/__pycache__/downloader.cpython-312.pyc b/backend/__pycache__/downloader.cpython-312.pyc deleted file mode 100644 index 39b8df2..0000000 Binary files a/backend/__pycache__/downloader.cpython-312.pyc and /dev/null differ diff --git a/backend/__pycache__/main.cpython-310.pyc b/backend/__pycache__/main.cpython-310.pyc deleted file mode 100644 index 588bed2..0000000 Binary files a/backend/__pycache__/main.cpython-310.pyc and /dev/null differ diff --git a/backend/__pycache__/main.cpython-312.pyc b/backend/__pycache__/main.cpython-312.pyc deleted file mode 100644 index 6dbeabd..0000000 Binary files a/backend/__pycache__/main.cpython-312.pyc and /dev/null differ diff --git a/backend/main.py b/backend/main.py index 6616c8b..7efed18 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,6 +1,7 @@ from fastapi import FastAPI, Query, HTTPException from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware +from fastapi import APIRouter import os from downloader import download_song @@ -26,6 +27,15 @@ def download(query: str = Query(..., min_length=2)): except Exception as e: raise HTTPException(status_code=500, detail=str(e)) +@app.get("/songs", summary="List downloaded songs") +def list_songs(): + try: + files = os.listdir(settings.MUSIC_DIR) + songs = [f for f in files if f.endswith(".mp3")] + return {"songs": sorted(songs)} + except Exception as e: + raise HTTPException(status_code=500, detail=f"Failed to read songs: {str(e)}") + if __name__ == "__main__": import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=8000, log_level="info", reload=True) \ No newline at end of file diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..8542182 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,6 @@ +node_modules +dist +.git +.gitignore +npm-debug.log +.DS_Store \ No newline at end of file diff --git a/frontend/10-generate-env.sh b/frontend/10-generate-env.sh new file mode 100644 index 0000000..fdfa367 --- /dev/null +++ b/frontend/10-generate-env.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -eu + +TEMPLATE="/etc/env/env.js.template" +TARGET="/usr/share/nginx/html/env.js" + +VITE_API_URL="${VITE_API_URL:-http://localhost:8000}" +echo "[entrypoint] Generating runtime env -> $TARGET" +sed "s|\$VITE_API_URL|${VITE_API_URL}|g" "$TEMPLATE" > "$TARGET" +echo "[entrypoint] Done." \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..e42f639 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,16 @@ +FROM node:20-alpine AS builder +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm install --legacy-peer-deps +COPY . . +RUN npm run build + +FROM nginx:alpine +RUN apk add --no-cache dos2unix gettext +COPY --from=builder /app/dist /usr/share/nginx/html +COPY public/env.js.template /etc/env/env.js.template +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY 10-generate-env.sh /docker-entrypoint.d/10-generate-env.sh +RUN dos2unix /docker-entrypoint.d/10-generate-env.sh && chmod +x /docker-entrypoint.d/10-generate-env.sh +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 0c589ec..767b3c7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -2,12 +2,12 @@
- -