Files
replypier/Dockerfile.frontend.prod
T

64 lines
2.0 KiB
Docker
Raw Normal View History

# Build stage
FROM node:22-slim AS builder
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
wget \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy package files first
COPY frontend/package*.json ./
# Copy frontend source code
COPY frontend/ .
# Install dependencies with legacy peer deps
RUN npm install
# Build the application, widget, and webclient. Use the :prod webclient build so
# the shipped loader bakes the production fallback URL (the real backend URL is
# resolved at runtime via window.replypierBaseUrl / APP_CONFIG regardless).
RUN npm run build-only && \
npm run build:widgetdocker && \
npm run build:webclient:prod && \
if [ ! -f dist/index.html ]; then \
echo "<!DOCTYPE html><html><head><meta charset='utf-8'><title>ReplyPier</title><link rel='icon' href='/favicon.ico'></head><body><div id='app'></div><script type='module' src='/src/main.ts'></script></body></html>" > dist/index.html; \
fi
# Production stage
FROM nginx:alpine
# Remove default nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy the built files to nginx
COPY --from=builder /app/dist/ /usr/share/nginx/html/
# Also serve the docker-built widget (widget.js/widget.css). build:widgetdocker
# emits these to /app/backend-assets; without this they are discarded and a
# frontend-served widget (VITE_WIDGET_URL -> frontend) falls back to the stale
# checked-in bundle. Fixed filenames, so this won't clobber hashed dashboard assets.
COPY --from=builder /app/backend-assets/ /usr/share/nginx/html/assets/
# Copy nginx configuration
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
# Copy entrypoint script
COPY frontend/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
# Expose port
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost/ || exit 1
# Use entrypoint script
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]