From 4579bae52e32fc99da030343abd2becb53f5bc4b Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Sat, 20 Sep 2025 23:45:33 +0200 Subject: [PATCH] Fix jwt-token --- server/Dockerfile | 39 ++++++++++---------------------- server/scripts/setup-database.js | 3 +-- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index d170f51..a23f820 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,14 +1,17 @@ # Backend Dockerfile for Drone Detection System FROM node:18-alpine AS base -# Install system dependencies +# Install system dependencies and create user in one layer RUN apk add --no-cache \ python3 \ make \ g++ \ curl \ dumb-init \ - netcat-openbsd + netcat-openbsd \ + su-exec && \ + addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 # Set working directory WORKDIR /app @@ -20,33 +23,15 @@ COPY package*.json ./ RUN npm install --only=production && \ npm cache clean --force -# Copy application code -# Copy application code -COPY --chown=nodejs:nodejs . . - -# Copy and set permissions for entrypoint script -COPY docker-entrypoint.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/docker-entrypoint.sh - -# Install su-exec for user switching -RUN apk add --no-cache su-exec - -# Create logs and uploads directories +# 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/ -# Create non-root user -RUN addgroup -g 1001 -S nodejs && \ - adduser -S nodejs -u 1001 - -# Set ownership of all app files including uploads -RUN chown -R nodejs:nodejs /app - -# Ensure uploads directory has proper permissions -RUN chmod -R 755 /app/uploads - -# Copy and set permissions for entrypoint script -COPY docker-entrypoint.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# 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) diff --git a/server/scripts/setup-database.js b/server/scripts/setup-database.js index 33e5b97..c0989a8 100644 --- a/server/scripts/setup-database.js +++ b/server/scripts/setup-database.js @@ -1,5 +1,4 @@ -const { Sequelize } = re // Models are already initialized through the imports - console.log('📋 Models loaded and ready...');ire('sequelize'); +const { Sequelize } = require('sequelize'); const bcrypt = require('bcryptjs'); // Import models from the main models index