From d08d9314ce1316baeeb5fbd08e064e99803cde6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 19 Apr 2020 08:50:00 +0200 Subject: [PATCH] :pushpin: Make the public Traefik network a fixed default (#150) to simplify development --- README.md | 1 - cookiecutter.json | 1 - {{cookiecutter.project_slug}}/.env | 2 +- {{cookiecutter.project_slug}}/README.md | 19 ++++++++++++++++++- .../cookiecutter-config-file.yml | 1 - .../docker-compose.deploy.networks.yml | 2 +- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 788110e..e9a6523 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,6 @@ The input variables, with their default values (some auto generated) are: * `traefik_constraint_tag`: The tag to be used by the internal Traefik load balancer (for example, to divide requests between backend and frontend) for production. Used to separate this stack from any other stack you might have. This should identify each stack in each environment (production, staging, etc). * `traefik_constraint_tag_staging`: The Traefik tag to be used while on staging. -* `traefik_public_network`: This assumes you have another separate publicly facing Traefik at the server / cluster level. This is the network that main Traefik lives in. * `traefik_public_constraint_tag`: The tag that should be used by stack services that should communicate with the public. * `flower_auth`: Basic HTTP authentication for flower, in the form`user:password`. By default: "`root:changethis`". diff --git a/cookiecutter.json b/cookiecutter.json index bbcd4f4..fc0e6fa 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -23,7 +23,6 @@ "traefik_constraint_tag": "{{cookiecutter.domain_main}}", "traefik_constraint_tag_staging": "{{cookiecutter.domain_staging}}", - "traefik_public_network": "traefik-public", "traefik_public_constraint_tag": "traefik-public", "flower_auth": "admin:{{cookiecutter.first_superuser_password}}", diff --git a/{{cookiecutter.project_slug}}/.env b/{{cookiecutter.project_slug}}/.env index 483754c..6f0bf56 100644 --- a/{{cookiecutter.project_slug}}/.env +++ b/{{cookiecutter.project_slug}}/.env @@ -6,8 +6,8 @@ DOMAIN=localhost # DOMAIN=localhost.tiangolo.com # DOMAIN=dev.{{cookiecutter.domain_main}} +TRAEFIK_PUBLIC_NETWORK=traefik-public TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}} -TRAEFIK_PUBLIC_NETWORK={{cookiecutter.traefik_public_network}} TRAEFIK_PUBLIC_TAG={{cookiecutter.traefik_public_constraint_tag}} DOCKER_IMAGE_BACKEND={{cookiecutter.docker_image_backend}} diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 23b89b8..901fe3b 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -394,6 +394,24 @@ And you can use CI (continuous integration) systems to do it automatically. But you have to configure a couple things first. +### Traefik network + +This stack expects the public Traefik network to be named `traefik-public`, just as in the tutorial in DockerSwarm.rocks. + +If you need to use a different Traefik public network name, update it in the `docker-compose.yml` files, in the section: + +```YAML +networks: + traefik-public: + external: true +``` + +Change `traefik-public` to the name of the used Traefik network. And then update it in the file `.env`: + +```bash +TRAEFIK_PUBLIC_NETWORK=traefik-public +``` + ### Persisting Docker named volumes You need to make sure that each service (Docker container) that uses a volume is always deployed to the same Docker "node" in the cluster, that way it will preserve the data. Otherwise, it could be deployed to a different node each time, and each time the volume would be created in that new node before starting the service. As a result, it would look like your service was starting from scratch every time, losing all the previous data. @@ -402,7 +420,6 @@ That's specially important for a service running a database. But the same proble To solve that, you can put constraints in the services that use one or more data volumes (like databases) to make them be deployed to a Docker node with a specific label. And of course, you need to have that label assigned to one (only one) of your nodes. - #### Adding services with volumes For each service that uses a volume (databases, services with uploaded files, etc) you should have a label constraint in your `docker-compose.deploy.volumes-placement.yml` file. diff --git a/{{cookiecutter.project_slug}}/cookiecutter-config-file.yml b/{{cookiecutter.project_slug}}/cookiecutter-config-file.yml index a83f4de..b0e7dd2 100644 --- a/{{cookiecutter.project_slug}}/cookiecutter-config-file.yml +++ b/{{cookiecutter.project_slug}}/cookiecutter-config-file.yml @@ -19,7 +19,6 @@ default_context: pgadmin_default_user_password: '{{ cookiecutter.pgadmin_default_user_password }}' traefik_constraint_tag: '{{ cookiecutter.traefik_constraint_tag }}' traefik_constraint_tag_staging: '{{ cookiecutter.traefik_constraint_tag_staging }}' - traefik_public_network: '{{ cookiecutter.traefik_public_network }}' traefik_public_constraint_tag: '{{ cookiecutter.traefik_public_constraint_tag }}' flower_auth: '{{ cookiecutter.flower_auth }}' sentry_dsn: '{{ cookiecutter.sentry_dsn }}' diff --git a/{{cookiecutter.project_slug}}/docker-compose.deploy.networks.yml b/{{cookiecutter.project_slug}}/docker-compose.deploy.networks.yml index 6d204cb..f1a81ff 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.deploy.networks.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.deploy.networks.yml @@ -14,5 +14,5 @@ services: - default networks: - {{cookiecutter.traefik_public_network}}: + traefik-public: external: true