From 580099bf59b7fc8fff5cfa57ff6b9f1937638eb7 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 5 Jul 2025 14:19:19 -0600 Subject: [PATCH] feat: Add Docker infrastructure and Gitea CI/CD pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Dockerfiles for server, client, and admin services - Create docker-compose.yml for orchestration - Add Gitea Actions workflow for automated build/deploy - Configure conditional builds based on directory changes - Use gitea.interno.com registry for image storage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .gitea/workflows/build-and-deploy.yml | 79 +++++++++++++++++++++++++++ admin/Dockerfile | 27 +++++++++ client/Dockerfile | 27 +++++++++ docker-compose.yml | 69 +++++++++++++++++++++++ server/Dockerfile | 27 +++++++++ 5 files changed, 229 insertions(+) create mode 100644 .gitea/workflows/build-and-deploy.yml create mode 100644 admin/Dockerfile create mode 100644 client/Dockerfile create mode 100644 docker-compose.yml create mode 100644 server/Dockerfile diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml new file mode 100644 index 0000000..b89d038 --- /dev/null +++ b/.gitea/workflows/build-and-deploy.yml @@ -0,0 +1,79 @@ +name: build-and-deploy + +on: + push: + branches: [ master ] + +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 # ⬅ ponelo en secrets + password: 7bc7b2fcd283bd6a251bef3ede368b7f897c919d # ⬅ idem + + - 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 + + - 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 diff --git a/admin/Dockerfile b/admin/Dockerfile new file mode 100644 index 0000000..4f5db46 --- /dev/null +++ b/admin/Dockerfile @@ -0,0 +1,27 @@ +# Admin Dockerfile - Vue 3 Admin Dashboard +FROM node:18-alpine + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci + +# Copy source code +COPY . . + +# Build Vue application +RUN npm run build + +# Expose port +EXPOSE 3001 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3001/health || exit 1 + +# Start admin server +CMD ["npm", "start"] \ No newline at end of file diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..d703582 --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,27 @@ +# Client Dockerfile - Vue 3 Client UI +FROM node:18-alpine + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci + +# Copy source code +COPY . . + +# Build Vue application +RUN npm run build + +# Expose port +EXPOSE 3000 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3000/health || exit 1 + +# Start client server +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..93c6963 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,69 @@ +version: '3.8' + +services: + # Servidor Colyseus + snatchgame-server: + image: gitea.interno.com/nucleo000/snatchgame-server:latest + container_name: snatchgame-server + ports: + - "2567:2567" + environment: + - NODE_ENV=production + - PORT=2567 + networks: + - snatchgame-network + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:2567/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + # Cliente Vue UI + snatchgame-client: + image: gitea.interno.com/nucleo000/snatchgame-client:latest + container_name: snatchgame-client + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - PORT=3000 + - VITE_SERVER_URL=http://snatchgame-server:2567 + depends_on: + - snatchgame-server + networks: + - snatchgame-network + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + # Admin Dashboard + snatchgame-admin: + image: gitea.interno.com/nucleo000/snatchgame-admin:latest + container_name: snatchgame-admin + ports: + - "3001:3001" + environment: + - NODE_ENV=production + - PORT=3001 + - VITE_SERVER_URL=http://snatchgame-server:2567 + depends_on: + - snatchgame-server + networks: + - snatchgame-network + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3001/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + +networks: + snatchgame-network: + driver: bridge \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..8c8574a --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,27 @@ +# Server Dockerfile - Colyseus Server +FROM node:18-alpine + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci --only=production + +# Copy source code +COPY . . + +# Build TypeScript +RUN npm run build + +# Expose port +EXPOSE 2567 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:2567/health || exit 1 + +# Start server +CMD ["npm", "start"] \ No newline at end of file