francescou / docker-compose-ui

web interface for Docker Compose
http://francescou.github.io/docker-compose-ui
MIT License
1.54k stars 228 forks source link

Variables on docker-compose #31

Closed WTFKr0 closed 7 years ago

WTFKr0 commented 8 years ago

Hi

Can we imagine that the docker-compose file in repository have some variables in them ? So, when we up a project, a form pop up and we can set some variables for this run. This functionnality will be similar to the rancher-compose questions feature.

What do you think ?

francescou commented 8 years ago

Hi right now you can define variables and then use an env_file, in most cases that is good enough.

Do you need to set variable values on each docker-compose up?

WTFKr0 commented 8 years ago

Yh i want to have a compose template, and then allow my users via the ui to param this compose file and run a set of containers

WTFKr0 commented 8 years ago

The env_file only set env variables into container. I want to allow user to param some of others fields in the docker-compose.yml file, for ex :

web: image: webimage/${version}

In command line, we can : version=1.2.3 docker-compose up -d cause compose substitute variable

I would like to do that via a UI

Thanx for reading

francescou commented 8 years ago

you can use an env_file for the docker-compose-ui service to perform variable substitution like this:

docker-compose.yml

docker_compose_ui:
    image: francescou/docker-compose-ui:0.17
    env_file: .env

.env

VERSION=8-jdk

java/docker-compose.yml

java:
  image: "java:${VERSION}"
  command: java -version

but, as you can see, this way you'll set an env shared between all the containers you manage from docker-compose-ui.

I'm not sure if this will be enough to you but I can't think of a "clean" way to implement variable substitution without using global variables. Feel free to suggest other solutions if you want, thanks.

WTFKr0 commented 8 years ago

Thanx for the trick But yh i think i want more than that :D Ideally, i want a template project, with some variables, and allow my users to create a new project from that template, all that in a UI If you know rancher, I want the same as the questions mechanism, but without the massive rancher infrastructure

francescou commented 8 years ago

so if I've understood correctly, this feature should be integrated with "Create new project" and not the docker-compose up, right?

WTFKr0 commented 8 years ago

Yeah right

francescou commented 8 years ago

to achieve this I think it could be useful to have an advanced yaml editor (something like this: https://github.com/CenturyLinkLabs/lorry-ui ?) and a repository of docker-compose.yml template files.

I'll have to think about it since this feature does not play well with the new git based docker-compose.yml files management

what do you think about it?

WTFKr0 commented 8 years ago

I think about that last couple of days, and this is how i see that :

A repository of templates, each project contain 2 files :

version: "2"
services:
  php:
    image: "mysql:{{MYSQL_TAG}}"
    environment:
      MYSQL_ROOT_PASSWORD: {{MYSQL_PASS}}
{
        "MYSQL_TAG": {
                "type":"select",
                "options": {
                        "url": "http://api.myorg.org/tags/mysql"
                }
        },
        "MYSQL_PASS": {
                "type":"password",
                "placeholder":"Password of the root user"
        }
}

A process take these two files and generate html form to fill the 2 fields

The submit button of the form replace the fileds in the template and display response This is not limited to docker-compose files

Do you know something like that on github ?

francescou commented 8 years ago

I guess you'll need something like http://www.alpacajs.org to generate the HTML form and maybe lodash template to process the docker-compose.yml file.

allamand commented 8 years ago

Hi Guys,

I'm looking to a similar feature, and I was thinking on something simpler, what about simple Env var ?

I've got a compose file :

  wordpress:
    restart: always
    image: wordpress
    expose:
      - "80"
    environment:
      - "WORDPRESS_DB_PASSWORD=${MYSQL_PWD}"
      - "affinity:container!=*traefik*"
      - reschedule:on-node-failure
    depends_on:
      - mysql
    volumes:
      - wordpress_www:/var/www/html
    labels:
      - "traefik.frontend.rule=Host:wordpress.${PROXY_DNS}"
      - "traefik.docker.network=traefik_net"
    logging:
      driver: gelf
      options:
        gelf-address: udp://${LOGSTASH_IP}:12201
    networks:
      - traefik_net
      - back

I used it to set mysql password, the Traefik rule for routing my request on my domain name, and ip for ELK logging.

In my case, just adding a text editor in the Settings section to set env variables like:

MYSQL_PWD=supersecret
PROXY_DNS=mydomain.com
LOGSTASH_IP=10.258.132.15

Then, just before calling docker-compose we just need to make an eval of this store file.

What do you think ?

allamand commented 8 years ago

I try an implementation for this : https://github.com/allamand/docker-compose-ui Pull REquest https://github.com/francescou/docker-compose-ui/pull/66 if you can try and let me know

francescou commented 7 years ago

Hello @WTFKr0 docker compose env files are supported in francescou/docker-compose-ui:1.1.0

MichaelMackus commented 7 years ago

@francescou has this issue been solved? From what I can tell, there's nowhere to enter environment variables (from a .env file) in the latest docker-compose-ui:1.4.1

Even a simple YML editor (alongside the existing "Create new project" form) would suffice for my use case. Personally, I'd like this to be implemented in the "up" action (as a modal of some sort), but I understand this introduces further complexities (where to list these containers, how to stop them, etc.).