drobne
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
# === Podstawowe ===
|
||||
APP_PORT=8080
|
||||
|
||||
# healthcheck na potrzeby dockera
|
||||
HEALTHCHECK_TOKEN=Bu22SW455TPe92
|
||||
|
||||
# SQLAlchemy URI bazy (np. SQLite, Postgres, MySQL).
|
||||
# Przykłady:
|
||||
# - SQLite w katalogu instance: sqlite:///instance/baza.db
|
||||
|
10
Dockerfile
10
Dockerfile
@@ -1,9 +1,15 @@
|
||||
FROM python:3.13-slim
|
||||
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
|
||||
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 . .
|
||||
RUN mkdir -p /app/instance
|
||||
|
10
app.py
10
app.py
@@ -595,6 +595,16 @@ def favicon():
|
||||
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__":
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
@@ -47,3 +47,5 @@ class Config:
|
||||
|
||||
# (opcjonalnie) wyłącz warningi track_modifications
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
HEALTHCHECK_TOKEN = _get_str("HEALTHCHECK_TOKEN", "healthcheck")
|
@@ -3,10 +3,17 @@ version: '3.8'
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
container_name: zbiorka-app
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "${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:
|
||||
- ./instance:/app/instance
|
||||
restart: unless-stopped
|
||||
|
Reference in New Issue
Block a user