From bd8fb004d00104408144a83008748eac1620abd5 Mon Sep 17 00:00:00 2001 From: aladecom Date: Wed, 8 Oct 2025 10:49:49 +0200 Subject: [PATCH 01/10] feat: add docker support --- docker/Dockerfile.backend | 13 +++++++++++++ docker/Dockerfile.frontend | 23 +++++++++++++++++++++++ docker/docker-compose.yml | 15 +++++++++++++++ docker/nginx.conf | 15 +++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 docker/Dockerfile.backend create mode 100644 docker/Dockerfile.frontend create mode 100644 docker/docker-compose.yml create mode 100644 docker/nginx.conf diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend new file mode 100644 index 0000000..6745d0e --- /dev/null +++ b/docker/Dockerfile.backend @@ -0,0 +1,13 @@ +FROM node:20-alpine + +WORKDIR /app + +COPY package.json package-lock.json ./ + +RUN npm install --only=production + +COPY server ./ + +EXPOSE 3005 + +CMD ["/usr/bin/env", "APP_PORT=3005", "node", "index.js"] \ No newline at end of file diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend new file mode 100644 index 0000000..5dd6ed5 --- /dev/null +++ b/docker/Dockerfile.frontend @@ -0,0 +1,23 @@ +FROM node:20-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +COPY craco.config.js ./ + +RUN npm install --silent + +COPY . . + +RUN npm run build + + +FROM nginx:alpine + +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf + +COPY --from=build /app/build /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..0be7f2c --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,15 @@ +services: + + backend: + image: laligaapp-backend:latest + restart: unless-stopped + networks: + - internal + + frontend: + image: laligaapp-frontend:latest + restart: unless-stopped + networks: + - internal + ports: + - 80:80 \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..2361b0b --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + location /api/ { + proxy_pass http://backend:3005; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + location / { + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file From e3a08a33b394a65e6097984b77e2962283384097 Mon Sep 17 00:00:00 2001 From: aladecom <54271797+aladecom@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:00:13 +0200 Subject: [PATCH 02/10] Apply suggestion from @Externoak Me parece bien. Habia pasado un poco por alto el puerto porque uso traefik Co-authored-by: D. <17742637+Externoak@users.noreply.github.com> --- docker/docker-compose.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 0be7f2c..3135c77 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,15 +1,34 @@ services: - backend: + build: + context: . + dockerfile: docker/Dockerfile.backend image: laligaapp-backend:latest restart: unless-stopped networks: - internal - + environment: + - APP_PORT=3005 + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3005/health"] + interval: 30s + timeout: 3s + retries: 3 + frontend: + build: + context: . + dockerfile: docker/Dockerfile.frontend image: laligaapp-frontend:latest restart: unless-stopped + depends_on: + backend: + condition: service_healthy networks: - internal ports: - - 80:80 \ No newline at end of file + - "8080:80" + +networks: + internal: + driver: bridge \ No newline at end of file From e43229575f0512bbdaf3762ee32b0f64832604f0 Mon Sep 17 00:00:00 2001 From: aladecom <54271797+aladecom@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:14:13 +0200 Subject: [PATCH 03/10] Apply suggestion from @Externoak Co-authored-by: D. <17742637+Externoak@users.noreply.github.com> --- docker/Dockerfile.backend | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index 6745d0e..a81bdca 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -4,7 +4,9 @@ WORKDIR /app COPY package.json package-lock.json ./ -RUN npm install --only=production +RUN npm ci --only=production + +COPY server ./server COPY server ./ From 8783fcbb68d4aadeec0fd226f24b98f2ad726e69 Mon Sep 17 00:00:00 2001 From: aladecom <54271797+aladecom@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:14:31 +0200 Subject: [PATCH 04/10] Apply suggestion from @Externoak Co-authored-by: D. <17742637+Externoak@users.noreply.github.com> --- docker/Dockerfile.backend | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index a81bdca..676860b 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -8,8 +8,18 @@ RUN npm ci --only=production COPY server ./server -COPY server ./ +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app +USER nodejs + +ENV APP_PORT=3005 EXPOSE 3005 +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ + CMD wget --no-verbose --tries=1 --spider http://localhost:3005/health || exit 1 + +CMD ["node", "server/index.js"] + CMD ["/usr/bin/env", "APP_PORT=3005", "node", "index.js"] \ No newline at end of file From 4e424032aeecaa1970ebfccd67f4ec166dc1f99c Mon Sep 17 00:00:00 2001 From: aladecom <54271797+aladecom@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:15:54 +0200 Subject: [PATCH 05/10] Apply suggestion from @Externoak Co-authored-by: D. <17742637+Externoak@users.noreply.github.com> --- docker/nginx.conf | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docker/nginx.conf b/docker/nginx.conf index 2361b0b..290090a 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,7 +1,16 @@ server { - listen 80; - root /usr/share/nginx/html; - index index.html; + listen 80; + root /usr/share/nginx/html; + index index.html; + + # Security headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-XSS-Protection "1; mode=block" always; + + # Gzip compression + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; location /api/ { proxy_pass http://backend:3005; From 53ef2443739eab0d678c255de3426fbe095f4ce4 Mon Sep 17 00:00:00 2001 From: aladecom <54271797+aladecom@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:16:00 +0200 Subject: [PATCH 06/10] Apply suggestion from @Externoak Co-authored-by: D. <17742637+Externoak@users.noreply.github.com> --- docker/nginx.conf | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker/nginx.conf b/docker/nginx.conf index 290090a..bb41a97 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -12,11 +12,13 @@ server { gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; - location /api/ { - proxy_pass http://backend:3005; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - } + location /api/ { + proxy_pass http://backend:3005; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } location / { try_files $uri $uri/ /index.html; From f6b3652d71dc1e7f6cd7d2bc3f23f67a9bd2c0cd Mon Sep 17 00:00:00 2001 From: aladecom Date: Fri, 17 Oct 2025 16:49:38 +0200 Subject: [PATCH 07/10] fix: Adaptados cambios sugeridos Con algunas modificaciones para que funciona despues de haberlo testeado --- .dockerignore | 17 ++++++++++ README.md | 34 +++++++++++++++++++ .../docker-compose.yml => docker-compose.yml | 6 ++-- docker/Dockerfile.backend | 4 +-- docker/Dockerfile.frontend | 2 +- docker/nginx.conf => nginx.conf | 0 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .dockerignore rename docker/docker-compose.yml => docker-compose.yml (84%) rename docker/nginx.conf => nginx.conf (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..530e852 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +node_modules +npm-debug.log +.npm +.git +.gitignore +README.md +.env +.env.local +docker-compose*.yml +Dockerfile* +docker/ +dist +build +coverage +.vscode +.idea +*.log \ No newline at end of file diff --git a/README.md b/README.md index 0d05992..827a5c5 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,40 @@ Imagen del menu principal: ¡Listo! No requiere instalación adicional. +## Docker + +### Prerequisitos +- Docker +- Docker Compose + +### Inicio rápido + +```bash +docker-compose up --build +``` + +Acceso + +- Frontend: http://localhost:8080 +- Backend API: http://localhost:8080/api + +Build manual de imágenes + +```bash +docker build -t laligaapp-backend:latest -f docker/Dockerfile.backend . +docker build -t laligaapp-frontend:latest -f docker/Dockerfile.frontend . +``` + +Variables de entorno + +Backend: +- APP_PORT - Puerto del servidor (default: 3005) + +Sobre tu comentario de reducir el tamaño del backend: con npm ci --only=production y el usuario no-root ya debería estar bastante optimizado. Si quieres ir más allá podrías usar una imagen distroless pero es opcional. + +Prueba los cambios a ver si funcionan bien y avísame si tienes dudas sobre algún punto. + + ## 🔐 Privacidad y Seguridad **🛡️ Tus datos están completamente seguros:** diff --git a/docker/docker-compose.yml b/docker-compose.yml similarity index 84% rename from docker/docker-compose.yml rename to docker-compose.yml index 3135c77..ba108d5 100644 --- a/docker/docker-compose.yml +++ b/docker-compose.yml @@ -3,14 +3,14 @@ services: build: context: . dockerfile: docker/Dockerfile.backend - image: laligaapp-backend:latest + image: laligaapp-backend:test restart: unless-stopped networks: - internal environment: - APP_PORT=3005 healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3005/health"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3005/health"] interval: 30s timeout: 3s retries: 3 @@ -19,7 +19,7 @@ services: build: context: . dockerfile: docker/Dockerfile.frontend - image: laligaapp-frontend:latest + image: laligaapp-frontend:test restart: unless-stopped depends_on: backend: diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index 676860b..2cb1a18 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -20,6 +20,4 @@ EXPOSE 3005 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ CMD wget --no-verbose --tries=1 --spider http://localhost:3005/health || exit 1 -CMD ["node", "server/index.js"] - -CMD ["/usr/bin/env", "APP_PORT=3005", "node", "index.js"] \ No newline at end of file +CMD ["node", "server/index.js"] \ No newline at end of file diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend index 5dd6ed5..27c6490 100644 --- a/docker/Dockerfile.frontend +++ b/docker/Dockerfile.frontend @@ -14,7 +14,7 @@ RUN npm run build FROM nginx:alpine -COPY docker/nginx.conf /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build /app/build /usr/share/nginx/html diff --git a/docker/nginx.conf b/nginx.conf similarity index 100% rename from docker/nginx.conf rename to nginx.conf From f803364580dc3ddd980f65521f285a59c828790d Mon Sep 17 00:00:00 2001 From: aladecom Date: Fri, 17 Oct 2025 16:55:08 +0200 Subject: [PATCH 08/10] fix: version de la imagen de test a latest --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ba108d5..eaeee02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: build: context: . dockerfile: docker/Dockerfile.backend - image: laligaapp-backend:test + image: laligaapp-backend:latest restart: unless-stopped networks: - internal @@ -19,7 +19,7 @@ services: build: context: . dockerfile: docker/Dockerfile.frontend - image: laligaapp-frontend:test + image: laligaapp-frontend:latest restart: unless-stopped depends_on: backend: From e95dcbd64c7be141ba8276a91d18c9c8e42979c5 Mon Sep 17 00:00:00 2001 From: "D." <17742637+Externoak@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:43:59 +0100 Subject: [PATCH 09/10] Moved Docker in Readme.md to a more correct placement --- README.md | 67 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 827a5c5..32585db 100644 --- a/README.md +++ b/README.md @@ -40,40 +40,6 @@ Imagen del menu principal: ¡Listo! No requiere instalación adicional. -## Docker - -### Prerequisitos -- Docker -- Docker Compose - -### Inicio rápido - -```bash -docker-compose up --build -``` - -Acceso - -- Frontend: http://localhost:8080 -- Backend API: http://localhost:8080/api - -Build manual de imágenes - -```bash -docker build -t laligaapp-backend:latest -f docker/Dockerfile.backend . -docker build -t laligaapp-frontend:latest -f docker/Dockerfile.frontend . -``` - -Variables de entorno - -Backend: -- APP_PORT - Puerto del servidor (default: 3005) - -Sobre tu comentario de reducir el tamaño del backend: con npm ci --only=production y el usuario no-root ya debería estar bastante optimizado. Si quieres ir más allá podrías usar una imagen distroless pero es opcional. - -Prueba los cambios a ver si funcionan bien y avísame si tienes dudas sobre algún punto. - - ## 🔐 Privacidad y Seguridad **🛡️ Tus datos están completamente seguros:** @@ -161,6 +127,39 @@ npm run electron # Build y ejecutar npm run build:electron # Empaquetar para distribución ``` +## Docker + +### Prerequisitos +- Docker +- Docker Compose + +### Inicio rápido + +```bash +docker-compose up --build +``` + +Acceso + +- Frontend: http://localhost:8080 +- Backend API: http://localhost:8080/api + +Build manual de imágenes + +```bash +docker build -t laligaapp-backend:latest -f docker/Dockerfile.backend . +docker build -t laligaapp-frontend:latest -f docker/Dockerfile.frontend . +``` + +Variables de entorno + +Backend: +- APP_PORT - Puerto del servidor (default: 3005) + +Sobre tu comentario de reducir el tamaño del backend: con npm ci --only=production y el usuario no-root ya debería estar bastante optimizado. Si quieres ir más allá podrías usar una imagen distroless pero es opcional. + +Prueba los cambios a ver si funcionan bien y avísame si tienes dudas sobre algún punto. + ## 🏗️ Estructura del proyecto ``` From 6d1fcb6b16c052ee433aa2e87eef15c56d70cde1 Mon Sep 17 00:00:00 2001 From: aladecom Date: Wed, 29 Oct 2025 18:31:09 +0100 Subject: [PATCH 10/10] fix: healthcheck para el backend --- docker-compose.yml | 2 +- docker/Dockerfile.backend | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index eaeee02..8d20c73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: environment: - APP_PORT=3005 healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3005/health"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://0.0.0.0:3005/health"] interval: 30s timeout: 3s retries: 3 diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index 2cb1a18..5ed17f4 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -18,6 +18,6 @@ ENV APP_PORT=3005 EXPOSE 3005 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ - CMD wget --no-verbose --tries=1 --spider http://localhost:3005/health || exit 1 + CMD wget --no-verbose --tries=1 --spider http://0.0.0.0:3005/health || exit 1 CMD ["node", "server/index.js"] \ No newline at end of file