diff --git a/Dockerfile b/Dockerfile index 27478ba..4def5a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,33 @@ -# syntax=docker/dockerfile:1.4 +# Create this base image once and reuse +# docker build -f Dockerfile.base -t my-node-base . -# Use Alpine for smaller size and faster package manager -FROM node:lts-alpine AS development +# === Dockerfile.base (build once) === +# FROM node:18-alpine +# RUN apk add --no-cache python3 make g++ vips-dev +# WORKDIR /app -WORKDIR /app - -# Install dependencies using apk (much faster than apt) -RUN --mount=type=cache,target=/var/cache/apk \ - apk add --update --no-cache \ - vips-dev \ - python3 \ - make \ - g++ +# === Main Dockerfile (super fast) === +FROM my-node-base AS development # Copy package files COPY package.json package-lock.json ./ -# Install npm dependencies with cache +# Install deps with cache RUN --mount=type=cache,target=/root/.npm \ - npm ci --legacy-peer-deps --ignore-scripts - -# Install sharp -RUN --mount=type=cache,target=/root/.npm \ - npm install --platform=linux --arch=x64 sharp + npm ci --legacy-peer-deps +# Copy source COPY . . -ENV CI=true -ENV PORT=3000 - -CMD [ "npm", "start" ] +ENV CI=true PORT=3000 +CMD ["npm", "start"] # Build stage FROM development AS build RUN npm run build -# Development with tools -FROM development as dev-envs - -RUN --mount=type=cache,target=/var/cache/apk \ - apk add --no-cache git - -RUN adduser -D -s /bin/sh vscode && \ - addgroup docker && \ - addgroup vscode docker - -COPY --from=gloursdocker/docker / / -CMD [ "npm", "start" ] - # Production -FROM nginx:alpine AS production - +FROM nginx:alpine COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf -WORKDIR /usr/share/nginx/html -RUN rm -rf ./* -COPY --from=build /app/build . - +COPY --from=build /app/build /usr/share/nginx/html ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file