-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (38 loc) · 1.84 KB
/
Copy pathDockerfile
File metadata and controls
49 lines (38 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Usa un'immagine ufficiale Python leggera come base
FROM python:3.11-slim
# Imposta la directory di lavoro all'interno del container
WORKDIR /app
# Installa le dipendenze di sistema richieste (iputils-ping: il 'ping' usato
# da collectors/network_scanner.py) e ripulisce la cache di apt per
# mantenere l'immagine il più leggera possibile.
RUN apt-get update && \
apt-get install -y --no-install-recommends iputils-ping && \
rm -rf /var/lib/apt/lists/*
# Copia prima il file delle dipendenze per sfruttare al meglio la cache dei layer di Docker
COPY requirements.txt .
# Installa le dipendenze Python
RUN pip install --no-cache-dir -r requirements.txt
# Copia l'intero progetto nella directory di lavoro del container
COPY . .
# L'app gira come utente non privilegiato (plan Phase 3, item 16).
# Il bind mount ./data:/app/data deve essere scrivibile da uid 1000:
# su host Linux eseguire 'chown -R 1000:1000 ./data' prima del primo avvio.
RUN useradd --create-home --uid 1000 sentinel && \
mkdir -p /app/data && \
chown -R sentinel:sentinel /app
USER sentinel
# Imposta le variabili d'ambiente predefinite per il funzionamento in Docker
ENV PYTHONUNBUFFERED=1 \
SENTINELNET_HOST=0.0.0.0 \
SENTINELNET_PORT=8000 \
SENTINELNET_NO_BROWSER=true \
SENTINELNET_DATA_DIR=/app/data
# Dichiara la directory dati come volume per la persistenza standalone
VOLUME /app/data
# Espone la porta del server FastAPI
EXPOSE 8000
# Salute del container: l'endpoint /api/version risponde senza autenticazione.
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD python -c "import os, sys, urllib.request; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:' + os.environ.get('SENTINELNET_PORT', '8000') + '/api/version', timeout=4).status == 200 else 1)"
# Comando per avviare l'app FastAPI
CMD ["python", "app_server.py"]