-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (85 loc) · 3.69 KB
/
Dockerfile
File metadata and controls
109 lines (85 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# =============================================================================
# Multi-stage Dockerfile for React Admin UI
# =============================================================================
# -----------------------------------------------------------------------------
# Base stage - Common setup for all stages
# -----------------------------------------------------------------------------
FROM node:20-alpine AS base
WORKDIR /app
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S reactuser -u 1001 -G nodejs
# -----------------------------------------------------------------------------
# Dependencies stage - Install all dependencies
# -----------------------------------------------------------------------------
FROM base AS dependencies
COPY package*.json ./
RUN npm ci --include=dev && npm cache clean --force
# -----------------------------------------------------------------------------
# Development stage - For local development with hot reload
# -----------------------------------------------------------------------------
FROM dependencies AS development
# Copy application code
# Note: In development, mount code as volume: docker run -v ./:/app
COPY --chown=reactuser:nodejs . .
# Switch to non-root user
USER reactuser
# Expose port
EXPOSE 3000
# Use dumb-init and start development server
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "run", "dev"]
# -----------------------------------------------------------------------------
# Build stage - Build the React application
# -----------------------------------------------------------------------------
FROM dependencies AS build
# Copy source code
COPY . .
# Build for production
ENV NODE_ENV=production
RUN npm run build
# -----------------------------------------------------------------------------
# Production stage - Serve with Nginx
# -----------------------------------------------------------------------------
FROM nginx:1.27-alpine AS production
# Install wget for healthcheck and gettext for envsubst
RUN apk add --no-cache wget gettext
# Copy custom nginx config as template (will be processed by entrypoint)
COPY nginx.conf /etc/nginx/conf.d/default.conf.template
# Copy entrypoint script
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
# Copy built application from build stage
COPY --from=build /app/build /usr/share/nginx/html
# Create non-root user for nginx
RUN addgroup -g 1001 -S nginx-app && \
adduser -S nginx-app -u 1001 -G nginx-app && \
chown -R nginx-app:nginx-app /usr/share/nginx/html && \
chown -R nginx-app:nginx-app /var/cache/nginx && \
chown -R nginx-app:nginx-app /var/log/nginx && \
chown -R nginx-app:nginx-app /etc/nginx/conf.d && \
touch /var/run/nginx.pid && \
chown -R nginx-app:nginx-app /var/run/nginx.pid
# Switch to non-root user
USER nginx-app
# Expose port
EXPOSE 8080
# Environment variable for BFF URL (can be overridden at runtime)
ENV BFF_URL=http://localhost:8014
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080 || exit 1
# Use entrypoint script for env substitution, then start nginx
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
# Labels for better image management and security scanning
LABEL maintainer="xshopai Team"
LABEL service="admin-ui"
LABEL version="1.0.0"
LABEL org.opencontainers.image.source="https://github.com/xshopai/xshopai"
LABEL org.opencontainers.image.description="Admin UI for xshopai platform"
LABEL org.opencontainers.image.vendor="xshopai"
LABEL framework="react"
LABEL language="javascript"