-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global env variables #210
Comments
I think you can use YAML features for this. I haven't tested it myself and maybe Python's YAML parser doesn't support the syntax, but: global: &global
FOO: bar
BOB: baz
web:
environment:
<<: *global
EXAMPLE: more The only downside here is that you'd need to explicitly |
Maybe services starting with underscores could be ignored. |
Hmm, I know it's purely aesthetic, but I think that could make the fig.yml look a bit ugly and wouldn't be immediately apparent to somebody reading the fig.yml for the first time. Maybe it would be best to introduce some sort of a reserved namespace key after all, so things of this nature could go under it. Say |
I wonder if there's a way for fig to detect that a key is marked as an anchor and ignore it in that case (i.e. ignore |
I have run into a similar issue where I have multiple entry points into the same image, so I end up duplicating a bunch of env vars and other metadata in my fig.yml. Instead of global properties, it would be nice to have some form of inheritance for the service definitions. Perhaps it could follow the Docker style and have a base:
abstract: true
build: .
environment:
FERNET_SECRET: 123449b81234
web:
from: base
command: web
ports:
- "5000"
environment:
PORT: "5000"
worker:
from: base
command: worker |
So I was looking at this and looking at the service.py file. Couldn't you modify that file so that when it's looking for services if it finds one named say "global" or "globalvars" (or something) instead of doing the normal service stuff it would do something a little different? Say it would modify all existing services and all future services and add the values in Global to the environment values. Or you force Global to be declared at the beginning of fig.yml so that it can just add everything to the services as they are created. This would at least give you global static variables that wouldn't require having to repeat them everywhere. |
For #318 I need a section in the config that isn't a service definition (similar to this). Maybe a single key like |
Yeah, in support of the idea of "reserving" a key for fig-specific things. |
@ryanbrainard have you tried implementing anything like your suggestion? |
@d11wtq, yep that works. You can use yaml to share environment configuration between containers like so: api:
environment: &environment
key: value
ui:
environment: *environment
db:
environment: *environment
logtaker:
environment: *environment This is presently working on my end. |
non container root level entriesFor me somthing along the lines of abstract: true (as suggested earlier) or maybe autostart:false would be a good fit. profilesI think that this change also should take something like "profiles" in consideration even if that is to be implemented later. My reasoning here is that both features call for some kind of conditional selection in the yaml tree and might benefit from being discussed together before implementing one of them. One example is that I might want to switch between mounting volumes on host or in containers. Another example is switching between binding to a specific port on the host and not doing that, since you cannot do "a fig run ..." if that container is running and also is configured to bind a specific host port. |
Now that we support environment variable interpolation these variables can be provided outside of the compose file. There's still an open issue about providing defaults, or reading values from a file, which I think are more appropriate now, so we can close this I think. env_file and extends can also be used to solve this problem. |
Move event types constants into single file
@sw-carlin agreed |
Is there a workaround for this or does one have to specify the variable individually for all containers? |
as of 2024, this is what i do.
|
I'd be great to be able to declare 'global' env variables, that are set for all containers.
The text was updated successfully, but these errors were encountered: