Major improvements: multi-stage Docker, security hardening, host metrics, tests
- Multi-stage Docker build: Dockerfile compiles frontend (Node.js) and backend (Gradle) inside Docker; no local Java/Node.js required - Security hardening: replaced full host root mount with specific directory mounts (/proc, /sys, /etc, /var, /home, /opt, /tmp, /srv, /usr) - Host metrics consistency: LinuxMemoryService and CpuDetailsService now read from /host/proc instead of container OSHI - Concurrency: replaced synchronized with AtomicReference in 3 services - Global error handling: added @RestControllerAdvice for JSON error responses - Unit tests: added 32 tests for /proc parsers, CPU usage, process uptime - Docker security: non-root user, read-only FS, no-new-privileges, healthcheck - Debug logging: added log.debug() in silent catch blocks - Documentation: updated README, INSTALLATION, DEVELOPMENT, CONFIGURATION, ARCHITECTURE, CHANGELOG Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
+29
-1
@@ -1,6 +1,34 @@
|
||||
|
||||
# Stage 1: Build frontend with Node.js
|
||||
FROM node:22-alpine AS frontend
|
||||
WORKDIR /frontend
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY frontend/ ./
|
||||
RUN npm run build -- --configuration production
|
||||
|
||||
# Stage 2: Build backend with Gradle
|
||||
FROM eclipse-temurin:21-jdk AS builder
|
||||
WORKDIR /app
|
||||
COPY backend/build.gradle backend/settings.gradle ./
|
||||
COPY backend/gradlew ./
|
||||
COPY backend/gradle/ gradle/
|
||||
COPY backend/src/ src/
|
||||
# Copy built frontend assets into Spring static resources
|
||||
COPY --from=frontend /frontend/dist/frontend/browser src/main/resources/static/
|
||||
RUN chmod +x gradlew && SKIP_FRONTEND=true ./gradlew bootJar --no-daemon
|
||||
|
||||
# Stage 3: Runtime image
|
||||
FROM eclipse-temurin:21-jre
|
||||
WORKDIR /app
|
||||
COPY backend/build/libs/backend-0.0.1-SNAPSHOT.jar app.jar
|
||||
COPY --from=builder /app/build/libs/backend-0.0.1-SNAPSHOT.jar app.jar
|
||||
|
||||
RUN adduser --disabled-password --no-create-home appuser && \
|
||||
chown appuser:appuser /app
|
||||
USER appuser
|
||||
|
||||
EXPOSE 8080
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD wget -q --spider http://localhost:8080/api/system/metrics || exit 1
|
||||
|
||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||
Reference in New Issue
Block a user