tiangolo / full-stack

Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
MIT License
523 stars 81 forks source link

✨ Read vars from files #2

Closed nicobytes closed 6 years ago

nicobytes commented 6 years ago

Hi!

Read environment vars in one line is not easy to read, for example:

DOMAIN={{cookiecutter.domain_main}} TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}} TRAEFIK_PUBLIC_TAG={{cookiecutter.traefik_public_constraint_tag}} STACK_NAME={{cookiecutter.docker_swarm_stack_name_main}} TAG=prod docker-compose -f docker-compose.yml -f docker-compose.admin.yml -f docker-compose.images.yml -f docker-compose.deploy.yml config > docker-stack.yml

Is easier with files:

export $(cat prod.env | grep '^[A-Z]' | xargs) docker-compose -f docker-compose.yml -f docker-compose.admin.yml -f docker-compose.images.yml -f docker-compose.deploy.yml config > docker-stack.yml

You can try with:

cookiecutter https://github.com/nicobytes/full-stack.git --checkout feature/env-files

tiangolo commented 6 years ago

Sorry for the delay!

We both agree that it is not easy to read the way it is right now and it should be improved.

But I think I would prefer to do not depend / require very sophisticated bash scripts or commands, to make it work.

It is a very clever trick what you did there, but it could be somewhat hard to understand for someone new.

I think the current file can be simplified and cleaned, in the same file, with a YAML multi-line string. I'll push a version with that so we can see it and test it (I have modified a couple projects doing that).

tiangolo commented 6 years ago

Can you check the latest commit?

The trick is the:

    - >

Here's how one of the long sections look like, I think it improves readability:

deploy-prod:
  stage: deploy
  script:
    - >
      DOMAIN={{cookiecutter.domain_main}}
      TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}}
      TRAEFIK_PUBLIC_TAG={{cookiecutter.traefik_public_constraint_tag}}
      STACK_NAME={{cookiecutter.docker_swarm_stack_name_main}}
      TAG=prod
      docker-compose
      -f docker-compose.yml
      -f docker-compose.admin.yml
      -f docker-compose.images.yml
      -f docker-compose.deploy.yml
      config > docker-stack.yml
    - docker stack deploy -c docker-stack.yml --with-registry-auth {{cookiecutter.docker_swarm_stack_name_main}}
  environment:
    name: production
    url: https://{{cookiecutter.domain_main}}
  only:
    - production
  tags:
    - swarm
    - prod
nicobytes commented 6 years ago

Ok I get it!