From 7a443efacf5c644f53556d0a803e19c715f3bda2 Mon Sep 17 00:00:00 2001 From: Eliot Date: Thu, 16 Jan 2025 13:03:24 +0100 Subject: [PATCH] ci(DockerFile): dashboard build on image --- .dockerignore | 3 --- .gitignore | 2 -- Dockerfile | 18 +++++++++++++++++- app/main.py | 12 +++++++++++- dashboard_build/.gitkeep | 0 5 files changed, 28 insertions(+), 7 deletions(-) delete mode 100644 dashboard_build/.gitkeep diff --git a/.dockerignore b/.dockerignore index 06307f2..2d23794 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,6 @@ ### Example user template template ### Example user template -# Project dashboard -web/ - # IntelliJ project files .idea *.iml diff --git a/.gitignore b/.gitignore index 7319041..7dd2129 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,3 @@ /alembic.ini /.idea /scrapers-config.json -!/dashboard_build/.gitkeep -/dashboard_build/* diff --git a/Dockerfile b/Dockerfile index 6a964ed..69f1f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,8 @@ WORKDIR /app RUN apt-get update && apt-get install -y \ libcurl4-openssl-dev \ + npm \ + nodejs \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt . @@ -21,11 +23,25 @@ RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt && \ pip install --no-cache-dir gunicorn +WORKDIR /app/web +COPY web/package.json web/package-lock.json ./ +RUN npm install +COPY web ./ +RUN npm run build + +# Déplacer les fichiers build React +WORKDIR /app +RUN mkdir -p /app/dashboard_build && \ + mv /app/web/build/* /app/dashboard_build + + + # Default environment variables ENV PYTHONPATH=/app \ PYTHONUNBUFFERED=1 \ FLASK_ENV=production \ - FLASK_DEBUG=0 + FLASK_DEBUG=0 \ + DASHBOARD_BUILD_PATH=/app/dashboard_build RUN useradd -m -s /bin/bash appuser && \ chown -R appuser:appuser /app diff --git a/app/main.py b/app/main.py index 12c8f22..aa70328 100644 --- a/app/main.py +++ b/app/main.py @@ -70,7 +70,7 @@ def create_app(): init_services() - flask_app = Flask(__name__) + flask_app = Flask(__name__, static_folder=os.getenv("DASHBOARD_BUILD_PATH", "../web/build")) # Load the routes load_scrapers_routes(flask_app) @@ -81,6 +81,16 @@ def create_app(): load_sync_routes(flask_app) load_auth_routes(flask_app) + # Serve React App + @app.route('/', defaults={'path': ''}) + @app.route('/') + def serve(path): + if path != "" and os.path.exists(app.static_folder + '/' + path): + return send_from_directory(app.static_folder, path) + else: + return send_from_directory(app.static_folder, 'index.html') + + CORS(flask_app) return flask_app diff --git a/dashboard_build/.gitkeep b/dashboard_build/.gitkeep deleted file mode 100644 index e69de29..0000000