From b79ee0c08ad379e3f6b0412881c118d455ba406a Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Tue, 24 Jun 2025 18:13:50 +0300 Subject: [PATCH] update docker --- Dockerfile | 44 +++++--------------------------------------- docker-compose.yml | 46 ++++++---------------------------------------- 2 files changed, 11 insertions(+), 79 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36ed65d..807eb44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ # syntax = docker/dockerfile:1 - ARG NODE_VERSION=20 FROM node:${NODE_VERSION}-slim AS base-node WORKDIR /app ENV NODE_ENV="production" - RUN apt-get update -qq && \ apt-get install --no-install-recommends -y \ build-essential \ @@ -17,66 +15,34 @@ RUN apt-get update -qq && \ rm -rf /var/lib/apt/lists/* FROM base-node AS build-main - # Copy package files COPY website/package.json website/package-lock.json* ./ - RUN npm install --include=dev - COPY website/. ./ - RUN npm run build FROM base-node AS build-websocket WORKDIR /websocket - RUN curl -fsSL https://bun.sh/install | bash ENV PATH="/root/.bun/bin:${PATH}" - COPY website/websocket/package.json website/websocket/bun.lock* ./ COPY website/websocket/tsconfig.json ./ - RUN bun install - COPY website/websocket/src ./src/ - RUN bun build src/main.ts --outdir dist --target bun FROM base-node AS production-main - COPY --from=build-main --chown=node:node /app/build ./build COPY --from=build-main --chown=node:node /app/node_modules ./node_modules COPY --from=build-main --chown=node:node /app/package.json ./package.json - -RUN npm install -g pm2 - -RUN echo 'module.exports = {\ - apps: [{\ - name: "rugplay-app",\ - script: "./build/index.js",\ - instances: "max",\ - exec_mode: "cluster",\ - env: {\ - NODE_ENV: "production",\ - PORT: 3000,\ - BODY_SIZE_LIMIT: "1.1M"\ - }\ - }]\ -};' > ecosystem.config.cjs - USER node EXPOSE 3000 +CMD ["node", "build"] -CMD ["pm2-runtime", "start", "ecosystem.config.cjs"] - -FROM base-node AS production-websocket +FROM oven/bun:1 AS production-websocket WORKDIR /websocket - -RUN curl -fsSL https://bun.sh/install | bash -ENV PATH="/root/.bun/bin:${PATH}" - -COPY --from=build-websocket /websocket/dist ./dist -COPY --from=build-websocket /websocket/package.json ./package.json - +COPY --from=build-websocket --chown=bun:bun /websocket/dist ./dist +COPY --from=build-websocket --chown=bun:bun /websocket/package.json ./package.json +USER bun EXPOSE 8080 CMD ["bun", "run", "dist/main.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index bfb0282..e41561b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,57 +1,23 @@ +version: '3.8' + services: - # Multiple app instances - app-1: + app: build: context: . target: production-main dockerfile: Dockerfile ports: - - "3003:3000" # Expose to host for nginx + - "5900-5907:3000" env_file: - website/.env - environment: - - INSTANCE_NAME=app-1 depends_on: - websocket restart: unless-stopped networks: - shared_backend + deploy: + replicas: 8 - app-2: - build: - context: . - target: production-main - dockerfile: Dockerfile - ports: - - "3004:3000" # Different port for second instance - env_file: - - website/.env - environment: - - INSTANCE_NAME=app-2 - depends_on: - - websocket - restart: unless-stopped - networks: - - shared_backend - - app-3: - build: - context: . - target: production-main - dockerfile: Dockerfile - ports: - - "3005:3000" # Different port for third instance - env_file: - - website/.env - environment: - - INSTANCE_NAME=app-3 - depends_on: - - websocket - restart: unless-stopped - networks: - - shared_backend - - # WebSocket service (single instance is usually sufficient) websocket: build: context: .