diff --git a/backend/services/admin-service/Dockerfile b/backend/services/admin-service/Dockerfile index 2a08ef4d..c7f96920 100644 --- a/backend/services/admin-service/Dockerfile +++ b/backend/services/admin-service/Dockerfile @@ -52,10 +52,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -63,8 +74,8 @@ USER nestjs EXPOSE 3010 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3010/api/v1/health || exit 1 -# Start service -CMD ["node", "dist/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/authorization-service/Dockerfile b/backend/services/authorization-service/Dockerfile index 95ee879b..3b9a8e89 100644 --- a/backend/services/authorization-service/Dockerfile +++ b/backend/services/authorization-service/Dockerfile @@ -43,8 +43,20 @@ COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma # Copy built application COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Expose port EXPOSE 3009 -# Start application -CMD ["node", "dist/main.js"] +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:3009/api/v1/health || exit 1 + +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/backup-service/Dockerfile b/backend/services/backup-service/Dockerfile index b2b04f8d..f477bb00 100644 --- a/backend/services/backup-service/Dockerfile +++ b/backend/services/backup-service/Dockerfile @@ -39,6 +39,14 @@ COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder /app/prisma ./prisma +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Set ownership RUN chown -R nestjs:nodejs /app @@ -49,8 +57,8 @@ USER nestjs EXPOSE 3002 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3002/health || exit 1 -# Start the application -CMD ["node", "dist/src/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/identity-service/Dockerfile b/backend/services/identity-service/Dockerfile index 02c6ce26..a0e7f132 100644 --- a/backend/services/identity-service/Dockerfile +++ b/backend/services/identity-service/Dockerfile @@ -52,10 +52,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -68,5 +79,5 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD curl -f http://localhost:3000/api/v1/health || exit 1 -# Start service -CMD ["node", "dist/src/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/leaderboard-service/Dockerfile b/backend/services/leaderboard-service/Dockerfile index b1b31257..c691856b 100644 --- a/backend/services/leaderboard-service/Dockerfile +++ b/backend/services/leaderboard-service/Dockerfile @@ -55,10 +55,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built application COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -68,8 +79,8 @@ ENV NODE_ENV=production EXPOSE 3007 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3007/api/health || exit 1 -# Start the application -CMD ["node", "dist/src/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/planting-service/Dockerfile b/backend/services/planting-service/Dockerfile index f86e8058..d051adeb 100644 --- a/backend/services/planting-service/Dockerfile +++ b/backend/services/planting-service/Dockerfile @@ -43,12 +43,20 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built application COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Expose port EXPOSE 3003 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3003/api/v1/health || exit 1 -# Start the application -CMD ["node", "dist/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/presence-service/Dockerfile b/backend/services/presence-service/Dockerfile index ad7c0208..cd556e4e 100644 --- a/backend/services/presence-service/Dockerfile +++ b/backend/services/presence-service/Dockerfile @@ -52,10 +52,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -65,8 +76,8 @@ ENV NODE_ENV=production EXPOSE 3011 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3011/api/v1/health || exit 1 -# Start service -CMD ["node", "dist/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/referral-service/Dockerfile b/backend/services/referral-service/Dockerfile index b0f29429..ee2bc606 100644 --- a/backend/services/referral-service/Dockerfile +++ b/backend/services/referral-service/Dockerfile @@ -52,10 +52,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -63,8 +74,8 @@ USER nestjs EXPOSE 3004 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3004/health || exit 1 -# Start service -CMD ["node", "dist/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/reporting-service/Dockerfile b/backend/services/reporting-service/Dockerfile index 85f2a021..5170c86b 100644 --- a/backend/services/reporting-service/Dockerfile +++ b/backend/services/reporting-service/Dockerfile @@ -57,10 +57,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -70,8 +81,8 @@ ENV NODE_ENV=production EXPOSE 3008 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3008/api/v1/health || exit 1 -# Start service -CMD ["node", "dist/src/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/reward-service/Dockerfile b/backend/services/reward-service/Dockerfile index fa62f88b..e8dfe841 100644 --- a/backend/services/reward-service/Dockerfile +++ b/backend/services/reward-service/Dockerfile @@ -55,10 +55,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -68,8 +79,8 @@ ENV NODE_ENV=production EXPOSE 3005 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3005/health || exit 1 -# Start service -CMD ["node", "dist/src/main.js"] +# Start service with migration +CMD ["/app/start.sh"] diff --git a/backend/services/wallet-service/Dockerfile b/backend/services/wallet-service/Dockerfile index 82cda711..04deae84 100644 --- a/backend/services/wallet-service/Dockerfile +++ b/backend/services/wallet-service/Dockerfile @@ -52,10 +52,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist +# Create startup script that runs migrations before starting the app +RUN echo '#!/bin/sh\n\ +set -e\n\ +echo "Running database migrations..."\n\ +npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\ +echo "Starting application..."\n\ +exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh + # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs +# Change ownership of app directory +RUN chown -R nestjs:nodejs /app + # Switch to non-root user USER nestjs @@ -63,8 +74,8 @@ USER nestjs EXPOSE 3001 # Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3001/api/v1/health || exit 1 -# Start service -CMD ["node", "dist/main.js"] +# Start service with migration +CMD ["/app/start.sh"]