From 52ed5a5f29096861b7cf5bef5edafb30f90a90dd Mon Sep 17 00:00:00 2001 From: Demetris Stavrou Date: Tue, 22 May 2018 22:23:51 +0300 Subject: [PATCH] Added traefik Dockerfile and configuration file. Updated 'production.yml' to add traefik and remove caddy Removed caddy Dockerfile and configuration file --- .../compose/production/caddy/Caddyfile | 14 ------- .../compose/production/caddy/Dockerfile | 3 -- .../compose/production/traefik/Dockerfile | 2 + .../compose/production/traefik/traefik.toml | 37 +++++++++++++++++++ {{cookiecutter.project_slug}}/production.yml | 27 +++++++++----- 5 files changed, 57 insertions(+), 26 deletions(-) delete mode 100644 {{cookiecutter.project_slug}}/compose/production/caddy/Caddyfile delete mode 100644 {{cookiecutter.project_slug}}/compose/production/caddy/Dockerfile create mode 100644 {{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile create mode 100644 {{cookiecutter.project_slug}}/compose/production/traefik/traefik.toml diff --git a/{{cookiecutter.project_slug}}/compose/production/caddy/Caddyfile b/{{cookiecutter.project_slug}}/compose/production/caddy/Caddyfile deleted file mode 100644 index d36632e4b..000000000 --- a/{{cookiecutter.project_slug}}/compose/production/caddy/Caddyfile +++ /dev/null @@ -1,14 +0,0 @@ -www.{% raw %}{$DOMAIN_NAME}{% endraw %} { - redir https://{{cookiecutter.domain_name}} -} - -{% raw %}{$DOMAIN_NAME}{% endraw %} { - proxy / django:5000 { - header_upstream Host {host} - header_upstream X-Real-IP {remote} - header_upstream X-Forwarded-Proto {scheme} - } - log stdout - errors stdout - gzip -} diff --git a/{{cookiecutter.project_slug}}/compose/production/caddy/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/caddy/Dockerfile deleted file mode 100644 index d02f0342d..000000000 --- a/{{cookiecutter.project_slug}}/compose/production/caddy/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM abiosoft/caddy:0.10.6 - -COPY ./compose/production/caddy/Caddyfile /etc/Caddyfile diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile new file mode 100644 index 000000000..4505ba52c --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile @@ -0,0 +1,2 @@ +FROM traefik +COPY ./compose/production/traefik/traefik.toml /etc/traefik diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.toml b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.toml new file mode 100644 index 000000000..e7bfd41e1 --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.toml @@ -0,0 +1,37 @@ +logLevel = "ERROR" +defaultEntryPoints = ["http", "https"] + +[web] +# Port for the status page +address = ":7080" + +# Entrypoints, http and https +[entryPoints] + # http should be redirected to https + [entryPoints.http] + address = ":80" + [entryPoints.http.redirect] + entryPoint = "https" + # https is the default + [entryPoints.https] + address = ":443" + [entryPoints.https.tls] + +# Enable ACME (Let's Encrypt): automatic SSL +[acme] +# Email address used for registration +email = "{{ cookiecutter.email }}" +storageFile = "acme.json" +entryPoint = "https" +onDemand = false +OnHostRule = true + # Use a HTTP-01 acme challenge rather than TLS-SNI-01 challenge + [acme.httpChallenge] + entryPoint = "http" + +# Enable Docker configuration backend +[docker] +endpoint = "unix:///var/run/docker.sock" +domain = "{{cookiecutter.domain_name}}" +watch = true +exposedbydefault = false diff --git a/{{cookiecutter.project_slug}}/production.yml b/{{cookiecutter.project_slug}}/production.yml index f8f8ca22c..3147fbf44 100644 --- a/{{cookiecutter.project_slug}}/production.yml +++ b/{{cookiecutter.project_slug}}/production.yml @@ -3,7 +3,6 @@ version: '2' volumes: postgres_data: {} postgres_backup: {} - caddy: {} services: django:{% if cookiecutter.use_celery == 'y' %} &django{% endif %} @@ -18,6 +17,11 @@ services: - ./.envs/.production/.django - ./.envs/.production/.postgres command: /gunicorn.sh + labels: + - "traefik.enable=true" + - "traefik.backend=django" + - "traefik.frontend.rule={{ cookiecutter.domain_name }}" + - "traefik.port=5000" postgres: build: @@ -30,20 +34,21 @@ services: env_file: - ./.envs/.production/.postgres - caddy: + traefik: build: context: . - dockerfile: ./compose/production/caddy/Dockerfile - image: {{ cookiecutter.project_slug }}_production_caddy + dockerfile: ./compose/production/traefik/Dockerfile + image: {{ cookiecutter.project_slug }}_production_traefik depends_on: - django volumes: - - caddy:/root/.caddy - env_file: - - ./.envs/.production/.caddy + - /var/run/docker.sock:/var/run/docker.sock:ro + # - ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro + # - ./traefik/acme:/etc/traefik/acme ports: - - "0.0.0.0:80:80" - - "0.0.0.0:443:443" + - "80:80" + - "443:443" + - "7080:7080" redis: image: redis:3.2 @@ -59,6 +64,8 @@ services: - ./.envs/.production/.django - ./.envs/.production/.postgres command: /start-celeryworker.sh + labels: + - "traefik.enable=false" celerybeat: <<: *django @@ -70,5 +77,7 @@ services: - ./.envs/.production/.django - ./.envs/.production/.postgres command: /start-celerybeat.sh + labels: + - "traefik.enable=false" {%- endif %}