compose icon indicating copy to clipboard operation
compose copied to clipboard

The project name should be configurable

Open bfirsh opened this issue 12 years ago • 55 comments

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.

bfirsh avatar Jan 22 '14 13:01 bfirsh

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:
  ...

aanand avatar Jan 22 '14 17:01 aanand

.project:
  name: myapp

web:
  ...

db:
  ...

maybe

bfirsh avatar Jan 22 '14 17:01 bfirsh

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.

bfirsh avatar Jan 22 '14 17:01 bfirsh

+1 on a special key like @aanand mentioned. I would like to do global environment variables here too :)

sherzberg avatar Feb 06 '14 04:02 sherzberg

+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.

djmaze avatar Feb 10 '14 16:02 djmaze

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

thaJeztah avatar Apr 04 '14 22:04 thaJeztah

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.

thomasf avatar Aug 17 '14 15:08 thomasf

+1 for a single special key for non-service or "meta" stuff. This also came up in #210, and will be necessary for #318.

dnephin avatar Aug 18 '14 23:08 dnephin

@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.

dnephin avatar Aug 18 '14 23:08 dnephin

Its supported according to the docs by using load_all

http://pyyaml.org/wiki/PyYAMLDocumentation#LoadingYAML

thomasf avatar Aug 18 '14 23:08 thomasf

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).

shuron avatar Aug 31 '14 11:08 shuron

@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 avatar Nov 08 '14 20:11 dnephin

@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.

aanand avatar Nov 10 '14 16:11 aanand

+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

mikehaertl avatar Mar 31 '15 12:03 mikehaertl

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.

jderusse avatar Mar 31 '15 13:03 jderusse

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.

yegortokmakov avatar May 04 '15 10:05 yegortokmakov

This sounds a lot like #318

dnephin avatar May 04 '15 14:05 dnephin

+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.

phazei avatar Jun 26 '15 02:06 phazei

+1

SonicGD avatar Jul 07 '15 09:07 SonicGD

+1

dcosson avatar Jul 15 '15 20:07 dcosson