The project name should be configurable
Ideally in fig.yml (how do we have general config in there? maybe we need a top level services key?), but maybe in a separate .fig-project file or something.
I don't want to give up top-level services without a fight. Perhaps everything other than service configuration could go in a top-level key with a special name:
PROJECT:
name: myapp
web:
...
db:
...
.project:
name: myapp
web:
...
db:
...
maybe
or maybe services is a reserved service name and you can either do
name: myapp
services:
web:
...
db:
...
or
web:
...
db:
...
depending on whether you need extra config. But that's a bit gross.
I think I quite like the idea of adding a top-level "services" key.
+1 on a special key like @aanand mentioned. I would like to do global environment variables here too :)
+1 for top-level name and services keys. You could just make a new major release so backwards compatibility is not mandatory ;)
I also like the idea of global environment variables. So you could e.g. give credentials to a database container (for setting up the database & user) as well as all consuming services. Those would be defined in a top-level environment entry.
Being able to specify the project-name manually (and not rely on the name of the directory) is quite important;
- using our standard project-structure, the most logical location for the fig-file to resort in will be named the same for all our projects.
- we're planning on using a shared docker host for our developers to work on. Multiple developers will work on their own instance of a project, so they should be able to provide a unique name for their instance of the project.
besides being able to specify the project-name inside fig.yml, fig should also take a parameter to override this, e.g. fig up -d --project-name=${USER}-my-project
An alternative solution to having a special global key is to support two streams in fig.yaml.
Something like this:
project-name: something
---
db:
...
app:
...
It might not be a good idea to attach semantics to location in the stream, I just wanted to throw it in the suggestion bowl.
+1 for a single special key for non-service or "meta" stuff. This also came up in #210, and will be necessary for #318.
@thomasf I'm not sure how many yaml parses support multiple streams. I tried it out with pyyaml and I got ComposerError: expected a single document in the stream.
Its supported according to the docs by using load_all
http://pyyaml.org/wiki/PyYAMLDocumentation#LoadingYAML
What about several (related) projects in one fig.yml? I wan't to manage them all in one fig. Cause to me fig define something like everything on one host or vm. So some kine of basic namespacing should be here. At least i wanna have a possibility to give containers custom names. ( run --name=custom).
@aanand do you see the group.yml format in https://gist.github.com/aanand/9e7ac7185ffd64c1a91a changing much?
I'd like to add support for that format to fig so that users can migrate to the new format ahead of any docker release with this support (to make the transition smoother). That change should also resolve this issue.
If you think it's still likely to change, I can hold off until it's more stable.
@dnephin It should be considered unstable, so no adding support just yet. Input appreciated on the format itself - I'm actually somewhat unconvinced about putting the group name in the file, because it makes the whole thing less portable. Perhaps it should go in a separate, unversioned file.
+1
Any news on this? There was an interesting suggestion by @jderusse here, which i like very much: https://github.com/docker/compose/issues/745#issuecomment-74028861
The problem with your proposals, is that you'r mixing project configuration and service declaration. it's less readable and adding a keyword (projet or .project) can break backward compatibility.
I realy thinks it's time for docker-compose to improve it schema by adding a top level structure wich contains services.
containers:
web:
...
db:
...
With such structure, we'll be able to improve the schema like
schema-version: 1.1
project_name: foo
containers:
web:
...
db:
...
or
schema-version: 2.0
project:
name: foo
default_env_file: ./bar
containers:
web:
...
db:
...
Notice the property schema-version which help us keep backword compatibilities with schema evolutions. And to keep BC with current schema, in compose/project.py::from_config
@classmethod
def from_config(cls, name, config, client):
if 'schema-version' not in config or not isinstance(config['schema-version'], basestring)
config = {
'schema-version': '1.0',
'containers': config
}
dicts = []
for service_name, service in list(config.containers.items()):
if not isinstance(service, dict):
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.' % service_name)
service['name'] = service_name
dicts.append(service)
return cls.from_dicts(name, dicts, client)
If I've time, i'll work on a patch proposal in the nexts days.
I have two projects that are using docker compose, one dependent on the other. For this use-case it will be great to have something like dependent projects:
schema-version: 2.0
project:
name: foo
default_env_file: ./bar
require:
project2:
config: PATH | URL
services:
- serv1
- serv2
detached: true
containers:
web:
...
db:
...
I am posting there because it seems like relative to #1233 Does it makes sense? If yes, I will make it based on @jderusse code.
This sounds a lot like #318
+1 It's a bother when dealing with many projects and many compose files to reply on "COMPOSE_PROJECT_NAME" or -p Should go in the config.
+1
+1