Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ ENV PRISMA_LOG_LEVEL=info

RUN mkdir -p /challenge-api/reports

CMD ["node","/challenge-api/app.js"]
# Copy entrypoint script and make it executable
COPY docker/entrypoint.sh /entrypoint.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Ensure that the entrypoint.sh script handles errors gracefully, especially during migrations. This is crucial to prevent the container from entering a crash loop if migrations fail.

RUN chmod +x /entrypoint.sh

# Use entrypoint to run migrations at startup (not build time)
# Prisma uses PostgreSQL advisory locks to prevent concurrent migrations
ENTRYPOINT ["/entrypoint.sh"]
22 changes: 22 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
set -e

echo "Starting Challenge API v6..."

# Run database migrations
# Prisma uses PostgreSQL advisory locks to prevent concurrent migrations
# Only one instance will run migrations, others will wait
echo "Running database migrations..."
npx prisma migrate deploy

# Check migration status
if [ $? -eq 0 ]; then
echo "Migrations completed successfully"
else
echo "Migration failed with exit code $?"
exit 1
fi

# Start the application
echo "Starting application server..."
exec node /challenge-api/app.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 design]
Using exec to start the application server is a good practice as it replaces the shell with the node process, ensuring that the process receives signals directly. Ensure that this behavior is intended.