refactor: switch to alpine base image
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -1,47 +1,31 @@
|
|||||||
# Build frontend in a dedicated stage
|
# Build frontend in a dedicated stage
|
||||||
FROM node:24-slim AS frontend-build
|
FROM node:24-alpine AS frontend-build
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
COPY frontend/package*.json frontend/package-lock*.json ./
|
COPY frontend/package*.json frontend/package-lock*.json ./
|
||||||
RUN npm ci --silent
|
RUN npm ci --silent
|
||||||
COPY frontend/ .
|
COPY frontend/ .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Final image: build backend, generate Prisma client, prune dev deps, and include frontend dist
|
# Final runtime image
|
||||||
FROM node:24-slim AS final
|
FROM node:24-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# install minimal OS deps
|
|
||||||
RUN apt-get update -y \
|
|
||||||
&& apt-get install -y openssl
|
|
||||||
|
|
||||||
# copy package manifests and install deps (leverage Docker cache)
|
# copy package manifests and install deps (leverage Docker cache)
|
||||||
COPY backend/package*.json backend/package-lock*.json ./backend/
|
COPY backend/package*.json backend/package-lock*.json ./backend/
|
||||||
RUN cd backend && npm ci --silent
|
RUN cd backend && npm ci --silent
|
||||||
|
|
||||||
# copy backend source (schema, migrations, source)
|
# copy backend source (schema, migrations, source)
|
||||||
COPY backend ./backend
|
COPY backend ./backend
|
||||||
|
|
||||||
# generate Prisma client against a harmless temp DB path (does not apply migrations)
|
# generate Prisma client against a harmless temp DB path (does not apply migrations)
|
||||||
RUN cd backend && DATABASE_URL="file:./data/sqlite.db" npx prisma generate --schema=./prisma/schema.prisma || true
|
RUN cd backend && DATABASE_URL="file:./data/sqlite.db" npx prisma generate --schema=./prisma/schema.prisma || true
|
||||||
|
|
||||||
# remove devDependencies to slim image
|
# remove devDependencies to slim image
|
||||||
RUN cd backend && npm prune --production --silent
|
RUN cd backend && npm prune --production --silent
|
||||||
|
|
||||||
# install prisma CLI into final image so entrypoint can run migrate deploy at runtime
|
# install prisma CLI into final image so entrypoint can run migrate deploy at runtime
|
||||||
RUN cd backend && npm i --no-audit --no-fund prisma --silent || true
|
RUN cd backend && npm i --no-audit --no-fund prisma --silent || true
|
||||||
|
# copy entrypoint and make executable
|
||||||
# copy entrypoint (added below) and make executable
|
|
||||||
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
# Copy built frontend into the expected location: /app/frontend/dist
|
# Copy built frontend into the expected location: /app/frontend/dist
|
||||||
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
|
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
|
||||||
|
|
||||||
# runtime environment (DATA_DIR used at runtime; DATABASE_URL points to it)
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV DATA_DIR=/data
|
|
||||||
ENV DATABASE_URL="file:${DATA_DIR}/sqlite.db"
|
|
||||||
|
|
||||||
WORKDIR /app/backend
|
WORKDIR /app/backend
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user