Skip to content

Commit a291d57

Browse files
authored
Merge pull request #90 from CoolerMinecraft/preview
Preview
2 parents 38de4e5 + b95d637 commit a291d57

18 files changed

Lines changed: 380 additions & 253 deletions

.env.vite.preview

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_SERVER_URL=http://localhost:9902

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ lerna-debug.log*
1010
.env*
1111
!.env.example
1212
!.env.vite.production
13+
!.env.vite.preview
1314
!.env.vite.development
1415
scripts
1516
node_modules

Dockerfile.preview

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Multi-stage build for PFControl v2
2+
FROM node:20-alpine AS builder
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy package files
8+
COPY package*.json ./
9+
10+
# Install ALL dependencies (including dev dependencies for build)
11+
RUN npm ci --legacy-peer-deps && npm cache clean --force
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Copy frontend env for Vite build
17+
COPY .env.vite.preview .env.preview
18+
19+
# Build the backend (TypeScript compilation)
20+
RUN npm run build:server
21+
22+
# Build the application (frontend)
23+
RUN npm run build
24+
25+
# Production stage
26+
FROM node:20-alpine AS production
27+
28+
# Install dumb-init for proper signal handling
29+
RUN apk add --no-cache dumb-init
30+
31+
# Create app user for security
32+
RUN addgroup -g 1001 -S nodejs && \
33+
adduser -S nodeuser -u 1001
34+
35+
# Set working directory
36+
WORKDIR /app
37+
38+
# Copy package files
39+
COPY package*.json ./
40+
41+
# Install only production dependencies
42+
RUN npm ci --omit=dev --legacy-peer-deps && npm cache clean --force
43+
44+
# Set NODE_ENV explicitly
45+
ENV NODE_ENV=production
46+
47+
# Copy built application from builder stage
48+
COPY --from=builder --chown=nodeuser:nodejs /app/dist ./dist
49+
COPY --from=builder --chown=nodeuser:nodejs /app/public ./public
50+
COPY --from=builder --chown=nodeuser:nodejs /app/server/dist ./server/dist
51+
COPY --from=builder --chown=nodeuser:nodejs /app/server/data ./server/data
52+
COPY --from=builder --chown=nodeuser:nodejs /app/server/data ./server/dist/data
53+
54+
# Create logs directory
55+
RUN mkdir -p logs && chown nodeuser:nodejs logs
56+
57+
# Switch to non-root user
58+
USER nodeuser
59+
60+
# Expose port
61+
EXPOSE 9902
62+
63+
# Health check
64+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
65+
CMD node -e "require('http').get('http://localhost:9902/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
66+
# Start the application
67+
ENTRYPOINT ["dumb-init", "--"]
68+
CMD ["node", "server/dist/main.js"]

docker-compose.preview.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.8'
2+
3+
services:
4+
pfcontrol:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "9902:9902"
10+
environment:
11+
- NODE_ENV=production
12+
env_file:
13+
- .env.preview
14+
volumes:
15+
- ./logs:/app/logs
16+
restart: unless-stopped
17+
networks:
18+
- pfcontrol-network
19+
20+
networks:
21+
pfcontrol-network:
22+
driver: bridge
812 KB
Loading
2.46 MB
Loading
1.81 MB
Loading
955 KB
Loading
435 KB
Loading
1.53 MB
Loading

0 commit comments

Comments
 (0)