refactor: finalize standalone services cleanup
Build & Deploy / build-and-push (backend) (push) Failing after 39s
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 26s
Build & Deploy / build-and-push (proxy) (push) Failing after 24s
Build & Deploy / build-and-push (backend) (push) Failing after 39s
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 26s
Build & Deploy / build-and-push (proxy) (push) Failing after 24s
- Remove root pnpm-lock.yaml (stale monorepo lockfile) - Rename root package from bete-monorepo to bete - Clean up root scripts to use cd instead of pnpm --prefix - Remove ignoreScripts/trustedDependencies from frontend package.json - Optimize Dockerfiles with multi-stage builds and proper layer caching - Update .dockerignore to exclude build artifacts - Remove leftover pnpm test config file from frontend
This commit is contained in:
+14
-4
@@ -1,11 +1,21 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
.next
|
||||||
|
out
|
||||||
.env
|
.env
|
||||||
.env.test
|
.env.*
|
||||||
.git
|
.git
|
||||||
.github
|
.gitignore
|
||||||
recordings
|
.claude/
|
||||||
|
.vscode/
|
||||||
|
.design/
|
||||||
|
design/
|
||||||
|
docs/
|
||||||
|
scripts/
|
||||||
|
test_out.nut
|
||||||
*.db
|
*.db
|
||||||
*.db-shm
|
*.db-shm
|
||||||
*.db-wal
|
*.db-wal
|
||||||
test_out.nut
|
*.log
|
||||||
|
*.md
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@@ -1,45 +1,53 @@
|
|||||||
|
# ---- Builder stage: install deps + compile ----
|
||||||
|
FROM node:22-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# Install pnpm and allow postinstall scripts for native addons
|
||||||
|
RUN npm install -g pnpm \
|
||||||
|
&& pnpm config set onlyBuiltDependencies '*' --location project
|
||||||
|
|
||||||
|
# Build-time system deps (python3 for node-gyp, g++ for native addons)
|
||||||
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
||||||
|
python3 make g++ \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Copy manifest files first for layer caching
|
||||||
|
COPY services/backend/package.json ./
|
||||||
|
COPY patches/ ./patches/
|
||||||
|
|
||||||
|
# Install all deps (devDeps included for build)
|
||||||
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --no-frozen-lockfile
|
||||||
|
|
||||||
|
# Copy source (shared code embedded in src/shared/)
|
||||||
|
COPY services/backend/ ./
|
||||||
|
|
||||||
|
# Build TypeScript
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# Strip devDependencies — production runtime only
|
||||||
|
RUN pnpm prune --prod
|
||||||
|
|
||||||
|
# ---- Runtime stage: minimal ----
|
||||||
FROM node:22-slim
|
FROM node:22-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install pnpm
|
|
||||||
RUN npm install -g pnpm
|
|
||||||
|
|
||||||
# Install build tools for native dependencies (node-crc, @discordjs/opus)
|
|
||||||
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends python3 make g++ wget && rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN groupadd --system app && useradd --system -g app app
|
RUN groupadd --system app && useradd --system -g app app
|
||||||
|
|
||||||
# Copy dependency definition files first for better caching
|
# Only production artifacts from builder
|
||||||
COPY services/backend/package.json services/backend/pnpm-lock.yaml* ./services/backend/
|
COPY --from=builder /build/dist ./dist
|
||||||
|
COPY --from=builder /build/node_modules ./node_modules
|
||||||
|
COPY --from=builder /build/package.json ./
|
||||||
|
|
||||||
# Copy patches (pnpm patchedDependencies)
|
|
||||||
COPY patches ./patches
|
|
||||||
|
|
||||||
# Copy service source (shared code is embedded in src/shared/)
|
|
||||||
COPY services/backend/ ./services/backend/
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
||||||
cd services/backend && pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
# Build backend
|
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
||||||
cd services/backend && pnpm run build
|
|
||||||
|
|
||||||
# Own dist + node_modules by non-root user
|
|
||||||
RUN chown -R app:app /app
|
RUN chown -R app:app /app
|
||||||
|
|
||||||
# Switch to non-root user
|
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
# Expose port
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Healthcheck — backend serves HTTP on port 3000
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
||||||
CMD wget -qO- http://localhost:3000/api/health || exit 1
|
CMD wget -qO- http://localhost:3000/api/health || exit 1
|
||||||
|
|
||||||
# Start backend
|
CMD ["node", "dist/index.js"]
|
||||||
CMD ["node", "services/backend/dist/index.js"]
|
|
||||||
|
|||||||
@@ -1,56 +1,60 @@
|
|||||||
# ---- Stage 1: Build native deps + TypeScript ----
|
# ---- Builder stage: native addons + TypeScript ----
|
||||||
FROM node:22-slim AS builder
|
FROM node:22-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /build
|
||||||
|
|
||||||
RUN corepack enable
|
# Install pnpm and allow postinstall scripts for native addons
|
||||||
|
RUN corepack enable \
|
||||||
|
&& pnpm config set onlyBuiltDependencies '*' --location project
|
||||||
|
|
||||||
# Build tools + Rust for native compilation
|
# Build tools + Rust (required by @dank074/discord-video-stream)
|
||||||
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
||||||
python3 make g++ curl ca-certificates \
|
python3 make g++ curl ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
|
||||||
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
|
||||||
|
|
||||||
# Dependency manifests
|
|
||||||
COPY services/discord-gateway/package.json services/discord-gateway/pnpm-lock.yaml* ./services/discord-gateway/
|
|
||||||
COPY patches ./patches
|
|
||||||
|
|
||||||
# Install ALL deps (including devDeps needed for build)
|
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
||||||
cd services/discord-gateway && pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
# Source code (shared code is embedded in src/shared/)
|
|
||||||
COPY services/discord-gateway ./services/discord-gateway
|
|
||||||
COPY services/discord-gateway/drizzle ./drizzle
|
|
||||||
|
|
||||||
# Build
|
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
||||||
cd services/discord-gateway && pnpm run build \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# ---- Stage 2: Runtime (minimal) ----
|
# Install Rust toolchain (separate RUN so the layer can cache if apt changes)
|
||||||
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
||||||
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
|
# Manifest files first for layer caching
|
||||||
|
COPY services/discord-gateway/package.json ./
|
||||||
|
COPY patches/ ./patches/
|
||||||
|
|
||||||
|
# Install all deps (devDeps needed for TypeScript build)
|
||||||
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --no-frozen-lockfile
|
||||||
|
|
||||||
|
# Source code (shared code embedded in src/shared/)
|
||||||
|
COPY services/discord-gateway/ ./
|
||||||
|
COPY services/discord-gateway/drizzle ./drizzle
|
||||||
|
|
||||||
|
# Build TypeScript
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# Strip devDependencies — only production deps in final image
|
||||||
|
RUN pnpm prune --prod
|
||||||
|
|
||||||
|
# ---- Runtime stage: minimal ----
|
||||||
FROM node:22-slim
|
FROM node:22-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Runtime system deps only
|
# Runtime system deps only (ffmpeg for audio processing)
|
||||||
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
||||||
ffmpeg ca-certificates \
|
ffmpeg ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy built artifacts
|
# Only production artifacts from builder
|
||||||
COPY --from=builder /app/services/discord-gateway/dist ./services/discord-gateway/dist
|
COPY --from=builder /build/dist ./dist
|
||||||
COPY --from=builder /app/services/discord-gateway/node_modules ./services/discord-gateway/node_modules
|
COPY --from=builder /build/node_modules ./node_modules
|
||||||
COPY --from=builder /app/services/discord-gateway/package.json ./services/discord-gateway/package.json
|
COPY --from=builder /build/package.json ./
|
||||||
COPY --from=builder /app/drizzle ./drizzle
|
COPY --from=builder /build/drizzle ./drizzle
|
||||||
|
|
||||||
# Create recordings dir and set ownership
|
# Create recordings dir
|
||||||
RUN mkdir -p /app/recordings && chown -R node:node /app
|
RUN mkdir -p /app/recordings && chown -R node:node /app
|
||||||
USER node
|
USER node
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
||||||
CMD sh -c "kill -0 1"
|
CMD sh -c "kill -0 1"
|
||||||
|
|
||||||
CMD ["node", "services/discord-gateway/dist/index.js"]
|
CMD ["node", "dist/index.js"]
|
||||||
|
|||||||
@@ -1,44 +1,42 @@
|
|||||||
# ---- Stage 1: Build Next.js static export ----
|
# ---- Builder stage: Next.js static export ----
|
||||||
FROM node:22-slim AS frontend-builder
|
FROM node:22-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /build
|
||||||
|
|
||||||
# Install pnpm
|
|
||||||
RUN corepack enable
|
RUN corepack enable
|
||||||
|
|
||||||
# Install build essentials for native deps
|
# Build essentials
|
||||||
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
||||||
python3 make g++ && rm -rf /var/lib/apt/lists/*
|
make g++ \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy dependency manifests first for layer caching
|
# Manifest files first
|
||||||
COPY services/frontend/package.json services/frontend/pnpm-lock.yaml* ./services/frontend/
|
COPY services/frontend/package.json ./
|
||||||
COPY services/frontend/tsconfig.json ./services/frontend/tsconfig.json
|
COPY services/frontend/tsconfig.json ./
|
||||||
|
COPY services/frontend/next.config.ts ./
|
||||||
|
|
||||||
# Install frontend dependencies (standalone, no shared workspace dep)
|
# Install all deps, skip postinstall (no native addons needed for static export)
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||||
cd services/frontend && pnpm install --no-frozen-lockfile
|
pnpm install --ignore-scripts --no-frozen-lockfile
|
||||||
|
|
||||||
# Copy source code
|
# Source code
|
||||||
COPY services/frontend/ ./services/frontend/
|
COPY services/frontend/ ./
|
||||||
|
|
||||||
# Pass API/WS URLs as build args
|
# Build args
|
||||||
ARG VITE_BE_API_URL
|
ARG VITE_BE_API_URL
|
||||||
ARG VITE_BE_WS_URL
|
ARG VITE_BE_WS_URL
|
||||||
ENV VITE_BE_API_URL=${VITE_BE_API_URL}
|
ENV VITE_BE_API_URL=${VITE_BE_API_URL}
|
||||||
ENV VITE_BE_WS_URL=${VITE_BE_WS_URL}
|
ENV VITE_BE_WS_URL=${VITE_BE_WS_URL}
|
||||||
|
|
||||||
# Build frontend static export
|
# Build static export
|
||||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||||
cd services/frontend && pnpm run build
|
npx next build
|
||||||
|
|
||||||
# ---- Stage 2: Nginx ----
|
# ---- Runtime stage: nginx ----
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Nginx config (API/WS proxy + static file serving)
|
|
||||||
COPY infra/docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
COPY infra/docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=builder /build/out/ /usr/share/nginx/html/
|
||||||
# Static export from frontend builder
|
|
||||||
COPY --from=frontend-builder /app/services/frontend/out/ /usr/share/nginx/html/
|
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "bete-monorepo",
|
"name": "bete",
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Bete Discord Moderation Services — standalone services in one repo",
|
"description": "Bete Discord Moderation — 3 standalone services in one repo",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev:backend": "pnpm --prefix services/backend dev",
|
"dev:backend": "cd services/backend && pnpm dev",
|
||||||
"dev:discord-gateway": "pnpm --prefix services/discord-gateway dev",
|
"dev:discord-gateway": "cd services/discord-gateway && pnpm dev",
|
||||||
"dev:web": "pnpm --prefix services/frontend dev",
|
"dev:web": "cd services/frontend && pnpm dev",
|
||||||
"build:web": "pnpm --prefix services/frontend build",
|
"build:backend": "cd services/backend && pnpm build",
|
||||||
"build:backend": "pnpm --prefix services/backend build",
|
"build:gateway": "cd services/discord-gateway && pnpm build",
|
||||||
"build:discord-gateway": "pnpm --prefix services/discord-gateway build",
|
"build:web": "cd services/frontend && pnpm build",
|
||||||
"typecheck": "pnpm --prefix services/backend typecheck && pnpm --prefix services/discord-gateway typecheck",
|
"typecheck": "cd services/backend && pnpm typecheck && cd ../../services/discord-gateway && pnpm typecheck",
|
||||||
"lint": "biome check --diagnostic-level=error .",
|
"lint": "biome check --diagnostic-level=error .",
|
||||||
"format": "biome format --write .",
|
"format": "biome format --write .",
|
||||||
"test": "pnpm --prefix services/backend test && pnpm --prefix services/discord-gateway test",
|
"test": "cd services/backend && pnpm test && cd ../../services/discord-gateway && pnpm test",
|
||||||
|
"install:all": "cd services/backend && pnpm install && cd ../../services/frontend && pnpm install && cd ../../services/discord-gateway && pnpm install",
|
||||||
"db:truncate": "psql \"$DATABASE_URL\" -f scripts/truncate-all.sql",
|
"db:truncate": "psql \"$DATABASE_URL\" -f scripts/truncate-all.sql",
|
||||||
"install:yt-dlp": "sh scripts/install-yt-dlp.sh"
|
"install:yt-dlp": "sh scripts/install-yt-dlp.sh"
|
||||||
},
|
},
|
||||||
|
|||||||
Generated
-9184
File diff suppressed because it is too large
Load Diff
@@ -41,13 +41,5 @@
|
|||||||
"babel-plugin-react-compiler": "1.0.0",
|
"babel-plugin-react-compiler": "1.0.0",
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
},
|
}
|
||||||
"ignoreScripts": [
|
|
||||||
"sharp",
|
|
||||||
"unrs-resolver"
|
|
||||||
],
|
|
||||||
"trustedDependencies": [
|
|
||||||
"sharp",
|
|
||||||
"unrs-resolver"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user