From 3a5e9918705c737f590ea9dab5afd591f2d76402 Mon Sep 17 00:00:00 2001 From: Sweetbread Date: Thu, 7 Aug 2025 21:16:47 +0300 Subject: [PATCH] sec: add production server --- Dockerfile | 23 ++++++++++++++++------- app.py | 4 +++- requirements.txt | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index aad43ec..f0ea489 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ -FROM python:3.11-slim +FROM node:18-alpine as sass -RUN apt-get update && apt-get install -y curl && \ - curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ - apt-get install -y nodejs && \ - NODE_OPTIONS=--dns-result-order=ipv4first npm install -g sass && \ - apt-get clean && rm -rf /var/lib/apt/lists/* +RUN NODE_OPTIONS=--dns-result-order=ipv4first npm install -g sass +WORKDIR /build +COPY ./static/style ./style +RUN sass ./style:./style \ + --no-source-map \ + --style=compressed + + +FROM python:3.11-slim WORKDIR /app COPY . . +COPY --from=sass /build/style/ ./static/style/ + RUN pip install --no-cache-dir -r requirements.txt -CMD flask run --host 0.0.0.0 +ENV FLASK_ENV=production +ENV PYTHONUNBUFFERED=1 + +CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--workers", "4"] diff --git a/app.py b/app.py index 44389ee..72e752b 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,9 @@ from os import system as console from flask import Flask, render_template app = Flask(__name__) -console("sass static/style/main.scss static/style/main.css") + +if app.debug: + console("sass static/style/main.scss static/style/main.css") @app.route("/") def index(): diff --git a/requirements.txt b/requirements.txt index aa4b129..4aac190 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Flask==3.1.1 +gunicorn