---

gitea_labels: [
  '"traefik.enable=true"',
  '"traefik.http.routers.{{ gitea_id }}.service={{ gitea_id }}"',
  '"traefik.http.routers.{{ gitea_id }}.rule=Host(`{{ stage_server_domain }}`) && !Path(`/metrics`)"',
  '"traefik.http.routers.{{ gitea_id }}.entrypoints=websecure"',
  '"traefik.http.routers.{{ gitea_id }}.tls=true"',
  '"traefik.http.routers.{{ gitea_id }}.tls.certresolver=letsencrypt"',
  '"traefik.http.services.{{ gitea_id }}.loadbalancer.server.port=3000"',

  '"traefik.http.routers.{{ gitea_id }}-admin.service={{ gitea_id }}-admin"',
  '"traefik.http.routers.{{ gitea_id }}-admin.rule=Host(`{{ stage_server_domain }}`) && Path(`/metrics`)"',
  '"traefik.http.routers.{{ gitea_id }}-admin.entrypoints=admin-service"',
  '"traefik.http.routers.{{ gitea_id }}-admin.tls=true"',
  '"traefik.http.routers.{{ gitea_id }}-admin.tls.certresolver=letsencrypt"',
  '"traefik.http.services.{{ gitea_id }}-admin.loadbalancer.server.port=3000"',

  '"traefik.tcp.routers.{{ gitea_id }}-git.service={{ gitea_id }}-git"',
  '"traefik.tcp.routers.{{ gitea_id }}-git.rule=HostSNI(`*`)"',
  '"traefik.tcp.routers.{{ gitea_id }}-git.entrypoints=git"',
  '"traefik.tcp.services.{{ gitea_id }}-git.loadbalancer.server.port=22"',
]

gitea_environment: [
  "USER: \"git\"",
  "USER_UID: \"1000\"",
  "USER_GID: \"1000\"",
  "GITEA__database__DB_TYPE: \"postgres\"",
  "GITEA__database__HOST: \"{{ gitea_postgres_host }}\"",
  "GITEA__database__NAME: \"{{ gitea_postgres_database }}\"",
  "GITEA__database__USER: \"{{ gitea_postgres_database }}\"",
  "GITEA__database__PASSWD: \"{{ gitea_postgres_password }}\"",
  "GITEA__database__SSL_MODE: \"require\"",

  "GITEA__server__DOMAIN: \"{{ stage_server_domain }}\"",
  "GITEA__server__SSH_DOMAIN: \"{{ stage_server_domain }}\"",
  "GITEA__server__ROOT_URL: \"{{ stage_server_url }}\"",

  "GITEA__mailer__ENABLED: \"true\"",
  "GITEA__mailer__FROM: \"{{ inventory_hostname }}@{{ domain }}\"",
  "GITEA__server__MAILER_TYPE: \"smtp\"",
  "GITEA__server__HOST: \"{{ shared_service_mail_hostname }}\"",

  "GITEA__metrics__ENABLED: \"true\"",
]

gitea_docker: {
  networks: [
    {
      name: front-tier,
      external: true,
    },
  ],
  volumes: [
    {
      name: "{{ gitea_id }}-data"
    },
  ],
  services: [
    {
      name: "{{ gitea_id }}",
      image_name: "{{ gitea_image_name }}",
      image_version: "{{ gitea_version }}",
      labels: "{{ gitea_labels + ( gitea_labels_additional | default([])) }}",
      restart: "{{ gitea_service_restart | default('always') }}",
      environment: "{{ gitea_environment + ( gitea_environment_additional | default([])) }}",
      volumes: [
        '"{{ gitea_id }}-data:/data"',
        '"/etc/timezone:/etc/timezone:ro"',
        '"/etc/localtime:/etc/localtime:ro"',
      ],
      networks: [
        '"front-tier"',
      ],
      extra_hosts: "{{ gitea_extra_hosts | default([]) }}",
    }
  ],
}
