From 46e746940d1061aebf34df553c65d06577ea846d Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:06:55 -0600 Subject: [PATCH 01/10] Agregar workflow de Gitea Actions para CI/CD --- .gitea/workflows/build-and-deploy.yml | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .gitea/workflows/build-and-deploy.yml diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml new file mode 100644 index 0000000..3626815 --- /dev/null +++ b/.gitea/workflows/build-and-deploy.yml @@ -0,0 +1,79 @@ +name: build-and-deploy + +on: + push: + 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: + needs: filter + runs-on: docker + env: + REG: gitea.interno.com/nucleo000 + steps: + - uses: actions/checkout@v3 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: gitea.interno.com + username: nucleo000 + password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d + + - name: Build+push server + if: needs.filter.outputs.server == 'true' + 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 + +#───────────────── deploy ───────────────── + deploy: + needs: build + runs-on: docker + env: + REG: gitea.interno.com/nucleo000 + steps: + - uses: actions/checkout@v3 + - name: Login to registry + run: docker login gitea.interno.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d + + - name: Pull fresh images used in compose + run: docker compose pull --ignore-pull-failures + + - name: Clean up stack + run: docker compose --project-name snatchgame down + + - name: Update stack + run: docker compose --project-name snatchgame up -d --remove-orphans --wait \ No newline at end of file From 338563612953cb1b0b6baad21674d27d62cf533c Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:09:03 -0600 Subject: [PATCH 02/10] cambiado el gitea --- .gitea/workflows/build-and-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 3626815..ba461b3 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -27,13 +27,13 @@ jobs: needs: filter runs-on: docker env: - REG: gitea.interno.com/nucleo000 + REG: gitea.nucleoriofrio.com/nucleo000 steps: - uses: actions/checkout@v3 - uses: docker/setup-buildx-action@v2 - uses: docker/login-action@v2 with: - registry: gitea.interno.com + registry: gitea.nucleoriofrio.com username: nucleo000 password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d @@ -63,11 +63,11 @@ jobs: needs: build runs-on: docker env: - REG: gitea.interno.com/nucleo000 + REG: gitea.nucleoriofrio.com/nucleo000 steps: - uses: actions/checkout@v3 - name: Login to registry - run: docker login gitea.interno.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d + run: docker login gitea.nucleoriofrio.com -u nucleo000 -p 7bc7b2fcd283bd6a251bef3ede368b7f897c919d - name: Pull fresh images used in compose run: docker compose pull --ignore-pull-failures From 84aef0774dbbd322aa0cd69a4fdfec66de1dc19a Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:18:42 -0600 Subject: [PATCH 03/10] =?UTF-8?q?Simplificar=20Docker=20a=20imagen=20?= =?UTF-8?q?=C3=BAnica=20y=20actualizar=20workflow=20CI/CD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 18 ++++++++ .gitea/workflows/build-and-deploy.yml | 65 +++++++++------------------ Dockerfile | 33 ++++++++++++++ start.sh | 15 +++++++ 4 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 start.sh 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 From 84fa2b86d37ab033035c5400aa001f295a97b641 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:22:46 -0600 Subject: [PATCH 04/10] Corregir errores de TypeScript y optimizar build para Docker --- Dockerfile | 2 +- client/package-lock.json | 26 ++++++++++++++++++++++++++ client/package.json | 8 +++++--- client/src/components/RoomsTable.vue | 24 ++++++++++++------------ client/src/services/colyseus.ts | 6 +++--- client/src/services/db.ts | 2 +- client/tsconfig.prod.json | 10 ++++++++++ client/vite.config.d.ts | 2 ++ 8 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 client/tsconfig.prod.json create mode 100644 client/vite.config.d.ts diff --git a/Dockerfile b/Dockerfile index 5e96e06..8881818 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ COPY . . # Compilar servidor y cliente RUN cd server && npm run build -RUN cd client && npm run build +RUN cd client && npx vite build # Instalar serve para servir archivos estáticos RUN npm install -g serve diff --git a/client/package-lock.json b/client/package-lock.json index 3b5f26f..cbc20b1 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -14,6 +14,8 @@ "vue-router": "latest" }, "devDependencies": { + "@types/lokijs": "^1.5.14", + "@types/node": "^24.3.0", "@vitejs/plugin-vue": "latest", "@vue/tsconfig": "latest", "typescript": "latest", @@ -915,6 +917,23 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lokijs": { + "version": "1.5.14", + "resolved": "https://registry.npmjs.org/@types/lokijs/-/lokijs-1.5.14.tgz", + "integrity": "sha512-4Fic47BX3Qxr8pd12KT6/T1XWU8dOlJBIp1jGoMbaDbiEvdv50rAii+B3z1b/J2pvMywcVP+DBPGP5/lgLOKGA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "24.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.3.0.tgz", + "integrity": "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.10.0" + } + }, "node_modules/@vitejs/plugin-vue": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.1.tgz", @@ -1488,6 +1507,13 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", + "integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==", + "dev": true, + "license": "MIT" + }, "node_modules/vite": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/vite/-/vite-7.0.6.tgz", diff --git a/client/package.json b/client/package.json index ca0ef51..17c5aac 100644 --- a/client/package.json +++ b/client/package.json @@ -9,12 +9,14 @@ "preview": "vite preview" }, "dependencies": { - "vue": "latest", - "vue-router": "latest", "colyseus.js": "latest", - "lokijs": "^1.5.12" + "lokijs": "^1.5.12", + "vue": "latest", + "vue-router": "latest" }, "devDependencies": { + "@types/lokijs": "^1.5.14", + "@types/node": "^24.3.0", "@vitejs/plugin-vue": "latest", "@vue/tsconfig": "latest", "typescript": "latest", diff --git a/client/src/components/RoomsTable.vue b/client/src/components/RoomsTable.vue index 8ecdcb5..dc6d296 100644 --- a/client/src/components/RoomsTable.vue +++ b/client/src/components/RoomsTable.vue @@ -51,15 +51,15 @@
- {{ getRoomDetails(room.roomId).players[0].name }} + {{ getRoomDetails(room.roomId)?.players?.[0]?.name }}
- 🦃 - 🌽 - 😳 + 🦃 + 🌽 + 😳
-
@@ -67,15 +67,15 @@
- {{ getRoomDetails(room.roomId).players[1].name }} + {{ getRoomDetails(room.roomId)?.players?.[1]?.name }}
- 🦃 - 🌽 - 😳 + 🦃 + 🌽 + 😳
-
diff --git a/client/src/services/colyseus.ts b/client/src/services/colyseus.ts index 299c899..5ec9edd 100644 --- a/client/src/services/colyseus.ts +++ b/client/src/services/colyseus.ts @@ -161,11 +161,11 @@ class ColyseusService { }); // Ensure the room id is set - if (!gameRoom.id) { - gameRoom.id = data.roomId; + if (!(gameRoom as any).id) { + (gameRoom as any).id = data.roomId; } - console.log('Successfully joined game room:', gameRoom.id, gameRoom); + console.log('Successfully joined game room:', (gameRoom as any).id, gameRoom); console.log('Setting gameRoom.value...'); this.gameRoom.value = gameRoom; this.currentRoom = gameRoom; diff --git a/client/src/services/db.ts b/client/src/services/db.ts index 026d5c4..40fcaf1 100644 --- a/client/src/services/db.ts +++ b/client/src/services/db.ts @@ -1,4 +1,4 @@ -import Loki from "lokijs"; +import Loki, { Collection } from "lokijs"; export interface LocalPlayerDoc { id: string; // fixed id for local profile diff --git a/client/tsconfig.prod.json b/client/tsconfig.prod.json new file mode 100644 index 0000000..9bd137f --- /dev/null +++ b/client/tsconfig.prod.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noUnusedLocals": false, + "noUnusedParameters": false, + "noImplicitAny": false, + "strict": false, + "skipLibCheck": true + } +} \ No newline at end of file diff --git a/client/vite.config.d.ts b/client/vite.config.d.ts new file mode 100644 index 0000000..340562a --- /dev/null +++ b/client/vite.config.d.ts @@ -0,0 +1,2 @@ +declare const _default: import("vite").UserConfig; +export default _default; From 05e6467158ef4aae82f74b79073c09c5dfd2ae03 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:24:45 -0600 Subject: [PATCH 05/10] Usar node:lts para resolver problema de crypto en build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8881818..666cba2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine +FROM node:lts WORKDIR /app From 7adc342ffa0454d8af57c3ed5d6bac30d2142409 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:28:20 -0600 Subject: [PATCH 06/10] Usar node:lts-slim y configurar puertos 8089:8090 con red principal --- .gitea/workflows/build-and-deploy.yml | 5 +++-- Dockerfile | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 9d838f0..024103a 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -49,6 +49,7 @@ jobs: docker run -d \ --name snatchgame \ --restart unless-stopped \ - -p 3000:3000 \ - -p 2567:2567 \ + --network principal \ + -p 8089:3000 \ + -p 8090:2567 \ $REG/snatchgame:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 666cba2..534575c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts +FROM node:lts-slim WORKDIR /app From 08f398c9e10eb07a3820dbd2dd32a36703270aac Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:36:59 -0600 Subject: [PATCH 07/10] Corregir ruta del servidor compilado en start.sh --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index d51d6fd..2cd1224 100644 --- a/start.sh +++ b/start.sh @@ -2,7 +2,7 @@ # Iniciar el servidor Colyseus en background echo "Starting Colyseus server..." -cd /app/server && node dist/index.js & +cd /app/server && node dist/server/src/index.js & # Esperar un momento para que el servidor inicie sleep 2 From 48f560d4e1e426392e69de796218abf27d3fc2b7 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 12:41:11 -0600 Subject: [PATCH 08/10] Remover mapeo de puertos, usar solo red principal para nginx --- .gitea/workflows/build-and-deploy.yml | 2 -- start.sh | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 024103a..46d7d70 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -50,6 +50,4 @@ jobs: --name snatchgame \ --restart unless-stopped \ --network principal \ - -p 8089:3000 \ - -p 8090:2567 \ $REG/snatchgame:latest \ No newline at end of file diff --git a/start.sh b/start.sh index 2cd1224..a49580a 100644 --- a/start.sh +++ b/start.sh @@ -1,15 +1,15 @@ #!/bin/sh -# Iniciar el servidor Colyseus en background +# Iniciar el servidor Colyseus en background (puerto 2567) echo "Starting Colyseus server..." -cd /app/server && node dist/server/src/index.js & +cd /app/server && PORT=2567 node dist/server/src/index.js & # Esperar un momento para que el servidor inicie sleep 2 -# Servir el cliente compilado +# Servir el cliente compilado (puerto 3000) echo "Starting client server..." -cd /app/client && serve -s dist -l 3000 & +cd /app/client && serve -s dist -p 3000 & # Mantener el contenedor corriendo wait \ No newline at end of file From 59f60328e2730f3405a155fcb302f3a30fb22d36 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 13:41:12 -0600 Subject: [PATCH 09/10] Configurar URLs para usar rutas de nginx sin puertos --- client/.env.production | 2 ++ client/src/services/colyseus.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 client/.env.production diff --git a/client/.env.production b/client/.env.production new file mode 100644 index 0000000..43310e3 --- /dev/null +++ b/client/.env.production @@ -0,0 +1,2 @@ +VITE_WS_URL=wss://snatchgame.nucleoriofrio.com/ws +VITE_API_URL=https://snatchgame.nucleoriofrio.com/api \ No newline at end of file diff --git a/client/src/services/colyseus.ts b/client/src/services/colyseus.ts index 5ec9edd..f43909c 100644 --- a/client/src/services/colyseus.ts +++ b/client/src/services/colyseus.ts @@ -37,13 +37,14 @@ class ColyseusService { constructor() { const defaultHost = typeof window !== "undefined" ? window.location.hostname : "localhost"; const defaultProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "wss" : "ws"; - const defaultPort = 3000; - const fallbackUrl = `${defaultProtocol}://${defaultHost}:${defaultPort}`; + const httpProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "https" : "http"; + + // Para producción, usar las rutas de nginx sin puerto + const fallbackUrl = `${defaultProtocol}://${defaultHost}/ws`; + const apiFallback = `${httpProtocol}://${defaultHost}/api`; + const url = import.meta.env.VITE_WS_URL || fallbackUrl; this.client = new Client(url); - - const httpProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "https" : "http"; - const apiFallback = `${httpProtocol}://${defaultHost}:${defaultPort}/api`; this.apiBase = (import.meta.env as any).VITE_API_URL || apiFallback; } From fa94330ace18baff9d07456a48c0bc62d3ab809e Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 15 Aug 2025 17:50:33 -0600 Subject: [PATCH 10/10] Organizar archivos de deployment en carpeta deploy/ --- .gitea/workflows/deploy-gcloud.yml | 47 ++++++ .gitignore.github | 14 ++ deploy/DEPLOY-GCLOUD.md | 217 +++++++++++++++++++++++++++ Dockerfile => deploy/Dockerfile | 0 deploy/NGINX-CONFIG.md | 106 +++++++++++++ deploy/README.md | 79 ++++++++++ .dockerignore => deploy/dockerignore | 0 deploy/gcloud/create-vm.sh | 61 ++++++++ deploy/gcloud/startup-script.sh | 137 +++++++++++++++++ deploy/gcloud/update-deployment.sh | 25 +++ start.sh => deploy/start.sh | 0 push-remotes.sh | 34 +++++ 12 files changed, 720 insertions(+) create mode 100644 .gitea/workflows/deploy-gcloud.yml create mode 100644 .gitignore.github create mode 100644 deploy/DEPLOY-GCLOUD.md rename Dockerfile => deploy/Dockerfile (100%) create mode 100644 deploy/NGINX-CONFIG.md create mode 100644 deploy/README.md rename .dockerignore => deploy/dockerignore (100%) create mode 100644 deploy/gcloud/create-vm.sh create mode 100644 deploy/gcloud/startup-script.sh create mode 100644 deploy/gcloud/update-deployment.sh rename start.sh => deploy/start.sh (100%) create mode 100644 push-remotes.sh diff --git a/.gitea/workflows/deploy-gcloud.yml b/.gitea/workflows/deploy-gcloud.yml new file mode 100644 index 0000000..07974db --- /dev/null +++ b/.gitea/workflows/deploy-gcloud.yml @@ -0,0 +1,47 @@ +name: deploy-to-gcloud + +on: + push: + branches: [ production ] # Solo desplegar cuando se pushee a rama production + +jobs: + build-and-deploy: + runs-on: docker + env: + REG: gitea.nucleoriofrio.com/nucleo000 + + steps: + - uses: actions/checkout@v3 + + # Build y push imagen (igual que antes) + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: gitea.nucleoriofrio.com + username: nucleo000 + password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d + + - name: Build and push snatchgame + run: | + docker build -t $REG/snatchgame:latest . + docker push $REG/snatchgame:latest + + # Deploy a Google Cloud VM + - name: Deploy to Google Cloud VM + run: | + # Instalar gcloud CLI si no está disponible + if ! command -v gcloud &> /dev/null; then + curl https://sdk.cloud.google.com | bash + exec -l $SHELL + source /root/google-cloud-sdk/path.bash.inc + fi + + # Configurar autenticación (necesitarás configurar service account) + # echo '${{ secrets.GCLOUD_SERVICE_KEY }}' | gcloud auth activate-service-account --key-file=- + # gcloud config set project tu-proyecto-gcloud + + # Ejecutar deployment en la VM + gcloud compute ssh snatchgame-vm \ + --zone=us-central1-a \ + --command="sudo /opt/deploy-snatchgame.sh" \ + || echo "Deploy failed - VM might not exist yet" \ No newline at end of file diff --git a/.gitignore.github b/.gitignore.github new file mode 100644 index 0000000..ace8f72 --- /dev/null +++ b/.gitignore.github @@ -0,0 +1,14 @@ +# Archivo .gitignore específico para GitHub +# Este archivo excluye la carpeta deploy/ para no exponer configuración de producción + +deploy/ +*.log +.env +.env.local +node_modules +*/node_modules +dist +*/dist +.DS_Store +.vscode +.idea \ No newline at end of file diff --git a/deploy/DEPLOY-GCLOUD.md b/deploy/DEPLOY-GCLOUD.md new file mode 100644 index 0000000..6e8e332 --- /dev/null +++ b/deploy/DEPLOY-GCLOUD.md @@ -0,0 +1,217 @@ +# Despliegue en Google Cloud + +Esta guía explica cómo desplegar SnatchGame en Google Cloud Platform usando una VM de Compute Engine. + +## Requisitos Previos + +1. **Cuenta de Google Cloud** con billing habilitado +2. **gcloud CLI** instalado y configurado +3. **Proyecto de Google Cloud** creado +4. **Dominio** configurado en Cloudflare + +## Paso 1: Configurar Google Cloud + +### Instalar gcloud CLI +```bash +# En tu máquina local +curl https://sdk.cloud.google.com | bash +exec -l $SHELL +gcloud init +``` + +### Configurar proyecto +```bash +# Listar proyectos disponibles +gcloud projects list + +# Configurar proyecto activo +gcloud config set project TU_PROJECT_ID + +# Habilitar APIs necesarias +gcloud services enable compute.googleapis.com +``` + +## Paso 2: Crear la VM + +### Editar configuración +Edita `deploy/gcloud/create-vm.sh` y cambia: +```bash +PROJECT_ID="tu-proyecto-gcloud" # Por tu project ID real +``` + +### Ejecutar creación +```bash +cd deploy/gcloud +chmod +x *.sh +./create-vm.sh +``` + +Esto creará: +- VM `snatchgame-vm` con Ubuntu 20.04 +- Tipo `e2-micro` (1 vCPU, 1GB RAM) +- Disco de 20GB +- Nginx configurado automáticamente +- Docker instalado +- Tu aplicación desplegada + +## Paso 3: Configurar DNS en Cloudflare + +Una vez creada la VM, obtendrás una IP externa. Configura en Cloudflare: + +``` +Type: A +Name: snatchgame +Content: IP_EXTERNA_DE_LA_VM +Proxy status: Proxied (naranja) +TTL: Auto +``` + +## Paso 4: Configurar SSL en Cloudflare + +En el dashboard de Cloudflare: + +1. **SSL/TLS → Overview** + - Encryption mode: `Flexible` o `Full` + +2. **SSL/TLS → Edge Certificates** + - Always Use HTTPS: `On` + - HTTP Strict Transport Security: `On` + +## Paso 5: Verificar Deployment + +### Verificar VM +```bash +# Conectarse a la VM +gcloud compute ssh snatchgame-vm --zone=us-central1-a + +# Verificar servicios +sudo systemctl status nginx +sudo systemctl status docker +docker ps + +# Ver logs +docker logs snatchgame +``` + +### Verificar URLs +- `http://snatchgame.nucleoriofrio.com` - Frontend +- `http://snatchgame.nucleoriofrio.com/colyseus` - Monitor + +## Paso 6: Configurar Deployment Automático (Opcional) + +### Crear Service Account +```bash +# Crear service account +gcloud iam service-accounts create gitea-deployer \ + --display-name="Gitea Deployer" + +# Asignar permisos +gcloud projects add-iam-policy-binding TU_PROJECT_ID \ + --member="serviceAccount:gitea-deployer@TU_PROJECT_ID.iam.gserviceaccount.com" \ + --role="roles/compute.instanceAdmin" + +# Crear key +gcloud iam service-accounts keys create key.json \ + --iam-account=gitea-deployer@TU_PROJECT_ID.iam.gserviceaccount.com +``` + +### Configurar secrets en Gitea +En tu repositorio de Gitea, agrega estos secrets: +- `GCLOUD_SERVICE_KEY`: Contenido del archivo `key.json` +- `GCLOUD_PROJECT_ID`: Tu project ID + +### Activar workflow +El archivo `.gitea/workflows/deploy-gcloud.yml` se ejecutará automáticamente cuando pushees a la rama `production`. + +## Actualización Manual + +Para actualizar manualmente: +```bash +cd deploy/gcloud +./update-deployment.sh +``` + +## Monitoreo y Logs + +### Ver logs de la aplicación +```bash +gcloud compute ssh snatchgame-vm --zone=us-central1-a +docker logs -f snatchgame +``` + +### Ver logs de nginx +```bash +gcloud compute ssh snatchgame-vm --zone=us-central1-a +sudo tail -f /var/log/nginx/access.log +sudo tail -f /var/log/nginx/error.log +``` + +### Monitoreo de recursos +```bash +# Conectarse a la VM +gcloud compute ssh snatchgame-vm --zone=us-central1-a + +# Ver uso de recursos +htop +docker stats +``` + +## Costos Estimados + +- **VM e2-micro**: ~$7/mes +- **Disco 20GB**: ~$0.80/mes +- **Tráfico de red**: ~$0.12/GB +- **Total estimado**: ~$8-10/mes + +## Troubleshooting + +### VM no responde +```bash +# Reiniciar VM +gcloud compute instances reset snatchgame-vm --zone=us-central1-a + +# Verificar startup script +gcloud compute ssh snatchgame-vm --zone=us-central1-a +sudo tail -f /var/log/syslog +``` + +### Aplicación no funciona +```bash +# Conectarse a VM +gcloud compute ssh snatchgame-vm --zone=us-central1-a + +# Verificar contenedor +docker ps +docker logs snatchgame + +# Redesplegar +sudo /opt/deploy-snatchgame.sh +``` + +### DNS no resuelve +- Verificar configuración en Cloudflare +- Esperar propagación DNS (puede tomar hasta 24h) +- Usar herramientas como `dig` o `nslookup` + +## Scaling y Optimización + +### Aumentar recursos de VM +```bash +# Parar VM +gcloud compute instances stop snatchgame-vm --zone=us-central1-a + +# Cambiar tipo de máquina +gcloud compute instances set-machine-type snatchgame-vm \ + --machine-type=e2-small --zone=us-central1-a + +# Iniciar VM +gcloud compute instances start snatchgame-vm --zone=us-central1-a +``` + +### Backup automático +```bash +# Crear snapshot del disco +gcloud compute disks snapshot snatchgame-vm \ + --zone=us-central1-a \ + --snapshot-names=snatchgame-backup-$(date +%Y%m%d) +``` \ No newline at end of file diff --git a/Dockerfile b/deploy/Dockerfile similarity index 100% rename from Dockerfile rename to deploy/Dockerfile diff --git a/deploy/NGINX-CONFIG.md b/deploy/NGINX-CONFIG.md new file mode 100644 index 0000000..dfd2822 --- /dev/null +++ b/deploy/NGINX-CONFIG.md @@ -0,0 +1,106 @@ +# Configuración de Nginx para SnatchGame + +Este documento explica cómo configurar Nginx Proxy Manager para que el juego SnatchGame funcione correctamente con todos sus componentes. + +## Arquitectura del Sistema + +El juego está dockerizado en un solo contenedor que ejecuta dos servicios: +- **Frontend (Vue.js)**: Puerto 3000 interno +- **Backend (Colyseus)**: Puerto 2567 interno + +El contenedor está conectado a la red `principal` de Docker sin exponer puertos al host. + +## Configuración en Nginx Proxy Manager + +### 1. Proxy Host Principal + +**Configuración básica:** +- **Domain Names:** `snatchgame.nucleoriofrio.com` +- **Forward Hostname/IP:** `snatchgame` +- **Forward Port:** `3000` +- **Cache Assets:** ON +- **Block Common Exploits:** ON +- **Websockets Support:** ON + +### 2. Custom Locations (Advanced Tab) + +#### Location: `/api` +- **Forward to:** `http://snatchgame:2567/api` +- **Websockets Support:** OFF + +#### Location: `/ws` +- **Forward to:** `http://snatchgame:2567` +- **Websockets Support:** ON + +#### Location: `/colyseus` (Opcional - Monitor) +- **Forward to:** `http://snatchgame:2567/colyseus` +- **Websockets Support:** OFF + +### 3. Custom Nginx Configuration + +Para que el dashboard SSE funcione correctamente, agregar en **Advanced → Custom Nginx Configuration:** + +```nginx +location /api/dashboard-stream { + proxy_pass http://snatchgame:2567/api/dashboard-stream; + proxy_set_header Host $http_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; + + # Headers específicos para SSE + proxy_buffering off; + proxy_cache off; + proxy_read_timeout 24h; + proxy_http_version 1.1; +} +``` + +### 4. SSL Configuration + +- **SSL Certificate:** Request new Let's Encrypt +- **Force SSL:** ON +- **HTTP/2 Support:** ON + +## Rutas Resultantes + +Una vez configurado, las siguientes rutas estarán disponibles: + +| Ruta | Destino | Propósito | +|------|---------|-----------| +| `https://snatchgame.nucleoriofrio.com/` | `snatchgame:3000` | Frontend principal (Vue.js) | +| `https://snatchgame.nucleoriofrio.com/api/*` | `snatchgame:2567/api/*` | API REST del backend | +| `https://snatchgame.nucleoriofrio.com/ws` | `snatchgame:2567` | WebSocket de Colyseus | +| `https://snatchgame.nucleoriofrio.com/api/dashboard-stream` | `snatchgame:2567/api/dashboard-stream` | Server-Sent Events para dashboard | +| `https://snatchgame.nucleoriofrio.com/colyseus` | `snatchgame:2567/colyseus` | Monitor de Colyseus | + +## Configuración del Cliente + +El cliente (frontend) está configurado para usar estas rutas automáticamente: + +- **WebSocket:** `wss://snatchgame.nucleoriofrio.com/ws` +- **API:** `https://snatchgame.nucleoriofrio.com/api` +- **SSE Dashboard:** `https://snatchgame.nucleoriofrio.com/api/dashboard-stream` + +## Problemas Comunes y Soluciones + +### Dashboard SSE no funciona +**Síntoma:** Error "MIME type text/html instead of text/event-stream" +**Solución:** Verificar que la configuración custom nginx para `/api/dashboard-stream` esté presente con `proxy_buffering off` + +### WebSocket no conecta +**Síntoma:** Error de conexión WebSocket +**Solución:** Verificar que "Websockets Support" esté habilitado en la location `/ws` + +### API calls fallan +**Síntoma:** Errores 404 o 502 en calls de API +**Solución:** Verificar que la location `/api` esté configurada correctamente apuntando a `snatchgame:2567/api` + +## Despliegue Automático + +El sistema utiliza Gitea Actions para CI/CD: +1. Build de imagen Docker única +2. Deploy automático en contenedor `snatchgame` en red `principal` +3. Nginx proxy maneja el routing automáticamente + +No se requiere reiniciar nginx tras deploys, solo el contenedor se actualiza. \ No newline at end of file diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..b1248af --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,79 @@ +# Deployment de SnatchGame + +Esta carpeta contiene todos los archivos y documentación necesarios para desplegar SnatchGame en diferentes entornos. + +## 📁 Estructura de archivos + +``` +deploy/ +├── Dockerfile # Imagen Docker de la aplicación completa +├── start.sh # Script de inicio para el contenedor +├── dockerignore # Archivos a ignorar en build (renombrar a .dockerignore) +├── NGINX-CONFIG.md # Configuración de Nginx Proxy Manager +├── DEPLOY-GCLOUD.md # Guía de despliegue en Google Cloud +└── gcloud/ # Scripts específicos para Google Cloud + ├── create-vm.sh # Script para crear la VM + ├── startup-script.sh # Script de inicio de la VM + └── update-deployment.sh # Script para actualizar deployment +``` + +## 🚀 Despliegue rápido + +### Opción 1: Docker local +```bash +cd deploy +cp dockerignore .dockerignore +docker build -t snatchgame . +docker run -p 3000:3000 -p 2567:2567 snatchgame +``` + +### Opción 2: Google Cloud VM +Ver [DEPLOY-GCLOUD.md](./DEPLOY-GCLOUD.md) para instrucciones detalladas. + +### Opción 3: Con Nginx Proxy Manager +Ver [NGINX-CONFIG.md](./NGINX-CONFIG.md) para configuración de proxy reverso. + +## 🔧 Configuración de Docker + +### Build de la imagen +```bash +# Desde la raíz del proyecto +docker build -f deploy/Dockerfile -t josedario87/snatchgame:latest . + +# O desde la carpeta deploy +cd deploy +cp dockerignore .dockerignore +docker build -t josedario87/snatchgame:latest .. +``` + +### Push a DockerHub +```bash +docker login +docker push josedario87/snatchgame:latest +``` + +## 📊 Puertos utilizados + +- **3000**: Frontend (Vue.js) +- **2567**: Backend (Colyseus WebSocket y API) + +## 🌐 URLs del juego + +- Frontend: `http://localhost:3000` +- API: `http://localhost:2567/api` +- WebSocket: `ws://localhost:2567/ws` +- Monitor: `http://localhost:2567/colyseus` + +## 🔄 Actualización del deployment + +1. Hacer cambios en el código +2. Reconstruir imagen: `docker build -t josedario87/snatchgame:latest .` +3. Push a DockerHub: `docker push josedario87/snatchgame:latest` +4. En el servidor: `docker pull josedario87/snatchgame:latest && docker restart snatchgame` + +## 📝 Notas importantes + +- El archivo `dockerignore` debe renombrarse a `.dockerignore` cuando se use +- Los scripts de `gcloud/` requieren configuración específica del proyecto +- La imagen Docker incluye tanto frontend como backend en un solo contenedor +- Se recomienda usar variables de entorno para configuración sensible \ No newline at end of file diff --git a/.dockerignore b/deploy/dockerignore similarity index 100% rename from .dockerignore rename to deploy/dockerignore diff --git a/deploy/gcloud/create-vm.sh b/deploy/gcloud/create-vm.sh new file mode 100644 index 0000000..746826a --- /dev/null +++ b/deploy/gcloud/create-vm.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Script para crear la VM en Google Cloud +# Ejecutar este script desde tu máquina local con gcloud CLI instalado + +PROJECT_ID="tu-proyecto-gcloud" # Cambiar por tu project ID +ZONE="us-central1-a" +VM_NAME="snatchgame-vm" +MACHINE_TYPE="e2-micro" +IMAGE_FAMILY="ubuntu-2004-lts" +IMAGE_PROJECT="ubuntu-os-cloud" + +echo "Creando VM para SnatchGame en Google Cloud..." + +# Crear la VM +gcloud compute instances create $VM_NAME \ + --project=$PROJECT_ID \ + --zone=$ZONE \ + --machine-type=$MACHINE_TYPE \ + --network-interface=network-tier=PREMIUM,subnet=default \ + --maintenance-policy=MIGRATE \ + --provisioning-model=STANDARD \ + --service-account=default \ + --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \ + --tags=http-server,https-server \ + --create-disk=auto-delete=yes,boot=yes,device-name=$VM_NAME,image=projects/$IMAGE_PROJECT/global/images/family/$IMAGE_FAMILY,mode=rw,size=20,type=projects/$PROJECT_ID/zones/$ZONE/diskTypes/pd-standard \ + --no-shielded-secure-boot \ + --shielded-vtpm \ + --shielded-integrity-monitoring \ + --labels=environment=production,app=snatchgame \ + --reservation-affinity=any \ + --metadata-from-file startup-script=startup-script.sh + +echo "VM creada exitosamente!" + +# Obtener IP externa +EXTERNAL_IP=$(gcloud compute instances describe $VM_NAME --zone=$ZONE --format='get(networkInterfaces[0].accessConfigs[0].natIP)') + +echo "" +echo "==================================================" +echo "VM SnatchGame creada exitosamente!" +echo "==================================================" +echo "Nombre: $VM_NAME" +echo "Zona: $ZONE" +echo "IP Externa: $EXTERNAL_IP" +echo "==================================================" +echo "" +echo "Próximos pasos:" +echo "1. Configurar DNS en Cloudflare:" +echo " A record: snatchgame.nucleoriofrio.com → $EXTERNAL_IP" +echo "" +echo "2. Esperar ~5 minutos para que el startup script termine" +echo "" +echo "3. Verificar que funciona:" +echo " http://$EXTERNAL_IP" +echo "" +echo "4. Una vez que DNS se propague:" +echo " http://snatchgame.nucleoriofrio.com" +echo "" +echo "Para monitorear el progreso del startup script:" +echo "gcloud compute ssh $VM_NAME --zone=$ZONE --command='sudo tail -f /var/log/syslog'" \ No newline at end of file diff --git a/deploy/gcloud/startup-script.sh b/deploy/gcloud/startup-script.sh new file mode 100644 index 0000000..65f7f2c --- /dev/null +++ b/deploy/gcloud/startup-script.sh @@ -0,0 +1,137 @@ +#!/bin/bash + +# Startup script para VM de Google Cloud +# Este script se ejecuta cuando la VM inicia + +# Update system +apt-get update +apt-get install -y apt-transport-https ca-certificates curl software-properties-common + +# Install Docker +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +apt-get update +apt-get install -y docker-ce docker-ce-cli containerd.io + +# Install Docker Compose +curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +chmod +x /usr/local/bin/docker-compose + +# Install Nginx +apt-get install -y nginx + +# Create nginx config for SnatchGame +cat > /etc/nginx/sites-available/snatchgame << 'EOF' +server { + listen 80; + server_name snatchgame.nucleoriofrio.com; + client_max_body_size 100M; + + # Frontend (puerto 3000 del contenedor) + location / { + proxy_pass http://localhost:3000; + proxy_set_header Host $http_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; + proxy_http_version 1.1; + } + + # WebSocket de Colyseus + location /ws { + proxy_pass http://localhost:2567; + proxy_set_header Host $http_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; + + # Headers específicos para WebSocket + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_cache_bypass $http_upgrade; + + # Timeouts para WebSocket + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + } + + # API REST general + location /api/ { + proxy_pass http://localhost:2567/api/; + proxy_set_header Host $http_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; + proxy_http_version 1.1; + } + + # SSE para dashboard + location /api/dashboard-stream { + proxy_pass http://localhost:2567/api/dashboard-stream; + proxy_set_header Host $http_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; + + # Headers específicos para SSE + proxy_buffering off; + proxy_cache off; + proxy_read_timeout 24h; + proxy_http_version 1.1; + } + + # Monitor de Colyseus (opcional) + location /colyseus { + proxy_pass http://localhost:2567/colyseus; + proxy_set_header Host $http_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; + proxy_http_version 1.1; + } +} +EOF + +# Enable site +ln -sf /etc/nginx/sites-available/snatchgame /etc/nginx/sites-enabled/ +rm -f /etc/nginx/sites-enabled/default + +# Start services +systemctl enable nginx +systemctl start nginx +systemctl enable docker +systemctl start docker + +# Create deployment script +cat > /opt/deploy-snatchgame.sh << 'EOF' +#!/bin/bash + +# Script para desplegar nueva versión del juego +echo "Deploying SnatchGame..." + +# Parar contenedor anterior +docker stop snatchgame 2>/dev/null || true +docker rm snatchgame 2>/dev/null || true + +# Obtener última imagen +docker pull gitea.nucleoriofrio.com/nucleo000/snatchgame:latest + +# Ejecutar nuevo contenedor +docker run -d \ + --name snatchgame \ + --restart unless-stopped \ + -p 3000:3000 \ + -p 2567:2567 \ + gitea.nucleoriofrio.com/nucleo000/snatchgame:latest + +echo "SnatchGame deployed successfully!" +EOF + +chmod +x /opt/deploy-snatchgame.sh + +# Initial deployment +/opt/deploy-snatchgame.sh + +echo "VM setup completed!" \ No newline at end of file diff --git a/deploy/gcloud/update-deployment.sh b/deploy/gcloud/update-deployment.sh new file mode 100644 index 0000000..a9cd139 --- /dev/null +++ b/deploy/gcloud/update-deployment.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Script para actualizar el deployment en la VM de Google Cloud +# Se puede ejecutar manualmente o desde CI/CD + +PROJECT_ID="tu-proyecto-gcloud" # Cambiar por tu project ID +ZONE="us-central1-a" +VM_NAME="snatchgame-vm" + +echo "Actualizando deployment en VM de Google Cloud..." + +# Ejecutar script de deployment en la VM +gcloud compute ssh $VM_NAME \ + --zone=$ZONE \ + --command="sudo /opt/deploy-snatchgame.sh" + +echo "Deployment actualizado exitosamente!" + +# Verificar que el contenedor está corriendo +echo "Verificando estado del contenedor..." +gcloud compute ssh $VM_NAME \ + --zone=$ZONE \ + --command="docker ps | grep snatchgame" + +echo "¡Listo! El juego debería estar disponible en http://snatchgame.nucleoriofrio.com" \ No newline at end of file diff --git a/start.sh b/deploy/start.sh similarity index 100% rename from start.sh rename to deploy/start.sh diff --git a/push-remotes.sh b/push-remotes.sh new file mode 100644 index 0000000..094a60c --- /dev/null +++ b/push-remotes.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Script para hacer push a ambos remotes con diferentes .gitignore + +echo "Pushing to Gitea (with deploy folder)..." +# Para Gitea: usar .gitignore normal (incluye deploy/) +git add -A +git commit -m "${1:-Update deployment}" || echo "No changes to commit" +git push gitea main + +echo "Pushing to GitHub (without deploy folder)..." +# Para GitHub: usar .gitignore que excluye deploy/ +if [ -f .gitignore.github ]; then + # Backup actual .gitignore + cp .gitignore .gitignore.backup + + # Usar .gitignore específico para GitHub + cp .gitignore.github .gitignore + + # Hacer push sin deploy/ + git add .gitignore + git rm -r --cached deploy/ 2>/dev/null || true + git commit -m "${1:-Update without deploy folder}" || echo "No changes to commit" + git push origin main + + # Restaurar .gitignore original + cp .gitignore.backup .gitignore + git add .gitignore + git commit -m "Restore gitignore" || echo "No changes to commit" +else + echo "No .gitignore.github found, skipping GitHub push" +fi + +echo "Done!" \ No newline at end of file