Simplificar Docker a imagen única y actualizar workflow CI/CD
Some checks failed
build-and-deploy / build (push) Failing after 47s
build-and-deploy / deploy (push) Has been skipped

This commit is contained in:
2025-08-15 12:18:42 -06:00
parent 3385636129
commit 84aef0774d
4 changed files with 86 additions and 45 deletions

18
.dockerignore Normal file
View File

@@ -0,0 +1,18 @@
node_modules
*/node_modules
npm-debug.log
.git
.gitignore
*.log
.env
.env.local
.DS_Store
dist
*/dist
.vscode
.idea
*.md
*.mmd
*.pdf
*.png
.gitea

View File

@@ -5,26 +5,8 @@ on:
branches: [ main ]
jobs:
#───────────────── filtra qué dirs cambiaron ─────────────────
filter:
runs-on: docker
outputs:
server: ${{ steps.paths.outputs.server }}
client: ${{ steps.paths.outputs.client }}
admin: ${{ steps.paths.outputs.admin }}
steps:
- uses: actions/checkout@v3
- id: paths
uses: dorny/paths-filter@v3
with:
filters: |
server: "server/**"
client: "client/**"
admin: "admin/**"
#───────────────── build & push ─────────────────
#───────────────── build & push imagen única ─────────────────
build:
needs: filter
runs-on: docker
env:
REG: gitea.nucleoriofrio.com/nucleo000
@@ -37,26 +19,11 @@ jobs:
username: nucleo000
password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
- name: Build+push server
if: needs.filter.outputs.server == 'true'
- name: Build and push snatchgame
run: |
docker build -f server/Dockerfile -t $REG/snatchgame-server:${{ github.sha }} -t $REG/snatchgame-server:latest server
docker push $REG/snatchgame-server:${{ github.sha }}
docker push $REG/snatchgame-server:latest
- name: Build+push client
if: needs.filter.outputs.client == 'true'
run: |
docker build -f client/Dockerfile -t $REG/snatchgame-client:${{ github.sha }} -t $REG/snatchgame-client:latest client
docker push $REG/snatchgame-client:${{ github.sha }}
docker push $REG/snatchgame-client:latest
- name: Build+push admin
if: needs.filter.outputs.admin == 'true'
run: |
docker build -f admin/Dockerfile -t $REG/snatchgame-admin:${{ github.sha }} -t $REG/snatchgame-admin:latest admin
docker push $REG/snatchgame-admin:${{ github.sha }}
docker push $REG/snatchgame-admin:latest
docker build -t $REG/snatchgame:${{ github.sha }} -t $REG/snatchgame:latest .
docker push $REG/snatchgame:${{ github.sha }}
docker push $REG/snatchgame:latest
#───────────────── deploy ─────────────────
deploy:
@@ -65,15 +32,23 @@ jobs:
env:
REG: gitea.nucleoriofrio.com/nucleo000
steps:
- uses: actions/checkout@v3
- name: Login to registry
run: docker login gitea.nucleoriofrio.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
- name: Pull fresh images used in compose
run: docker compose pull --ignore-pull-failures
- name: Stop existing container
run: docker stop snatchgame || true
- name: Clean up stack
run: docker compose --project-name snatchgame down
- name: Remove existing container
run: docker rm snatchgame || true
- name: Update stack
run: docker compose --project-name snatchgame up -d --remove-orphans --wait
- name: Pull latest image
run: docker pull $REG/snatchgame:latest
- name: Run new container
run: |
docker run -d \
--name snatchgame \
--restart unless-stopped \
-p 3000:3000 \
-p 2567:2567 \
$REG/snatchgame:latest

33
Dockerfile Normal file
View File

@@ -0,0 +1,33 @@
FROM node:18-alpine
WORKDIR /app
# Copiar archivos de configuración
COPY package*.json ./
COPY server/package*.json ./server/
COPY client/package*.json ./client/
# Instalar dependencias
RUN npm install
RUN cd server && npm install
RUN cd client && npm install
# Copiar código fuente
COPY . .
# Compilar servidor y cliente
RUN cd server && npm run build
RUN cd client && npm run build
# Instalar serve para servir archivos estáticos
RUN npm install -g serve
# Script de inicio
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh
# Exponer puertos
EXPOSE 3000 2567
# Ejecutar ambos servicios
CMD ["/app/start.sh"]

15
start.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Iniciar el servidor Colyseus en background
echo "Starting Colyseus server..."
cd /app/server && node dist/index.js &
# Esperar un momento para que el servidor inicie
sleep 2
# Servir el cliente compilado
echo "Starting client server..."
cd /app/client && serve -s dist -l 3000 &
# Mantener el contenedor corriendo
wait