FROM python:3.11-slim # Set working directory for the app WORKDIR /opt/moto_site # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ postgresql-client \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install Python dependencies COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy all application code to /opt/moto_site COPY . . # Create uploads directory RUN mkdir -p uploads/images uploads/gpx # Set FLASK_APP so Flask CLI commands are available ENV FLASK_APP=run.py # Initialize the database and create admin at build time (as root, before switching user) RUN flask --app run.py init-db && flask --app run.py create-admin # Create non-root user and set permissions RUN adduser --disabled-password --gecos '' appuser && chown -R appuser:appuser /opt/moto_site USER appuser # Expose port EXPOSE 5000 # Run the application with Gunicorn, looking for run:app in /opt/moto_site ENTRYPOINT ["/bin/sh", "-c", "exec gunicorn --bind 0.0.0.0:5000 run:app"]