Environment Variable in build time

I’m using Prisma Client to connect to my database from Space. However, I’m encountering issues with environment variables: they only seem to be available when the app is actually running (inside entrypoint.sh). This means I can’t run prisma generate at build time, and at runtime, I’m hitting a directory permission error. I even tried running the application as root to bypass the issue, but it seems Space doesn’t allow that.

Here are some code for context:
Dockerfile:

FROM python:3.12.5-bookworm
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 2710 user

# Switch to the "user" user
USER user
ENV HOME=/home/user \
	PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/src
COPY --chown=user . $HOME/src
RUN mkdir .ipfs
RUN chmod 777 $HOME/src/.ipfs
RUN chmod 777 $HOME

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

// RUN prisma generate

RUN chmod +x ./entrypoint.sh

EXPOSE 7860

ENTRYPOINT [ "./entrypoint.sh" ]

Entrypoint:

#!/bin/sh

python main.py

Some other docker hosting has BUILD_ENV which provide env variable for build time.

I don’t use Docker, so I don’t know much about it, but I’ve found something that looks like it.

Secrets and Variables Management

You can manage a Space’s environment variables in the Space Settings. Read more here.

Variables

Buildtime

Variables are passed as build-args when building your Docker Space. Read Docker’s dedicated documentation for a complete guide on how to use this in the Dockerfile.

But Huggingface space don’t let us change the run command of the docker (the build-args when buiding). It only let us change the env at runtime.
I try to printenv at runtime and buildtime and only see Spaces Variables (huggingface env setting) at runtime. Nor buildtime

Is that just a bug…?

Basically, there are quite a few features that aren’t used very often that are buggy. No one reports it, so none of the developers notice…

I don’t know where to report bugs in Spaces.
HF doesn’t have a DM, so the only way is to send a mentions to someone who seems to have admin rights, or hit up Discord, or open a Discussion with a randomly selected HF staff repo.

P.S.

By the way, what I would do is either find another alternative tool because I’m too lazy to wait, or combine multiple somethings to somehow make it work.
It’s not pretty, but it’s the fast way.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.