Hello guys, need help here!! I am trying to inject...
# general
q
Hello guys, need help here!! I am trying to inject .env file in docker image and somehow its not working. the final result I want is that it the docker image should fetch .env. i want to upload either .env to pex or directly to docker. please suggest what i need to change in my BUILD file, i have attached it
Copy code
python_requirement(
    name='auth_requirements',
    requirements = [
        'python-dotenv',
        'fastapi',
        'uvicorn',
        'pydantic'
    ]
)

resource(name='env', source='//.env')

python_sources(
    name='auth_app',
    sources=[
        'src/**'
    ],
    dependencies=[
        ':auth_requirements',
        ':env',
        'libs/util/db/mongoose:db_mongoose',
        'libs/domains/users:domain_users'
    ],
)

pex_binary(
    name='main',
    entry_point='src/app.py',
    dependencies=[
        ':auth_app',
    ],
    output_path='auth/main.pex',
)

docker_image(
    name='zillow-auth',
    pull=True,
    instructions=[
        'FROM python:3.11',
        'COPY auth/main.pex /home/zillow/auth/main.pex',
        'CMD /home/zillow/auth/main.pex',
    ],
    output_path='auth/zillow-auth.docker-info.json',
)
c
Hi! You’re close. A few things.. as your resource does not seem to be within your source root of the python sources, it won’t be included in your pex. Either you need to move it, or include it explicitly in your docker image. I’ll provide en example for the latter. replace your env resource with a file one:
Copy code
file(name='env', source='.env')
Then move the dependency on
:env
from your python_sources to the
docker_image
and add a
COPY .env /home/zillow/..
or where ever you want to have it.
q
Great it worked as expected!! Thanks for the help :))
👍 1