Spaces:
Running
on
T4
Running
on
T4
# 1. Base Image: Start with Miniconda as your project requires it. | |
FROM continuumio/miniconda3 | |
# 2. Create Conda Environment: | |
# First, copy only the environment file and create the environment. | |
# This is done as root and caches this layer, so it only re-runs if environment.yaml changes. | |
COPY environment.yaml /tmp/environment.yaml | |
RUN conda env create -f /tmp/environment.yaml | |
# 3. Create a Non-Root User: | |
# As shown in your example, we create a dedicated, non-root user to run the application. | |
# This is a critical security and permissions best practice. | |
RUN useradd -m -u 1000 user | |
# 4. Copy Application Code: | |
# Copy the rest of your application code into the user's home directory. | |
# The `--chown=user:user` flag sets the correct ownership at the same time, | |
# which is more efficient and cleaner than a separate `chown` command. | |
COPY --chown=user:user . /home/user/app | |
# 5. Switch to Non-Root User: | |
# From this point on, all commands will be run as 'user'. | |
USER user | |
# 6. Set Working Directory: | |
# Set the working directory to where the code was copied. | |
WORKDIR /home/user/app | |
# 7. Expose Port: | |
# Expose the port your Gradio app will run on. | |
EXPOSE 7860 | |
# 8. Run the Application: | |
# The JIT compilation will now happen here, on first startup. | |
# Because this happens on the GPU-enabled runtime machine, it will be much faster. | |
# The results will be cached in /home/user/.cache, making subsequent starts fast. | |
CMD ["conda", "run", "--no-capture-output", "-n", "tirex", "python", "app.py"] |