This commit is contained in:
Luke Gustafson
2024-11-27 03:40:00 +00:00
parent 1b2144d7b5
commit 80c45b7519
2 changed files with 38 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Start the backend server in the background # Start the backend server in the background
node server.js & node /backend/server.js &
# Start Nginx in the foreground # Start Nginx in the foreground
nginx -g "daemon off;" nginx -g "daemon off;"

View File

@@ -1,23 +1,55 @@
# Build frontend # Build frontend
FROM node:18-slim AS frontend-build FROM ubuntu:20.04 AS frontend-build
WORKDIR /app WORKDIR /app
# Install Node.js and npm
RUN apt-get update && apt-get install -y \
curl \
gnupg2 \
lsb-release \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean
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 node:18-slim AS backend-build FROM ubuntu:20.04 AS backend-build
WORKDIR /backend WORKDIR /backend
# Install Node.js and npm
RUN apt-get update && apt-get install -y \
curl \
gnupg2 \
lsb-release \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean
COPY backend/package*.json ./ COPY backend/package*.json ./
RUN npm install RUN npm install
COPY backend/ . COPY backend/ .
# Production image # Production image
FROM nginx:alpine FROM ubuntu:20.04
# Install Node.js and nginx
RUN apt-get update && apt-get install -y \
curl \
nginx \
gnupg2 \
lsb-release \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean
# Copy frontend static files to nginx folder # Copy frontend static files to nginx folder
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
# Copy backend application # Copy backend application
COPY --from=backend-build /backend /backend COPY --from=backend-build /backend /backend
# Start backend and frontend servers # Copy entrypoint script
CMD ["sh", "-c", "node /backend/server.js & nginx -g 'daemon off;'"] COPY --from=backend-build /backend/entrypoint.sh /backend/entrypoint.sh
# Make entrypoint.sh executable
RUN chmod +x /backend/entrypoint.sh
# Use entrypoint script to start backend and frontend servers
ENTRYPOINT ["/backend/entrypoint.sh"]