# Environment Variable in build time

**URL:** <https://discuss.huggingface.co/t/environment-variable-in-build-time/104436>\
**Category:** Spaces\
**Created:** [August 29, 2024, 3:01am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436 "2024-08-29T03:01:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quanvndzai](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/quanvndzai/32/31002_2.png) [@quanvndzai](https://discuss.huggingface.co/u/quanvndzai)\
**Post date:** [August 29, 2024, 3:01am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436/1 "2024-08-29T03:01:34Z")

</div>

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:

```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:

```bash
#!/bin/sh

python main.py

```

Some other docker hosting has BUILD\_ENV which provide env variable for build time.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [August 29, 2024, 8:32am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436/2 "2024-08-29T08:32:03Z")

</div>

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

> **[Docker Spaces](https://huggingface.co/docs/hub/en/spaces-sdks-docker)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> Secrets and Variables Management

> You can manage a Space’s environment variables in the Space Settings. Read more [here](https://huggingface.co/docs/hub/en/spaces-overview#managing-secrets).

> ### Variables

> #### Buildtime

> Variables are passed as `build-arg`s when building your Docker Space. Read [Docker’s dedicated documentation](https://docs.docker.com/engine/reference/builder/#arg) for a complete guide on how to use this in the Dockerfile.

---

<div class="post-metadata">

**Author:** ![quanvndzai](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/quanvndzai/32/31002_2.png) [@quanvndzai](https://discuss.huggingface.co/u/quanvndzai)\
**Post date:** [August 29, 2024, 10:53am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436/3 "2024-08-29T10:53:23Z")

</div>

> [@John6666](#):
>
> en building your Doc

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

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [August 29, 2024, 11:03am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436/4 "2024-08-29T11:03:13Z")

</div>

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.  
[https://huggingface.co/posts/bartowski/524900219749834#66cf4e92da5d6bbe4d4155a5](https://huggingface.co/posts/bartowski/524900219749834#66cf4e92da5d6bbe4d4155a5)

## 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [August 30, 2024, 5:57am UTC](https://discuss.huggingface.co/t/environment-variable-in-build-time/104436/5 "2024-08-30T05:57:56Z")

</div>

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