fix(docker): handle missing package-lock.json in npm build | ApprovalToken: 1767139849
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Add conditional check for .web directory and package.json - Fallback to npm install if package-lock.json doesn't exist - Skip npm build gracefully if directory doesn't exist - Fixes npm ci error when reflex export doesn't create lock file
This commit is contained in:
@@ -54,18 +54,24 @@ RUN reflex init --loglevel debug || true && \
|
||||
reflex export --frontend-only --no-zip --loglevel debug || echo "Export completed with warnings"
|
||||
|
||||
# Build frontend with npm (fallback if reflex export fails)
|
||||
WORKDIR /build/.web
|
||||
|
||||
# Configure npm for better reliability
|
||||
RUN npm config set fetch-retry-mintimeout 20000 && \
|
||||
npm config set fetch-retry-maxtimeout 120000 && \
|
||||
npm config set fetch-retries 5 && \
|
||||
npm config set fetch-timeout 300000
|
||||
|
||||
# Install and build
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm ci --prefer-offline --no-audit --loglevel verbose && \
|
||||
npm run build
|
||||
# Check if .web directory exists and has package.json
|
||||
RUN if [ -d "/build/.web" ] && [ -f "/build/.web/package.json" ]; then \
|
||||
echo "Found .web directory with package.json, building frontend..." && \
|
||||
cd /build/.web && \
|
||||
npm config set fetch-retry-mintimeout 20000 && \
|
||||
npm config set fetch-retry-maxtimeout 120000 && \
|
||||
npm config set fetch-retries 5 && \
|
||||
npm config set fetch-timeout 300000 && \
|
||||
if [ -f "package-lock.json" ]; then \
|
||||
npm ci --prefer-offline --no-audit --loglevel verbose; \
|
||||
else \
|
||||
echo "package-lock.json not found, using npm install..." && \
|
||||
npm install --prefer-offline --no-audit --loglevel verbose; \
|
||||
fi && \
|
||||
npm run build; \
|
||||
else \
|
||||
echo "Warning: .web directory or package.json not found, skipping npm build"; \
|
||||
fi
|
||||
|
||||
# ============================================
|
||||
# Stage 2: Runtime (using base image for Node.js)
|
||||
|
||||
Reference in New Issue
Block a user