From ae64c7741873b4e85c25961a032eb8a1f8a7b533 Mon Sep 17 00:00:00 2001 From: Wenjing Yu Date: Sun, 6 Jul 2025 23:46:49 -0700 Subject: [PATCH] fix docker build for db update --- Dockerfile | 18 +++++++----------- docker-entrypoint.sh | 6 +++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index e2649ae..e3ee861 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,27 +19,23 @@ ENV FORGE_DEBUG_LOGGING=${ARG_DEBUG_LOGGING} # Install system dependencies including PostgreSQL client and gosu for user privilege management RUN apt-get update && apt-get install -y \ postgresql-client \ - gosu \ && rm -rf /var/lib/apt/lists/* -# Create logs directory -RUN mkdir -p /app/logs +RUN mkdir -p /app/logs && \ + chown -R nobody:nogroup /app/logs && \ + chmod -R 777 /app/logs # Copy project files COPY . . -# Copy entrypoint script and make it executable -COPY docker-entrypoint.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/docker-entrypoint.sh - # Install dependencies using pip -RUN pip install -e ".[dev]" +RUN pip install -e . + +# Switch to non-root user for security +USER nobody # Expose port EXPOSE 8000 -# Set the entrypoint to our script -ENTRYPOINT ["docker-entrypoint.sh"] - # Run the application (this command is passed to the entrypoint) CMD ["gunicorn", "app.main:app", "-k", "uvicorn.workers.UvicornWorker", "--workers", "10", "--bind", "0.0.0.0:8000"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index eca0be9..9991c1a 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,7 +8,11 @@ set -e chown -R nobody:nogroup /app/logs # Run Alembic migrations -alembic upgrade head +echo "Running database migrations..." +if ! alembic upgrade head; then + echo "⚠️ Warning: Alembic migration failed. Continuing without shutdown." +fi # Use gosu to drop from root to the 'nobody' user and run the main command exec gosu nobody "$@" +