Updated conection process to work hopfully with docker.

This commit is contained in:
Karmaa
2025-03-05 16:15:51 -06:00
parent 713d43fc52
commit e800064f05
6 changed files with 52 additions and 45 deletions

View File

@@ -1,32 +1,39 @@
# Build everything in one stage
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
# Install nginx and dependencies
RUN apk add --no-cache nginx npm
# Set working directory
# Stage 1: Build frontend
FROM --platform=$BUILDPLATFORM node:18-alpine AS frontend-builder
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm install
# Copy the entire project (frontend and backend)
COPY ./ ./
# Build the frontend
COPY . .
RUN npm run build
# Stage 2: Build backend
FROM --platform=$BUILDPLATFORM node:18-alpine AS backend-builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY src/backend/ ./src/backend/
# Stage 3: Final production image
FROM node:18-alpine
RUN apk add --no-cache nginx
# Configure nginx
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=frontend-builder /app/dist /usr/share/nginx/html
# Copy built frontend to nginx's web directory
COPY ./dist /usr/share/nginx/html
# Copy backend
COPY --from=backend-builder /app/node_modules ./node_modules
COPY --from=backend-builder /app/src/backend ./src/backend
# Expose necessary ports
EXPOSE 8080
EXPOSE 8081
# Create separate directories for nginx and node
RUN mkdir -p /var/log/nginx && \
mkdir -p /var/lib/nginx && \
chown -R nginx:nginx /var/log/nginx /var/lib/nginx
# Use entrypoint.sh to run both the backend and nginx
RUN chmod +x /app/src/backend/entrypoint.sh
ENTRYPOINT ["/app/src/backend/entrypoint.sh"]
# Expose ports
EXPOSE 8080 8081
# Use a start script to run both services
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]

10
docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
# Start NGINX in background
nginx -g "daemon off;" &
# Start Node.js backend
node src/backend/index.js
# Keep container running
wait

View File

@@ -21,17 +21,16 @@ http {
# Proxy IO requests
location /socket.io/ {
proxy_pass http://0.0.0.0:8081;
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
# CORS settings
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' '*';
add_header 'Access-Control-Allow-Headers' '*';
# Timeout settings
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
# Error pages