Files
gruperly/Dockerfile.backend
Jose Selesan 69275c37b4 chore: update comments and documentation for clarity and consistency across various files
- Translated comments from Spanish to English in vite.config.ts, docker-compose.yml, attendance-risk.ts, analytics.ts, attendance.ts, attendees.ts, enums.ts, groups.ts, and onboarding.ts.
- Improved descriptions for better understanding of code functionality and purpose.
- Ensured uniformity in terminology and phrasing throughout the codebase.
2026-10-01 16:06:54 -03:00

67 lines
3.5 KiB
Docker

# syntax=docker/dockerfile:1
# ─── Base ────────────────────────────────────────────────────────────────────
FROM oven/bun:1.4-alpine AS base
WORKDIR /app
ENV CI=1
# ─── Dependencies ────────────────────────────────────────────────────────────
# Only the package.json files: bun needs no source code to resolve the lockfile.
FROM base AS deps
COPY package.json bun.lock bunfig.toml turbo.json ./
COPY apps/backend/package.json ./apps/backend/
COPY apps/web/package.json ./apps/web/
COPY packages/config/package.json ./packages/config/
COPY packages/shared/package.json ./packages/shared/
# bun's global cache weighs ~370MB: it is dropped in the same layer.
RUN bun install --frozen-lockfile && rm -rf /root/.bun/install
# ─── Prisma Client ───────────────────────────────────────────────────────────
# The "prisma-client" generator emits TypeScript, so the generated client runs
# with Bun without compilation. The URL is a placeholder: `generate` only needs
# to read the schema, not connect to a database.
FROM deps AS generate
ARG DATABASE_URL=postgresql://user:password@localhost:5432/placeholder
ENV DATABASE_URL=$DATABASE_URL
COPY apps/backend/prisma.config.ts ./apps/backend/
COPY apps/backend/prisma ./apps/backend/prisma
WORKDIR /app/apps/backend
RUN bun run db:generate
# ─── API image ───────────────────────────────────────────────────────────────
FROM base AS api
ENV NODE_ENV=production \
PORT=4000
COPY package.json bun.lock bunfig.toml ./
COPY apps/backend/package.json ./apps/backend/
COPY packages/config/package.json ./packages/config/
COPY packages/shared/package.json ./packages/shared/
# `prisma` and `dotenv` are dependencies (not dev) because the entrypoint runs
# `prisma migrate deploy` on every boot. With `--production` the rest of the
# tooling does not come in: biome, typescript, turbo.
RUN bun install --frozen-lockfile --production && rm -rf /root/.bun/install
# The Prisma CLI loads prisma.config.ts, which points to the schema.
COPY apps/backend/prisma ./apps/backend/prisma
COPY apps/backend/prisma.config.ts ./apps/backend/prisma.config.ts
COPY --from=generate /app/apps/backend/generated ./apps/backend/generated
COPY apps/backend/tsconfig.json ./apps/backend/
COPY apps/backend/src ./apps/backend/src
# @gruperly/shared is consumed as TS source; @gruperly/config provides the base
# tsconfig that the backend tsconfig extends.
COPY packages ./packages
COPY apps/backend/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
WORKDIR /app/apps/backend
EXPOSE 4000
# No `${...}` here: the CMD runs under /bin/sh (ash), where that is a syntax error.
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD bun --eval "fetch('http://127.0.0.1:4000/api/v1/health').then((r) => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Bun runs the TypeScript directly and resolves `@/*` with the tsconfig.json,
# same as `bun start` locally.
CMD ["bun", "src/server.ts"]