#!/bin/bash # This script is run as root. # Fix ownership of the data volume. # The USER_ID and GROUP_ID are passed in at build time and baked into the image. # We're setting the ownership of the mounted volume to match the user that the app will run as. echo "Updating /app/data ownership..." chown -R appuser:appgroup /app/data echo "Switching to user 'appuser' to run application..." # Use gosu to drop privileges and execute the application as the 'appuser' # The '-E' flag preserves the environment variables. exec gosu appuser:appgroup bash -c ' # Now running as appuser # Start the FastAPI application with Uvicorn in the background python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 & UVICORN_PID=$! echo "Uvicorn started with PID $UVICORN_PID" # Start the worker process in the background python app/worker.py & WORKER_PID=$! echo "Worker started with PID $WORKER_PID" # Wait for both processes to exit wait $UVICORN_PID $WORKER_PID '