| # Base Node.js image | |
| FROM node:18-alpine | |
| # Set working directory | |
| WORKDIR /app | |
| # Install necessary tools (git, bash, etc.) | |
| RUN apk add --no-cache git bash | |
| # Copy application files to container | |
| COPY . . | |
| # Install dependencies | |
| RUN yarn install | |
| # Set permissions for users.json and users directory | |
| RUN touch users.json && \ | |
| chmod 666 users.json && \ | |
| mkdir -p users && \ | |
| chmod 777 users | |
| # Ensure start.sh is executable | |
| RUN chmod +x start.sh | |
| # Create a non-root user and switch to it | |
| RUN adduser -D appuser | |
| USER appuser | |
| # Expose application port | |
| EXPOSE 7860 | |
| # Set default environment variables | |
| ENV NODE_ENV=production | |
| ENV PORT=7860 | |
| # Healthcheck to ensure app is running | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD curl -f http://localhost:7860 || exit 1 | |
| # Run start script | |
| CMD ["sh", "./start.sh"] |