Files
VibeFinance/Dockerfile
T

81 lines
3.8 KiB
Docker
Raw Normal View History

# ╔══════════════════════════════════════════════════════════════════════════╗
# ║ VibeFinance — één app-image: Express API + gebouwde Vite-frontend ║
# ║ ║
# ║ Targets: ║
# ║ test backend-tests (npm test, geen database nodig) ║
# ║ development API (node --watch) + Vite dev-server, hot reload ║
# ║ production API die de statische build op / serveert ║
# ╚══════════════════════════════════════════════════════════════════════════╝
# ── Stage 1: frontend dependencies ────────────────────────────────────────────
FROM node:22-alpine AS frontend-deps
WORKDIR /build/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install && npm cache clean --force
# ── Stage 2: frontend bouwen (Vite → dist) ────────────────────────────────────
FROM frontend-deps AS frontend-build
ARG VITE_API_URL=/api
ARG VITE_APP_VERSION=dev
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_APP_VERSION=$VITE_APP_VERSION
COPY frontend/ ./
RUN npm run build
# ── Stage 3: backend dependencies ─────────────────────────────────────────────
FROM node:22-alpine AS backend-deps
WORKDIR /app
COPY backend/package.json backend/package-lock.json* ./
RUN npm install && npm cache clean --force
# ── Stage 4: productie-dependencies (zonder devDependencies) ──────────────────
FROM backend-deps AS backend-prod-deps
RUN npm prune --omit=dev
# ── Stage 5: tests (backend, zonder database) ─────────────────────────────────
FROM backend-deps AS test
WORKDIR /app
ENV NODE_ENV=test
COPY backend/ ./
CMD ["npm", "test"]
# ── Stage 6: development (API + Vite samen, hot reload) ───────────────────────
FROM node:22-alpine AS development
WORKDIR /app
ENV NODE_ENV=development
COPY --from=backend-deps /app/node_modules ./node_modules
COPY --from=frontend-deps /build/frontend/node_modules ./frontend/node_modules
COPY backend/ ./
COPY frontend/ ./frontend/
COPY docker/dev-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
RUN chmod +x /usr/local/bin/dev-entrypoint.sh
# 5173 = Vite dev-server (browser), 3001 = API
EXPOSE 5173 3001
CMD ["/usr/local/bin/dev-entrypoint.sh"]
# ── Stage 7: production (minimale image) ──────────────────────────────────────
FROM node:22-alpine AS production
LABEL maintainer="VibeFinance"
ARG APP_VERSION=dev
ENV NODE_ENV=production
ENV APP_VERSION=$APP_VERSION
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=backend-prod-deps /app/node_modules ./node_modules
COPY backend/package.json ./
COPY backend/src/ ./src/
# De frontend-build wordt door de backend geserveerd (config.STATIC_DIR)
COPY --from=frontend-build /build/frontend/dist ./public/
RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 3001
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD wget -qO- http://localhost:3001/api/health || exit 1
CMD ["node", "src/server.js"]