feat(staging): optimize staging build with local Maven packaging

- Add server/Dockerfile.dev for fast local builds (JRE-only, ~70MB)
- Modify staging target to build JAR locally before Docker image
- Update .dockerignore to allow target/ directory for Dockerfile.dev
- Build time reduced from 17+ minutes to ~4 seconds
- Reuses local Maven cache (~/.m2/repository) instead of downloading in Docker
This commit is contained in:
wowo-zZ 2026-03-14 14:21:06 +08:00
parent 5254cd155e
commit 5581bd6f06
3 changed files with 26 additions and 3 deletions

View file

@ -178,8 +178,9 @@ validate-release-config: ## 校验发布环境变量文件(默认 .env.release
./scripts/validate-release-config.sh .env.release
staging: ## 构建并启动 staging 环境,运行 smoke test混合模式后端镜像 + 前端静态文件)
@echo "=== [1/5] Building backend Docker image ==="
docker build -t $(STAGING_SERVER_IMAGE) -f server/Dockerfile server
@echo "=== [1/5] Building backend JAR and Docker image ==="
cd server && ./mvnw package -DskipTests -B -q
docker build -t $(STAGING_SERVER_IMAGE) -f server/Dockerfile.dev server
@echo "=== [2/5] Building frontend static files ==="
cd web && pnpm run build
@echo "=== [3/5] Starting dependency services ==="

View file

@ -1,4 +1,7 @@
**/target/
# Exclude target for multi-stage build (Dockerfile)
# But allow it for runtime build (Dockerfile.runtime) which needs pre-built JAR
# **/target/
**/.idea/
**/*.iml
.git/

19
server/Dockerfile.dev Normal file
View file

@ -0,0 +1,19 @@
# Development Dockerfile
# Expects pre-built JAR at skillhub-app/target/*.jar
# Used by: make staging (local development workflow)
FROM eclipse-temurin:21-jre-alpine
RUN addgroup -S app && adduser -S app -G app
WORKDIR /app
# Copy pre-built JAR from local build (relative to server/ directory)
COPY ./skillhub-app/target/*.jar app.jar
RUN chown -R app:app /app
USER app
EXPOSE 8080
HEALTHCHECK --interval=10s --timeout=3s \
CMD wget -qO- http://localhost:8080/actuator/health || exit 1
ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75.0", "-jar", "app.jar"]