lifetracker/Dockerfile

61 lines
1.8 KiB
Docker

FROM node:18-alpine AS base
FROM base AS builder
RUN apk update
RUN apk add --no-cache libc6-compat postgresql
# Set working directory
WORKDIR /app
# Replace <your-major-version> with the major version installed in your repository. For example:
# RUN yarn global add turbo@^2
RUN corepack enable
RUN pnpm install turbo@^2.2.3
COPY . .
# Generate a partial monorepo with a pruned lockfile for a target workspace.
# Assuming "web" is the name entered in the project's package.json: { name: "web" }
RUN pnpm turbo prune @lifetracker/web --docker
# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN corepack enable
# First install the dependencies (as they change less often)
COPY --from=builder /app/out/json/ .
RUN pnpm install
# Build the project
COPY --from=builder /app/out/full/ .
RUN pnpm turbo run build
FROM base AS runner
WORKDIR /app
RUN corepack enable
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
# Handle db migrations
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodejs /app/packages/db ./packages/db
RUN ["pnpm", "--filter=@lifetracker/db", "install"]
RUN ["pnpm", "--filter=@lifetracker/db", "generate"]
RUN ["pnpm", "--filter=@lifetracker/db", "migrate"]
EXPOSE 3000
CMD node apps/web/server.js