Commit
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Start the backend server in the background
|
|
||||||
|
# Start the backend server
|
||||||
node /backend/server.js &
|
node /backend/server.js &
|
||||||
# Start Nginx in the foreground
|
|
||||||
nginx -g "daemon off;"
|
# Start nginx in the foreground
|
||||||
|
nginx -g 'daemon off;'
|
||||||
@@ -1,40 +1,27 @@
|
|||||||
# Build frontend
|
# Build frontend
|
||||||
FROM ubuntu:20.04 AS frontend-build
|
FROM node:18-alpine AS frontend-build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Install Node.js
|
|
||||||
RUN apt-get update && apt-get install -y curl && \
|
|
||||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
|
||||||
apt-get install -y nodejs && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
COPY frontend/package*.json ./frontend/
|
COPY frontend/package*.json ./frontend/
|
||||||
RUN npm --prefix frontend install
|
RUN npm --prefix frontend install
|
||||||
COPY frontend/ ./frontend/
|
COPY frontend/ ./frontend/
|
||||||
RUN npm --prefix frontend run build
|
RUN npm --prefix frontend run build
|
||||||
|
|
||||||
# Build backend
|
# Build backend
|
||||||
FROM ubuntu:20.04 AS backend-build
|
FROM node:18-alpine AS backend-build
|
||||||
WORKDIR /backend
|
WORKDIR /backend
|
||||||
# Install Node.js
|
|
||||||
RUN apt-get update && apt-get install -y curl && \
|
|
||||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
|
||||||
apt-get install -y nodejs && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
COPY backend/package*.json ./
|
COPY backend/package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY backend/ .
|
COPY backend/ .
|
||||||
|
|
||||||
# Production image
|
# Production image using nginx:alpine
|
||||||
FROM ubuntu:20.04
|
FROM nginx:alpine
|
||||||
# Install Node.js and Nginx
|
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
RUN apt-get update && apt-get install -y curl nginx && \
|
|
||||||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
|
|
||||||
apt-get install -y nodejs && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
# Copy frontend and backend
|
|
||||||
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
||||||
COPY --from=backend-build /backend /backend
|
COPY --from=backend-build /backend /backend
|
||||||
# Copy entrypoint script
|
COPY --from=backend-build /backend/entrypoint.sh /backend/entrypoint.sh
|
||||||
COPY backend/entrypoint.sh /backend/entrypoint.sh
|
|
||||||
|
# Make entrypoint.sh executable
|
||||||
RUN chmod +x /backend/entrypoint.sh
|
RUN chmod +x /backend/entrypoint.sh
|
||||||
# Start backend and frontend servers using entrypoint script
|
|
||||||
CMD ["/backend/entrypoint.sh"]
|
# Use entrypoint script to start backend and frontend servers
|
||||||
|
ENTRYPOINT ["/backend/entrypoint.sh"]
|
||||||
@@ -7,7 +7,7 @@ server {
|
|||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
# Frontend routes
|
# Frontend routes (SPA)
|
||||||
location / {
|
location / {
|
||||||
try_files $uri /index.html;
|
try_files $uri /index.html;
|
||||||
}
|
}
|
||||||
@@ -19,5 +19,13 @@ server {
|
|||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_redirect off; # Disable automatic redirects by the backend (if any)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optional: Custom error handling
|
||||||
|
error_page 404 /404.html;
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user