Simplificar Docker a imagen única y actualizar workflow CI/CD
This commit is contained in:
18
.dockerignore
Normal file
18
.dockerignore
Normal 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
|
||||||
@@ -5,26 +5,8 @@ on:
|
|||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
#───────────────── filtra qué dirs cambiaron ─────────────────
|
#───────────────── build & push imagen única ─────────────────
|
||||||
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:
|
build:
|
||||||
needs: filter
|
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
env:
|
env:
|
||||||
REG: gitea.nucleoriofrio.com/nucleo000
|
REG: gitea.nucleoriofrio.com/nucleo000
|
||||||
@@ -37,26 +19,11 @@ jobs:
|
|||||||
username: nucleo000
|
username: nucleo000
|
||||||
password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
|
password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
|
||||||
|
|
||||||
- name: Build+push server
|
- name: Build and push snatchgame
|
||||||
if: needs.filter.outputs.server == 'true'
|
|
||||||
run: |
|
run: |
|
||||||
docker build -f server/Dockerfile -t $REG/snatchgame-server:${{ github.sha }} -t $REG/snatchgame-server:latest server
|
docker build -t $REG/snatchgame:${{ github.sha }} -t $REG/snatchgame:latest .
|
||||||
docker push $REG/snatchgame-server:${{ github.sha }}
|
docker push $REG/snatchgame:${{ github.sha }}
|
||||||
docker push $REG/snatchgame-server:latest
|
docker push $REG/snatchgame: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
|
|
||||||
|
|
||||||
#───────────────── deploy ─────────────────
|
#───────────────── deploy ─────────────────
|
||||||
deploy:
|
deploy:
|
||||||
@@ -65,15 +32,23 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
REG: gitea.nucleoriofrio.com/nucleo000
|
REG: gitea.nucleoriofrio.com/nucleo000
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Login to registry
|
- name: Login to registry
|
||||||
run: docker login gitea.nucleoriofrio.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
|
run: docker login gitea.nucleoriofrio.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d
|
||||||
|
|
||||||
- name: Pull fresh images used in compose
|
- name: Stop existing container
|
||||||
run: docker compose pull --ignore-pull-failures
|
run: docker stop snatchgame || true
|
||||||
|
|
||||||
- name: Clean up stack
|
- name: Remove existing container
|
||||||
run: docker compose --project-name snatchgame down
|
run: docker rm snatchgame || true
|
||||||
|
|
||||||
- name: Update stack
|
- name: Pull latest image
|
||||||
run: docker compose --project-name snatchgame up -d --remove-orphans --wait
|
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
33
Dockerfile
Normal 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
15
start.sh
Normal 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
|
||||||
Reference in New Issue
Block a user