This commit is contained in:
mukesh13
2025-06-25 10:08:02 +05:30
parent e191a7251d
commit 5ce138bfc8

View File

@ -1,49 +1,55 @@
# syntax=docker/dockerfile:1.4
# syntax=docker/dockerfile:1
FROM node:18-alpine AS development
### Base Image ###
FROM node:18-alpine AS base
### Dependencies Stage ###
FROM base AS deps
# Use default Alpine mirror (or Tsinghua if preferred)
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \
echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \
apk update --no-cache && \
apk add --no-cache vips-dev
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache python make g++ \
&& apk add vips-dev fftw-dev build-base \
--update-cache \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/community \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/main \
&& rm -fR /var/cache/apk/*
# Copy package files
COPY package.json package-lock.json ./
# Enforce prebuilt sharp binaries
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=true
RUN npm ci
# Install dependencies
RUN npm ci --legacy-peer-deps
### Builder Stage ###
FROM base AS builder
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \
echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \
apk update --no-cache && \
apk add --no-cache vips-dev
# Copy source code
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV CI=true
ENV PORT=3000
CMD ["npm", "start"]
# Build stage
FROM development AS build
RUN npm run build
# Production stage
FROM nginx:alpine AS production
### Production Runner Stage ###
FROM nginx:alpine AS runner
WORKDIR /usr/share/nginx/html
# Remove default nginx files
# Set permissions for default nginx user
RUN mkdir -p /var/cache/nginx /var/run/nginx && \
chown -R nginx:nginx /var/cache/nginx /var/run/nginx /usr/share/nginx/html && \
chmod -R 755 /var/cache/nginx /var/run/nginx /usr/share/nginx/html
# Remove default Nginx assets
RUN rm -rf ./*
# Copy built app
COPY --from=build /app/build .
# Copy nginx config if it exists
COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf
# Copy static assets from builder
COPY --from=builder --chown=nginx:nginx /app/public .
# Expose port
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
# Healthcheck
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80 || exit 1
# Run Nginx
CMD ["nginx", "-g", "daemon off;"]