51 lines
1.3 KiB
Docker
51 lines
1.3 KiB
Docker
# Backend Dockerfile for Drone Detection System
|
|
FROM node:18-alpine AS base
|
|
|
|
# Install system dependencies and create user in one layer
|
|
RUN apk add --no-cache \
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
curl \
|
|
dumb-init \
|
|
netcat-openbsd \
|
|
su-exec && \
|
|
addgroup -g 1001 -S nodejs && \
|
|
adduser -S nodejs -u 1001
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm install --only=production && \
|
|
npm cache clean --force
|
|
|
|
# Create directories and copy files with proper ownership in one step
|
|
RUN mkdir -p logs uploads/logos
|
|
COPY --chown=nodejs:nodejs . .
|
|
COPY --chown=root:root docker-entrypoint.sh /usr/local/bin/
|
|
|
|
# Set all permissions in one layer
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
|
|
chmod -R 755 /app/uploads && \
|
|
chown -R nodejs:nodejs /app
|
|
|
|
# Stay as root for the entrypoint (it will switch to nodejs user)
|
|
# USER nodejs (commented out - entrypoint will handle user switching)
|
|
|
|
# Expose port
|
|
EXPOSE 3001
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:3001/api/health || exit 1
|
|
|
|
# Use custom entrypoint that handles permissions and user switching
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
|
|
# Start the application
|
|
CMD ["npm", "start"]
|