---

wordpress_labels:
  - '"traefik.enable=true"'
  - '"traefik.http.routers.{{ wordpress_id }}.service={{ wordpress_id }}"'
  - '"traefik.http.routers.{{ wordpress_id }}.rule=Host(`{{ wordpress_base_url }}`)"'
  - '"traefik.http.routers.{{ wordpress_id }}.entrypoints=websecure"'
  - '"traefik.http.routers.{{ wordpress_id }}.tls=true"'
  - '"traefik.http.routers.{{ wordpress_id }}.tls.certresolver=letsencrypt"'
  - '"traefik.http.services.{{ wordpress_id }}.loadbalancer.server.port=80"'

  - '"traefik.http.routers.{{ wordpress_id }}-admin.service={{ wordpress_id }}-admin"'
  - '"traefik.http.routers.{{ wordpress_id }}-admin.rule=Host(`{{ wordpress_base_url }}`)&&(Path(`/wp-login.php`)||PathPrefix(`/wp-admin/`))"'
  - '"traefik.http.routers.{{ wordpress_id }}-admin.entrypoints=websecure"'
  - '"traefik.http.routers.{{ wordpress_id }}-admin.tls=true"'
  - '"traefik.http.routers.{{ wordpress_id }}-admin.tls.certresolver=letsencrypt"'
  - '"traefik.http.services.{{ wordpress_id }}-admin.loadbalancer.server.port=80"'
  - '"traefik.http.routers.{{ wordpress_id }}-admin.middlewares={{ wordpress_id }}-admin-ipwhitelist"'
  - '"traefik.http.middlewares.{{ wordpress_id }}-admin-ipwhitelist.ipwhitelist.sourcerange={{ ip_whitelist | join(",") }}"'

wordpress_docker:
  networks:
    - name: back-tier
      external: true
    - name: front-tier
      external: true
  volumes:
    - name: "{{ wordpress_id }}-content"
  services:
    - name: "{{ wordpress_id }}"
      image_name: "{{ wordpress_image_name }}"
      image_version: "{{ wordpress_image_version }}"
      labels: "{{ wordpress_labels + ( wordpress_labels_additional | default([])) }}"
      environment:
        - "WORDPRESS_DB_HOST: \"{{ shared_service_maria_primary }}:{{ wordpress_mysql_port | default('3306') }}\""
        - "WORDPRESS_DB_USER: \"{{ connect_wordpress_maria_username }}\""
        - "WORDPRESS_DB_PASSWORD: \"{{ connect_wordpress_maria_password }}\""
        - "WORDPRESS_DB_NAME: \"{{ connect_wordpress_maria_database }}\""
        - "WORDPRESS_DEBUG: \"{{ wordpress_debug | default(1) }}\""
        - "WORDPRESS_DOMAIN: \"{{ http_s }}://{{ wordpress_base_url }}\""
        - "WORDPRESS_CONFIG_EXTRA: |"
        - "  define( 'WP_HOME', 'https://{{ wordpress_base_url }}' );"
        - "  define( 'WP_SITEURL', 'https://{{ wordpress_base_url }}' );"
        - "  define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT );"
        - "RESOURCE_API: \"https://{{ connect_base_url }}\""
        - "SMARDIGO_AUTH_TOKEN_NAME: \"{{ smardigo_auth_token_name }}\""
        - "SMARDIGO_AUTH_TOKEN_VALUE: \"{{ smardigo_auth_token_value }}\""
      volumes:
        - '"{{ wordpress_id }}-content:/var/www/html/wp-content"'
      networks:
        - '"back-tier"'
        - '"front-tier"'
      extra_hosts: "{{ wordpress_extra_hosts | default([]) }}"
