0

I'm trying to dockerize my project, and I've come up with the following file structure:

project/
├── app1/
│   ├── main.py
│   ├── Dockerfile
│   └── venv/
├── app2/
│   ├── main.py
│   ├── Dockerfile
│   └── venv/
├── .env
└── docker-compose.yml

In each main.py, I would like to use pydantic's BaseSettings to read env vars from .env file.

from pydantic import BaseSettings

class Config(BaseSettings):
    VAR: str

    class Config:
        env_file = "???"

config = Config()

The question is: how do I use my single .env file each main.py file? Or have I already used some antipatterns and this isn't possible with the current file structure?

PS. I understand that it has nothing to do with docker, it's there for context.

Shmookoff
  • 146
  • 1
  • 10
  • I'd think about putting `.env` into it's own package that's installed into each app's venv. – Woodford Feb 14 '22 at 18:04
  • @Woodford yeah, but in my case, different apps share some variables, so if I wanted to update one, I would have to update it in each `.env` file... – Shmookoff Feb 14 '22 at 18:07
  • Your settings would come from the shared package, not explicitly using the `env_file` mechanism. There are other ways to establish base settings than a `.env` file. – Woodford Feb 14 '22 at 18:13
  • @Woodford how would that package look like and how do I integrate it with Docker? – Shmookoff Feb 14 '22 at 18:19

0 Answers0