update docker
This commit is contained in:
parent
fda3643881
commit
b79ee0c08a
2 changed files with 11 additions and 79 deletions
44
Dockerfile
44
Dockerfile
|
|
@ -1,10 +1,8 @@
|
||||||
# syntax = docker/dockerfile:1
|
# syntax = docker/dockerfile:1
|
||||||
|
|
||||||
ARG NODE_VERSION=20
|
ARG NODE_VERSION=20
|
||||||
FROM node:${NODE_VERSION}-slim AS base-node
|
FROM node:${NODE_VERSION}-slim AS base-node
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV NODE_ENV="production"
|
ENV NODE_ENV="production"
|
||||||
|
|
||||||
RUN apt-get update -qq && \
|
RUN apt-get update -qq && \
|
||||||
apt-get install --no-install-recommends -y \
|
apt-get install --no-install-recommends -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
|
|
@ -17,66 +15,34 @@ RUN apt-get update -qq && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
FROM base-node AS build-main
|
FROM base-node AS build-main
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY website/package.json website/package-lock.json* ./
|
COPY website/package.json website/package-lock.json* ./
|
||||||
|
|
||||||
RUN npm install --include=dev
|
RUN npm install --include=dev
|
||||||
|
|
||||||
COPY website/. ./
|
COPY website/. ./
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM base-node AS build-websocket
|
FROM base-node AS build-websocket
|
||||||
WORKDIR /websocket
|
WORKDIR /websocket
|
||||||
|
|
||||||
RUN curl -fsSL https://bun.sh/install | bash
|
RUN curl -fsSL https://bun.sh/install | bash
|
||||||
ENV PATH="/root/.bun/bin:${PATH}"
|
ENV PATH="/root/.bun/bin:${PATH}"
|
||||||
|
|
||||||
COPY website/websocket/package.json website/websocket/bun.lock* ./
|
COPY website/websocket/package.json website/websocket/bun.lock* ./
|
||||||
COPY website/websocket/tsconfig.json ./
|
COPY website/websocket/tsconfig.json ./
|
||||||
|
|
||||||
RUN bun install
|
RUN bun install
|
||||||
|
|
||||||
COPY website/websocket/src ./src/
|
COPY website/websocket/src ./src/
|
||||||
|
|
||||||
RUN bun build src/main.ts --outdir dist --target bun
|
RUN bun build src/main.ts --outdir dist --target bun
|
||||||
|
|
||||||
FROM base-node AS production-main
|
FROM base-node AS production-main
|
||||||
|
|
||||||
COPY --from=build-main --chown=node:node /app/build ./build
|
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/node_modules ./node_modules
|
||||||
COPY --from=build-main --chown=node:node /app/package.json ./package.json
|
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
|
USER node
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
CMD ["node", "build"]
|
||||||
|
|
||||||
CMD ["pm2-runtime", "start", "ecosystem.config.cjs"]
|
FROM oven/bun:1 AS production-websocket
|
||||||
|
|
||||||
FROM base-node AS production-websocket
|
|
||||||
WORKDIR /websocket
|
WORKDIR /websocket
|
||||||
|
COPY --from=build-websocket --chown=bun:bun /websocket/dist ./dist
|
||||||
RUN curl -fsSL https://bun.sh/install | bash
|
COPY --from=build-websocket --chown=bun:bun /websocket/package.json ./package.json
|
||||||
ENV PATH="/root/.bun/bin:${PATH}"
|
USER bun
|
||||||
|
|
||||||
COPY --from=build-websocket /websocket/dist ./dist
|
|
||||||
COPY --from=build-websocket /websocket/package.json ./package.json
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD ["bun", "run", "dist/main.js"]
|
CMD ["bun", "run", "dist/main.js"]
|
||||||
|
|
@ -1,57 +1,23 @@
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# Multiple app instances
|
app:
|
||||||
app-1:
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: production-main
|
target: production-main
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "3003:3000" # Expose to host for nginx
|
- "5900-5907:3000"
|
||||||
env_file:
|
env_file:
|
||||||
- website/.env
|
- website/.env
|
||||||
environment:
|
|
||||||
- INSTANCE_NAME=app-1
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- websocket
|
- websocket
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- shared_backend
|
- 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:
|
websocket:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
|
|
||||||
Reference in a new issue