This commit is contained in:
Mateusz Gruszczyński
2025-08-28 13:56:00 +02:00
parent 62e40d5aee
commit 6f85dbf91c
5 changed files with 30 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
# === Podstawowe === # === Podstawowe ===
APP_PORT=8080 APP_PORT=8080
# healthcheck na potrzeby dockera
HEALTHCHECK_TOKEN=Bu22SW455TPe92
# SQLAlchemy URI bazy (np. SQLite, Postgres, MySQL). # SQLAlchemy URI bazy (np. SQLite, Postgres, MySQL).
# Przykłady: # Przykłady:
# - SQLite w katalogu instance: sqlite:///instance/baza.db # - SQLite w katalogu instance: sqlite:///instance/baza.db

View File

@@ -1,9 +1,15 @@
FROM python:3.13-slim FROM python:3.13-slim
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements.txt COPY requirements.txt requirements.txt
RUN apt-get update && apt-get install -y build-essential && \
pip install --upgrade pip && pip install -r requirements.txt RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
COPY . . COPY . .
RUN mkdir -p /app/instance RUN mkdir -p /app/instance

10
app.py
View File

@@ -595,6 +595,16 @@ def favicon():
return "", 204 return "", 204
@app.route("/healthcheck")
def healthcheck():
header_token = request.headers.get("X-Internal-Check")
correct_token = app.config.get("HEALTHCHECK_TOKEN")
if header_token != correct_token:
abort(404)
return "OK", 200
if __name__ == "__main__": if __name__ == "__main__":
with app.app_context(): with app.app_context():
db.create_all() db.create_all()

View File

@@ -47,3 +47,5 @@ class Config:
# (opcjonalnie) wyłącz warningi track_modifications # (opcjonalnie) wyłącz warningi track_modifications
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
HEALTHCHECK_TOKEN = _get_str("HEALTHCHECK_TOKEN", "healthcheck")

View File

@@ -3,10 +3,17 @@ version: '3.8'
services: services:
app: app:
build: build:
container_name: zbiorka-app
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
ports: ports:
- "${APP_PORT:-8080}:${APP_PORT:-8080}" - "${APP_PORT:-8080}:${APP_PORT:-8080}"
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; import sys; req = urllib.request.Request('http://localhost:8000/healthcheck', headers={'X-Internal-Check': '${HEALTHCHECK_TOKEN}'}); sys.exit(0) if urllib.request.urlopen(req).read() == b'OK' else sys.exit(1)"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
volumes: volumes:
- ./instance:/app/instance - ./instance:/app/instance
restart: unless-stopped restart: unless-stopped