diff --git a/Dockerfile b/Dockerfile index 7a6adbd..a748943 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get update \ libpq-dev \ gettext \ curl \ + gosu \ && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* @@ -39,11 +40,13 @@ RUN groupadd -r django && useradd -r -g django django COPY . /app/ -# Create directories that need write permissions +# Create directories that need write permissions RUN mkdir -p /app/staticfiles /app/media && \ + chmod -R 755 /app/staticfiles /app/media && \ chown -R django:django /app -USER django +# Don't switch to django user yet - let entrypoint handle permissions +# USER django EXPOSE 8000 diff --git a/docker-compose.dokploy.yml b/docker-compose.dokploy.yml index 83ba38c..580257a 100644 --- a/docker-compose.dokploy.yml +++ b/docker-compose.dokploy.yml @@ -8,7 +8,7 @@ services: /app/entrypoint.sh && gunicorn --bind 0.0.0.0:8000 --workers 3 django_project.wsgi:application" volumes: - - "../files/static:/app/staticfiles" + - "../files/staticfiles:/app/staticfiles" - "../files/media:/app/media" expose: - 8000 diff --git a/entrypoint.sh b/entrypoint.sh index a58ed26..0570995 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,6 +5,12 @@ set -e echo "Waiting for PostgreSQL..." sleep 5 +echo "Setting up directories and permissions..." +# Create directories and set proper permissions +mkdir -p /app/staticfiles /app/media +chown -R django:django /app/staticfiles /app/media +chmod -R 755 /app/staticfiles /app/media + echo "Running migrations..." python manage.py migrate --noinput @@ -15,8 +21,8 @@ echo "Setting up social applications..." python manage.py setup_social_apps echo "Collecting static files..." -# Ensure static directories exist with proper permissions -mkdir -p /app/staticfiles /app/media python manage.py collectstatic --noinput -exec "$@" \ No newline at end of file +echo "Switching to django user and starting application..." +# Switch to django user for the main application +exec gosu django "$@" \ No newline at end of file