agenta icon indicating copy to clipboard operation
agenta copied to clipboard

[Bug] Agenta Variant container fails to start due to missing env var

Open alanmun opened this issue 1 year ago • 1 comments

Traceback (most recent call last):
  File "/app/main.py", line 3, in <module>
    import _app  # This will register the routes with the FastAPI application
  File "/app/_app.py", line 2, in <module>
    from shared.constants import UserType
  File "/app/shared/constants.py", line 39, in <module>
    REDACTED_BUCKET= os.environ["REDACTED_BUCKET"]
  File "/usr/local/lib/python3.10/os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'REDACTED_BUCKET'

Expected behavior image

It should use the environment variables I defined in .env. This environment variable is present there, it seems that the docker container never grabbed my environment variables when deploying this variant.

docker inspect (my variant container) outputs for "Env":

            "Env": [
                "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D",
                "PYTHON_VERSION=3.10.14",
                "PYTHON_PIP_VERSION=23.0.1",
                "PYTHON_SETUPTOOLS_VERSION=65.5.1",
                "PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/dbf0c85f76fb6e1ab42aa672ffca6f0a675d9ee4/public/get-pip.py",
                "PYTHON_GET_PIP_SHA256=dfe9fd5c28dc98b5ac17979a953ea550cec37ae1b47a5116007395bfacff2ab9"
            ],

alanmun avatar Apr 12 '24 20:04 alanmun

To resolve the issue with the REDACTED_BUCKET environment variable not being loaded into your Docker container, follow these steps:

  1. Include the .env File in Your Docker Image: Ensure your Dockerfile copies the .env file into the image. Use the COPY command to place the .env file in the same directory as your application code or wherever your entrypoint.sh script expects it to be.
COPY path/to/your/.env /path/in/container/.env
  1. Modify the entrypoint.sh Script: If your .env file is located in a different spot within the container, update your entrypoint.sh script to source the .env file from its correct location.
#!/bin/bash
# Update the path to where your .env file is located
if [ -f /path/in/container/.env ]; then
    source /path/in/container/.env
fi

exec python main.py
  1. Rebuild and Run Your Docker Container: After making these adjustments, rebuild your Docker image and run your container. This ensures the REDACTED_BUCKET environment variable is correctly loaded.
docker build -t your-image-name .

This approach ensures that your Docker container correctly sources the .env file, making the REDACTED_BUCKET environment variable available to your application.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 12 '24 20:04 dosubot[bot]