diff --git a/docker/Dockerfile b/docker/Dockerfile index 82f737e..35e991c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 +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"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..75890e6 --- /dev/null +++ b/docker/entrypoint.sh @@ -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