This commit is contained in:
Luke Gustafson
2024-11-27 03:55:53 +00:00
parent 3ee91ed963
commit 8e6923b7a0
3 changed files with 25 additions and 28 deletions

View File

@@ -1,40 +1,27 @@
# Build frontend
FROM ubuntu:20.04 AS frontend-build
FROM node:18-alpine AS frontend-build
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/
RUN npm --prefix frontend install
COPY frontend/ ./frontend/
RUN npm --prefix frontend run build
# Build backend
FROM ubuntu:20.04 AS backend-build
FROM node:18-alpine AS backend-build
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 ./
RUN npm install
COPY backend/ .
# Production image
FROM ubuntu:20.04
# Install Node.js and Nginx
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
# Production image using nginx:alpine
FROM nginx:alpine
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
COPY --from=backend-build /backend /backend
# Copy entrypoint script
COPY backend/entrypoint.sh /backend/entrypoint.sh
COPY --from=backend-build /backend/entrypoint.sh /backend/entrypoint.sh
# Make entrypoint.sh executable
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"]

View File

@@ -7,7 +7,7 @@ server {
root /usr/share/nginx/html;
index index.html;
# Frontend routes
# Frontend routes (SPA)
location / {
try_files $uri /index.html;
}
@@ -19,5 +19,13 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
}
}