Simplify Dockerfile.browser to 2-stage build (#969)
Consolidates the browser mode Docker build from 3 stages to 2 by removing the redundant intermediate `deps` stage and cleaning dev dependencies in-place after build. ## Changes - **Stage 1 (builder)**: Install all deps → build → remove dev deps with `yarn install --production` - **Stage 2 (production)**: Copy built artifacts and production node_modules from builder (previously split across builder + deps stages) **Before:** ```dockerfile # Stage 1: Build RUN yarn install --frozen-lockfile RUN yarn build:server # Stage 2: Production dependencies COPY --from=builder /build/package.json /build/yarn.lock ./ RUN yarn install --production --frozen-lockfile # Stage 3: Production COPY --from=builder /build/dist ./dist COPY --from=deps /deps/node_modules ./node_modules ``` **After:** ```dockerfile # Stage 1: Build and prepare production dependencies RUN yarn install --frozen-lockfile RUN yarn build:server RUN yarn install --production --frozen-lockfile # Stage 2: Production COPY --from=builder /build/dist ./dist COPY --from=builder /build/node_modules ./node_modules ``` No functional changes to final image; eliminates redundant package resolution and copying. <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > simplify the Dockerfile browser build, install dependencies and build in the first stage, after the build remove the dev dependency </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/thomasnordquist/MQTT-Explorer/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thomasnordquist <7721625+thomasnordquist@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Multi-stage build for MQTT Explorer Browser Mode
|
# Multi-stage build for MQTT Explorer Browser Mode
|
||||||
# Stage 1: Build
|
# Stage 1: Build and prepare production dependencies
|
||||||
FROM node:24-alpine AS builder
|
FROM node:24-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
@@ -18,20 +18,12 @@ RUN yarn install --frozen-lockfile --network-timeout 100000
|
|||||||
# Build the application (compiles TypeScript and webpack bundles)
|
# Build the application (compiles TypeScript and webpack bundles)
|
||||||
RUN yarn build:server
|
RUN yarn build:server
|
||||||
|
|
||||||
# Stage 2: Production dependencies
|
# Remove dev dependencies, keeping only production dependencies
|
||||||
FROM node:24-alpine AS deps
|
|
||||||
|
|
||||||
WORKDIR /deps
|
|
||||||
|
|
||||||
# Copy only package files
|
|
||||||
COPY --from=builder /build/package.json /build/yarn.lock ./
|
|
||||||
|
|
||||||
# Install ONLY production dependencies
|
|
||||||
RUN yarn install --production --frozen-lockfile --network-timeout 100000 && \
|
RUN yarn install --production --frozen-lockfile --network-timeout 100000 && \
|
||||||
yarn cache clean && \
|
yarn cache clean && \
|
||||||
rm -rf /tmp/*
|
rm -rf /tmp/*
|
||||||
|
|
||||||
# Stage 3: Production
|
# Stage 2: Production
|
||||||
FROM node:24-alpine
|
FROM node:24-alpine
|
||||||
|
|
||||||
# Install dumb-init in a single layer
|
# Install dumb-init in a single layer
|
||||||
@@ -50,8 +42,8 @@ COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/dist ./dist
|
|||||||
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/build ./app/build
|
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/build ./app/build
|
||||||
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/index.html ./app/
|
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/index.html ./app/
|
||||||
|
|
||||||
# Copy runtime node_modules (minimal set)
|
# Copy runtime node_modules (production dependencies only)
|
||||||
COPY --from=deps --chown=mqttexplorer:mqttexplorer /deps/node_modules ./node_modules
|
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/node_modules ./node_modules
|
||||||
|
|
||||||
# Copy package.json for version info (needed by server)
|
# Copy package.json for version info (needed by server)
|
||||||
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/package.json ./
|
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/package.json ./
|
||||||
|
|||||||
Reference in New Issue
Block a user