FROM python:3.11-slim # Install system dependencies RUN apt-get update && apt-get install -y \ postgresql \ postgresql-contrib \ curl \ tzdata \ && rm -rf /var/lib/apt/lists/* # Set work directory WORKDIR /app # Set default timezone ENV TZ=Europe/Rome # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Create necessary directories RUN mkdir -p /data /app/logs /var/lib/postgresql/data /var/run/postgresql # Make startup scripts executable RUN chmod +x /app/docker/init-database.py /app/docker/test-db.py # Create startup script directly in Dockerfile RUN echo '#!/bin/bash' > /app/start.sh && \ echo 'set -e' >> /app/start.sh && \ echo 'cd /app' >> /app/start.sh && \ echo 'export FLASK_APP=app' >> /app/start.sh && \ echo 'export DATABASE_URL=postgresql+psycopg2://timetracker@localhost:5432/timetracker' >> /app/start.sh && \ echo 'echo "=== Starting TimeTracker ==="' >> /app/start.sh && \ echo 'echo "Testing startup script..."' >> /app/start.sh && \ echo 'ls -la /app/docker/' >> /app/start.sh && \ echo 'echo "Starting database initialization..."' >> /app/start.sh && \ echo 'python /app/docker/init-database-sql.py' >> /app/start.sh && \ echo 'echo "Starting application..."' >> /app/start.sh && \ echo 'exec gunicorn --bind 0.0.0.0:8080 --worker-class eventlet --workers 1 --timeout 120 "app:create_app()"' >> /app/start.sh # Make startup scripts executable RUN chmod +x /app/start.sh /app/docker/init-database.py /app/docker/test-db.py # Create timetracker user and ensure postgres user exists RUN useradd -m -u 1000 timetracker && \ chown -R timetracker:timetracker /app /data /app/logs && \ chown -R postgres:postgres /var/lib/postgresql/data /var/run/postgresql && \ chmod +x /app/start.sh # Verify startup script exists and is accessible RUN ls -la /app/start.sh && \ head -1 /app/start.sh # Expose port EXPOSE 8080 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -f http://localhost:8080/_health || exit 1 # Start the application CMD ["/app/start.sh"]