WeightTracker/Dockerfile

51 lines
1.5 KiB
Docker

# Multi-stage build for smaller final image
FROM node:18-alpine AS base
# Install dependencies for the data API
WORKDIR /app
COPY package*.json ./
RUN npm install --production
# Build stage for the web application
FROM node:18-alpine AS web-builder
WORKDIR /app
# Copy all application files
COPY . .
# Final stage
FROM nginx:alpine
# Create directory for persistent data storage
RUN mkdir -p /data && chmod -R 755 /data
# Install Node.js for the data API
RUN apk add --no-cache nodejs npm supervisor
# Copy the static website files to the Nginx serving directory
COPY --from=web-builder /app /usr/share/nginx/html
# Copy the Node.js dependencies and API scripts
COPY --from=base /app/node_modules /usr/share/nginx/api/node_modules
COPY data-api.js /usr/share/nginx/api/
COPY backup-s3.js /usr/share/nginx/api/
COPY auth-middleware.js /usr/share/nginx/api/
COPY login.html /usr/share/nginx/api/
COPY inject-password-hash.js /usr/share/nginx/api/
# Copy a custom Nginx configuration that includes the data API proxy
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy supervisor configuration
COPY supervisord.conf /etc/supervisord.conf
# Clean up unnecessary files from the HTML directory
RUN cd /usr/share/nginx/html && \
rm -rf node_modules Dockerfile docker-compose.yml nginx.conf supervisord.conf data-api.js package*.json .git* .vscode
# Expose port 80
EXPOSE 80
# Start supervisor which will manage both Nginx and Node.js
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]