iterativo-git / dockerdoo

Flexible and streamlined Odoo image to be used with docker-compose, docker swarm or Kubernetes. Fully integrated to with VSCode devcontainers
MIT License
95 stars 91 forks source link

Adding Traefik into dockerdoo #108

Closed axelpina closed 4 years ago

axelpina commented 4 years ago

I am interested in adding Traefik to the dockerdoo stack. Like I explained in Odoo Dominicana's Telegram, I proceeded to create a .yml called traefik.yml with the following configuration:

version: "3"

services:
    traefik:
        image: traefik:v2.0
        env_file: .env
        ports:
          # The HTTP port
          - "80:80"
          - "443:443"
          # The Web UI (enabled by --api.insecure=false)
          - "8080:8080"
        volumes:
          - "./traefik/letsencrypt:/letsencrypt"
          - "./traefik/traefik.yml:/etc/traefik.yml"
          - "/var/run/docker.sock:/var/run/docker.sock"
        labels:
          - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
          - "traefik.http.routers.http-catchall.entrypoints=web"
          - "traefik.http.routers.http-catchall.middlewares=redirect-to-https@docker"
          - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
        command:
         - "--log.level=DEBUG"
         - "--api.insecure=false"
         - "--providers.docker"
         - "--providers.docker.defaultRule=Host(`{{ trimPrefix `/` .Name }}.${TRAEFIK_DEFAULT_DOMAIN}`)"
         - "--entryPoints.web.address=:80"
         - "--entryPoints.websecure.address=:443"
         - "--certificatesResolvers.test.acme.httpchallenge=true"
         - "--certificatesresolvers.test.acme.httpchallenge.entrypoint=web"
         - "--certificatesresolvers.test.acme.email=${ACME_EMAIL}"
         - "--certificatesresolvers.test.acme.storage=/letsencrypt/acme.json"

In the .env:

# Traefik Configuration
TRAEFIK_DEFAULT_DOMAIN=mydomain.com
ACME_EMAIL=username@email.com
# Odoo
ODOO_TRAEFIK_URL_TEST=test.mydomain.com

Then in the docker-compose.yml I added the following labels to the odoo service:

    labels:
      - 'traefik.http.routers.test.rule=Host(`${ODOO_TRAEFIK_URL_TEST}`)'
      - 'traefik.http.routers.test.entrypoints=websecure'
      - 'traefik.http.routers.test.tls.certresolver=test'
      - 'traefik.port=8069'

When I try to run the compose using docker-compose -f docker-compose.yml -f hosted.yml -f traefik.yml up -d it gives me the following error:

ERROR: In file './traefik.yml', network must be a mapping, not an array.

Clearly there's something I'm doing wrong.

When doing docker-compose config this was the output (If its of any help at all):

networks:
  default:
    external: true
    name: cloudbuild
  odoonet: {}
services:
  db:
    environment:
      PGDATA: /var/lib/postgresql/data/pgdata
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: username
      POSTGRES_USER: password
    image: postgres:11
    networks:
      odoonet: null
    restart: unless-stopped
    volumes:
    - psql:/var/lib/postgresql/data/pgdata:rw
  odoo:
    depends_on:
      db:
        condition: service_started
    environment:
      ACME_EMAIL: mail@mydomain.net
      ADMIN_PASSWORD: my-weak-password
      BOOTSTRAP_VERSION: ''
      DBFILTER: .*
      DB_ENV_POSTGRES_PASSWORD: odoo
      DB_ENV_POSTGRES_USER: odoo
      DB_MAXCONN: '64'
      DB_PORT_5432_TCP_ADDR: db
      DB_PORT_5432_TCP_PORT: '5432'
      DB_SSLMODE: prefer
      DB_TEMPLATE: template1
      HTTP_INTERFACE: 0.0.0.0
      HTTP_PORT: '8069'
      LIMIT_MEMORY_HARD: '2684354560'
      LIMIT_MEMORY_SOFT: '2147483648'
      LIMIT_TIME_CPU: '600'
      LIMIT_TIME_REAL: '1200'
      LIMIT_TIME_REAL_CRON: '300'
      LIST_DB: "True"
      LOG_DB: "False"
      LOG_DB_LEVEL: warning
      LOG_HANDLER: :INFO
      LOG_LEVEL: info
      MAX_CRON_THREADS: '2'
      NODE_VERSION: ''
      ODOO_BASEPATH: /opt/odoo
      ODOO_DATA_DIR: /var/lib/odoo/data
      ODOO_EXTRA_ADDONS: /mnt/extra-addons
      ODOO_LOGS_DIR: /var/lib/odoo/logs
      ODOO_RC: /etc/odoo/odoo.conf
      ODOO_TRAEFIK_URL_TEST: test.mydomain.com
      ODOO_VERSION: '12.0'
      PIP_AUTO_INSTALL: '0'
      POSTGRES_PASSWORD: username
      POSTGRES_USER: password
      PROXY_MODE: "False"
      PSQL_VERSION: '11'
      RUN_TESTS: '0'
      SERVER_WIDE_MODULES: base,web
      SMTP_PASSWORD: "False"
      SMTP_PORT: '25'
      SMTP_SERVER: localhost
      SMTP_SSL: "False"
      SMTP_USER: "False"
      TEST_ENABLE: "False"
      TRAEFIK_DEFAULT_DOMAIN: mydomain.com
      UNACCENT: "False"
      WITHOUT_DEMO: "True"
      WKHTMLTOPDF_CHECKSUM: ''
      WKHTMLTOX_VERSION: ''
      WORKERS: '0'
    image: iterativodo/dockerdoo:12.0
    labels:
      traefik.http.routers.test.entrypoints: websecure
      traefik.http.routers.test.rule: Host(`test.mydomain.com`)
      traefik.http.routers.test.tls.certresolver: test
      traefik.port: '8069'
    networks:
      odoonet: null
    restart: unless-stopped
    volumes:
    - /home/ubuntu/prod-test/custom:/mnt/extra-addons:delegated
    - odoo-data:/var/lib/odoo/data:rw
    - odoo-testlogs:/var/lib/odoo/logs:rw
version: '3.7'
volumes:
  odoo-data: {}
  odoo-testlogs: {}
axelpina commented 4 years ago

Succesfully added Traefik to the iterativo odoo stack. Will proceed soon to submit my changes!