Skip to content

Conversation

@kkartunov
Copy link
Contributor

Running migrations automatically when service starts.


RUN mkdir -p /challenge-api/reports

RUN echo "Running database migrations..."

Choose a reason for hiding this comment

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

[⚠️ performance]
Combining the echo command with the npx prisma migrate deploy command into a single RUN statement can reduce the number of layers in the Docker image, which can improve build performance and reduce image size. Consider using RUN echo "Running database migrations..." && npx prisma migrate deploy.

RUN mkdir -p /challenge-api/reports

RUN echo "Running database migrations..."
RUN npx prisma migrate deploy

Choose a reason for hiding this comment

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

[❗❗ correctness]
Running database migrations automatically when the container starts can lead to potential issues if multiple instances of the container are started simultaneously, as they might attempt to run migrations concurrently. Consider implementing a locking mechanism or ensuring that only one instance handles migrations to avoid race conditions.


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.


# 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.

@kkartunov kkartunov merged commit b829e34 into develop Nov 11, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants