2025-07-11 14:16:34 +01:00
|
|
|
# Frontend Dockerfile - React/Vite application
|
|
|
|
FROM node:20-alpine AS build
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy package files
|
2025-07-16 23:09:26 +01:00
|
|
|
COPY frontend/package*.json ./
|
2025-07-11 14:16:34 +01:00
|
|
|
|
2025-08-26 13:46:15 +01:00
|
|
|
# Install dependencies (uses .npmrc secret if available, otherwise anonymous)
|
|
|
|
RUN --mount=type=secret,id=npmrc \
|
|
|
|
set -e && \
|
|
|
|
if [ -s /run/secrets/npmrc ]; then \
|
|
|
|
echo "Using authenticated npm registry" && \
|
|
|
|
echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \
|
|
|
|
else \
|
|
|
|
echo "Using anonymous npm registry (no token provided)"; \
|
|
|
|
fi && \
|
|
|
|
npm ci --loglevel=warn && \
|
|
|
|
rm -f /root/.npmrc
|
2025-07-11 14:16:34 +01:00
|
|
|
|
|
|
|
# Copy source code
|
2025-07-16 23:09:26 +01:00
|
|
|
COPY frontend .
|
2025-07-11 14:16:34 +01:00
|
|
|
|
2025-08-26 13:46:15 +01:00
|
|
|
# Build the application (uses .npmrc secret if available, otherwise anonymous)
|
|
|
|
RUN --mount=type=secret,id=npmrc \
|
|
|
|
set -e && \
|
|
|
|
if [ -s /run/secrets/npmrc ]; then \
|
|
|
|
echo "Using authenticated npm registry for build" && \
|
|
|
|
echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \
|
|
|
|
else \
|
|
|
|
echo "Using anonymous npm registry for build (no token provided)"; \
|
|
|
|
fi && \
|
|
|
|
npm run build && \
|
|
|
|
rm -f /root/.npmrc
|
2025-07-11 14:16:34 +01:00
|
|
|
|
|
|
|
# Production stage
|
|
|
|
FROM nginx:alpine
|
|
|
|
|
|
|
|
# Copy built files from build stage
|
|
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
|
|
|
|
# Copy nginx configuration and entrypoint
|
2025-07-16 23:09:26 +01:00
|
|
|
COPY docker/frontend/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
COPY docker/frontend/entrypoint.sh /entrypoint.sh
|
2025-07-11 14:16:34 +01:00
|
|
|
|
|
|
|
# Make entrypoint executable
|
|
|
|
RUN chmod +x /entrypoint.sh
|
|
|
|
|
|
|
|
# Expose port 80 (standard HTTP port)
|
|
|
|
EXPOSE 80
|
|
|
|
|
|
|
|
# Environment variables for flexibility
|
2025-07-18 14:19:36 +01:00
|
|
|
ENV VITE_API_BASE_URL=http://backend:8080
|
2025-07-11 14:16:34 +01:00
|
|
|
|
|
|
|
# Use custom entrypoint
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|