# Step 1: Choose a base image FROM python:3.9 # Step 2: Set the working directory inside the container WORKDIR /app # Step 3: Copy the application files to the container COPY . /app # Step 4: Install the required dependencies RUN pip install -r requirements.txt # Step 5: Expose the necessary port EXPOSE 7860 # Install huggingface-cli RUN pip install huggingface_hub # Login to Hugging Face using the token from the environment variable # Create a non-root user and grant read-write permissions RUN useradd -ms /bin/bash myuser RUN chown -R myuser:myuser /app # Change permissions of /app directory RUN chmod -R 777 /app # Switch to the non-root user USER myuser # Expose the secret HUGGINGFACE_TOKEN at buildtime and use its value as the Hugging Face token RUN --mount=type=secret,id=HUGGINGFACE_TOKEN,mode=0444,required=true \ echo "HUGGINGFACE_TOKEN=$(cat /run/secrets/HUGGINGFACE_TOKEN)" > .env # Step 6: Define the entry point command CMD ["flask", "run", "--host=0.0.0.0", "--port=7860"]