config: migrate from nestjs to tasks and websocket server in docker (#316)
* feat: make tasks script run in docker * feat: make websocket server work in docker * fix: format issue * fix: broken lockfile * fix: non matching typescript versions
This commit is contained in:
46
Dockerfile
46
Dockerfile
@@ -1,14 +1,16 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat redis
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN npm i -g turbo
|
||||
RUN turbo prune @homarr/nextjs --docker --out-dir ./next-out
|
||||
RUN turbo prune @homarr/nest --docker --out-dir ./nest-out
|
||||
RUN turbo prune @homarr/tasks --docker --out-dir ./tasks-out
|
||||
RUN turbo prune @homarr/websocket --docker --out-dir ./websocket-out
|
||||
RUN turbo prune @homarr/db --docker --out-dir ./migration-out
|
||||
|
||||
# Add lockfile and package.json's of isolated subworkspace
|
||||
FROM base AS installer
|
||||
@@ -19,35 +21,35 @@ WORKDIR /app
|
||||
# First install the dependencies (as they change less often)
|
||||
COPY .gitignore .gitignore
|
||||
|
||||
COPY --from=builder /app/nest-out/json/ .
|
||||
COPY --from=builder /app/nest-out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN corepack enable pnpm && pnpm install --prod
|
||||
RUN rm -rf node_modules/next
|
||||
RUN rm -rf node_modules/typescript
|
||||
RUN rm -rf node_modules/@babel
|
||||
RUN rm -rf node_modules/esbuild
|
||||
RUN rm -rf node_modules/@esbuild
|
||||
RUN rm -rf node_modules/@typescript-eslint
|
||||
RUN rm -rf node_modules/prettier
|
||||
RUN rm -rf node_modules/webpack
|
||||
RUN rm -rf node_modules/eslint
|
||||
RUN rm -rf node_modules/@swc
|
||||
RUN mv node_modules ./temp_node_modules
|
||||
COPY --from=builder /app/tasks-out/json/ .
|
||||
COPY --from=builder /app/tasks-out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN corepack enable pnpm && pnpm install
|
||||
|
||||
COPY --from=builder /app/websocket-out/json/ .
|
||||
COPY --from=builder /app/websocket-out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN corepack enable pnpm && pnpm install
|
||||
|
||||
COPY --from=builder /app/migration-out/json/ .
|
||||
COPY --from=builder /app/migration-out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN corepack enable pnpm && pnpm install
|
||||
|
||||
COPY --from=builder /app/next-out/json/ .
|
||||
COPY --from=builder /app/next-out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN corepack enable pnpm && pnpm install
|
||||
|
||||
# Build the project
|
||||
COPY --from=builder /app/nest-out/full/ .
|
||||
COPY --from=builder /app/tasks-out/full/ .
|
||||
COPY --from=builder /app/websocket-out/full/ .
|
||||
COPY --from=builder /app/next-out/full/ .
|
||||
COPY --from=builder /app/migration-out/full/ .
|
||||
ARG SKIP_ENV_VALIDATION=true
|
||||
RUN corepack enable pnpm && pnpm turbo run build
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache redis
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
@@ -56,8 +58,12 @@ USER nextjs
|
||||
COPY --from=installer /app/apps/nextjs/next.config.mjs .
|
||||
COPY --from=installer /app/apps/nextjs/package.json .
|
||||
|
||||
COPY --from=installer /app/temp_node_modules ./node_modules
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nestjs/dist ./apps/nestjs/dist
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/apps/tasks/tasks.cjs ./apps/tasks/tasks.cjs
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/apps/websocket/wssServer.cjs ./apps/websocket/wssServer.cjs
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node /app/build/better_sqlite3.node
|
||||
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/packages/db/migrations ./db/migrations
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/packages/db/migrate.cjs ./db/migrate.cjs
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
@@ -65,8 +71,6 @@ COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/standalone ./
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/static ./apps/nextjs/.next/static
|
||||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/public ./apps/nextjs/public
|
||||
COPY --chown=nextjs:nodejs scripts/run.sh ./run.sh
|
||||
COPY --chown=nextjs:nodejs packages/db/migrations ./db/migrations
|
||||
COPY --chown=nextjs:nodejs packages/db/migrate.mjs ./db/migrate.mjs
|
||||
|
||||
ENV DB_URL='/app/db/db.sqlite'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user