-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
156 lines (128 loc) · 4.38 KB
/
Dockerfile
File metadata and controls
156 lines (128 loc) · 4.38 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Dockerfile - LabPiPanel
# Multi-stage build para Python backend + Node.js frontend
# Soporta ARM64 (Raspberry Pi 4) y x86_64
# ============================================================
# STAGE 1: Build Python Backend
# ============================================================
FROM python:3.11-slim-bullseye as backend-builder
WORKDIR /app
# Instalar dependencias del sistema necesarias para compilar packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libusb-1.0-0-dev \
libusb-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copiar requirements
COPY requirements.txt .
# Instalar dependencias Python en una carpeta isolada
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt
# ============================================================
# STAGE 2: Build Node.js Frontend
# ============================================================
FROM node:18-bullseye as frontend-builder
WORKDIR /app
# Copiar package.json y lock file
COPY package*.json ./
# Instalar dependencias (solo producción)
RUN npm ci --only=production && npm cache clean --force
# Copiar código fuente
COPY . .
# Build Next.js
RUN npm run build
# ============================================================
# STAGE 3: Runtime (Python + Node.js)
# ============================================================
FROM python:3.11-slim-bullseye as runtime
WORKDIR /app
# Metadatos
LABEL maintainer="Instituto Tecnológico Metropolitano (ITM)" \
description="LabPiPanel - Thermal Laboratory Control System" \
version="0.1.0"
# Instalar dependencias runtime del sistema
RUN apt-get update && apt-get install -y --no-install-recommends \
libusb-1.0-0 \
libusb-0.1-4 \
curl \
wget \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copiar Python packages instalados
COPY --from=backend-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=backend-builder /usr/local/bin /usr/local/bin
# Copiar Node.js runtime modules (opcional, para si necesitamos node en runtime)
COPY --from=frontend-builder /app/node_modules /app/node_modules
# Copiar Next.js build output
COPY --from=frontend-builder /app/.next /app/.next
COPY --from=frontend-builder /app/public /app/public
# Copiar aplicación Python
COPY labpipanel.py /app/
COPY config.py /app/
COPY fuente_xln.py /app/
COPY daq_usb5203.py /app/
COPY relay_controller.py /app/
COPY thermal_experiment.py /app/
# Copiar assets frontend
COPY templates/ /app/templates/
COPY static/ /app/static/
# Crear directorios para logs y resultados
RUN mkdir -p /app/logs /app/results && \
chmod -R 755 /app/logs /app/results
# Variables de entorno por defecto
ENV FLASK_HOST=0.0.0.0 \
FLASK_PORT=5000 \
FLASK_DEBUG=False \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/usr/local/bin:${PATH}"
# Crear usuario no-root (mejorar seguridad)
RUN useradd -m -u 1000 labpipanel && \
chown -R labpipanel:labpipanel /app
USER labpipanel
# Health check (verifica que API responde)
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${FLASK_PORT}/api/status || exit 1
# Exponer puertos
EXPOSE 5000 3000 9090
# Volúmenes
VOLUME ["/app/logs", "/app/results"]
# Entrypoint: ejecutar servidor Flask
CMD ["python", "-u", "labpipanel.py"]
# ============================================================
# NOTAS
# ============================================================
#
# Build:
# docker build -t labpipanel:latest .
#
# Build multi-plataforma (ARM64 + x86_64):
# docker buildx build --platform linux/arm64,linux/amd64 -t labpipanel:latest .
#
# Run:
# docker run -d \
# -p 5000:5000 \
# -p 3000:3000 \
# -e XLN_HOST=192.168.1.100 \
# --device /dev/bus/usb \
# --device /dev/mem \
# --volume /sys/class/gpio:/sys/class/gpio:rw \
# --privileged \
# labpipanel:latest
#
# En Raspberry Pi (con hardware real):
# docker run -d \
# --name labpipanel \
# --restart unless-stopped \
# -p 5000:5000 \
# -p 3000:3000 \
# --device /dev/bus/usb \
# --device /dev/mem \
# --device /dev/gpiomem \
# --volume /sys/class/gpio:/sys/class/gpio:rw \
# --volume $(pwd)/logs:/app/logs \
# --volume $(pwd)/results:/app/results \
# --privileged \
# -e XLN_HOST=192.168.1.100 \
# labpipanel:latest
#