mirror of
https://github.com/p-stream/backend.git
synced 2026-04-18 14:02:05 +00:00
Refactor Dockerfile for improved efficiency
This commit is contained in:
parent
0c65b8e9f7
commit
cbc907cae4
1 changed files with 15 additions and 7 deletions
22
Dockerfile
22
Dockerfile
|
|
@ -1,14 +1,18 @@
|
|||
FROM node:22-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
# Install curl (for Coolify healthchecks) and openssl (required by Prisma on Alpine)
|
||||
RUN apk add --no-cache curl openssl
|
||||
|
||||
# 1. Copy dependency files first to maximize Docker layer caching
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Install curl for healthchecks (required by Coolify)
|
||||
RUN apk add --no-cache curl
|
||||
# 2. Copy ONLY the prisma folder next to cache the Prisma Client generation
|
||||
COPY prisma ./prisma/
|
||||
|
||||
# Define build arguments
|
||||
ARG BUILD_DATABASE_URL="file:./dev.db"
|
||||
ARG DATABASE_URL
|
||||
ARG DATABASE_URL_DOCKER
|
||||
ARG META_NAME
|
||||
|
|
@ -21,7 +25,7 @@ ARG TRAKT_CLIENT_ID
|
|||
ARG TRAKT_SECRET_ID
|
||||
ARG NODE_ENV=production
|
||||
|
||||
ENV DATABASE_URL=${DATABASE_URL}
|
||||
# Persist only non-sensitive runtime env vars (do NOT persist real DATABASE_URL)
|
||||
ENV DATABASE_URL_DOCKER=${DATABASE_URL_DOCKER}
|
||||
ENV META_NAME=${META_NAME}
|
||||
ENV META_DESCRIPTION=${META_DESCRIPTION}
|
||||
|
|
@ -33,12 +37,16 @@ ENV TRAKT_CLIENT_ID=${TRAKT_CLIENT_ID}
|
|||
ENV TRAKT_SECRET_ID=${TRAKT_SECRET_ID}
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
|
||||
# 3. Generate Prisma client using the build-only placeholder URL
|
||||
RUN DATABASE_URL=${BUILD_DATABASE_URL} npx prisma generate
|
||||
|
||||
# 4. Copy the rest of the application code AFTER dependencies and Prisma are sorted
|
||||
COPY . .
|
||||
|
||||
RUN npx prisma generate
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Run migrations and start the server (kept exactly as you requested)
|
||||
CMD ["sh", "-c", "npx prisma migrate deploy && node .output/server/index.mjs"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue