diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a00db68 --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index ba461b3..9d838f0 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e96e06 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..d51d6fd --- /dev/null +++ b/start.sh @@ -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 \ No newline at end of file