services:
{% if use_syslogd %}
  log:
    image: {{image_src}}/harbor-log:{{version}}
    container_name: harbor-log
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - {{log_location}}/:/var/log/docker/:z
      - type: bind
        source: ./common/config/log/logrotate.conf
        target: /etc/logrotate.d/logrotate.conf
      - type: bind
        source: ./common/config/log/rsyslog_docker.conf
        target: /etc/rsyslog.d/rsyslog_docker.conf
    ports:
      - 127.0.0.1:1514:10514
    networks:
      - harbor
{% endif %}
  registry:
    image: {{image_src}}/harbor-registry:{{reg_version}}
    container_name: registry
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/registry:/storage:z
      - ./common/config/registry/:/etc/registry/:z
      - type: bind
        source: {{data_volume}}/secret/registry/root.crt
        target: /etc/registry/root.crt
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{% if gcs_keyfile %}
      - type: bind
        source: {{gcs_keyfile}}
        target: /etc/registry/gcs.key
{% endif %}
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.core_crt_path}}
        target: /harbor_cust_cert/core.crt
      - type: bind
        source: {{internal_tls.registry_crt_path}}
        target: /etc/harbor/tls/registry.crt
      - type: bind
        source: {{internal_tls.registry_key_path}}
        target: /etc/harbor/tls/registry.key
{% endif %}
    networks:
      - harbor
{% if use_syslogd %}
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "registry"
{% endif %}
  registryctl:
    image: {{image_src}}/harbor-registryctl:{{version}}
    container_name: registryctl
    env_file:
      - ./common/config/registryctl/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/registry:/storage:z
      - ./common/config/registry/:/etc/registry/:z
      - type: bind
        source: ./common/config/registryctl/config.yml
        target: /etc/registryctl/config.yml
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{% if gcs_keyfile %}
      - type: bind
        source: {{gcs_keyfile}}
        target: /etc/registry/gcs.key
{% endif %}
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.registryctl_crt_path}}
        target: /etc/harbor/ssl/registryctl.crt
      - type: bind
        source: {{internal_tls.registryctl_key_path}}
        target: /etc/harbor/ssl/registryctl.key
{% endif %}
    networks:
      - harbor
{% if use_syslogd %}
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "registryctl"
{% endif %}
{% if external_database == False %}
  postgresql:
    image: {{image_src}}/harbor-db:{{version}}
    container_name: harbor-db
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/database:/var/lib/postgresql/data:z
    networks:
      harbor:
    env_file:
      - ./common/config/db/env
{% if use_syslogd %}
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "postgresql"
{% endif %}
    shm_size: '1gb'
{% endif %}
  core:
    image: {{image_src}}/harbor-core:{{version}}
    container_name: harbor-core
    env_file:
      - ./common/config/core/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/ca_download/:/etc/core/ca/:z
      - {{data_volume}}/:/data/:z
      - ./common/config/core/certificates/:/etc/core/certificates/:z
      - type: bind
        source: ./common/config/core/app.conf
        target: /etc/core/app.conf
      - type: bind
        source: {{data_volume}}/secret/core/private_key.pem
        target: /etc/core/private_key.pem
      - type: bind
        source: {{data_volume}}/secret/keys/secretkey
        target: /etc/core/key
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{% if uaa_ca_file %}
      - type: bind
        source: {{uaa_ca_file}}
        target: /etc/core/certificates/uaa_ca.pem
{% endif %}
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.core_crt_path}}
        target: /etc/harbor/ssl/core.crt
      - type: bind
        source: {{internal_tls.core_key_path}}
        target: /etc/harbor/ssl/core.key
{% endif %}
    networks:
      harbor:
    depends_on:
      - registry
{% if external_redis == False %}
      - redis
{% endif %}
{% if external_database == False %}
      - postgresql
{% endif %}
{% if use_syslogd %}
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "core"
{% endif %}
  portal:
    image: {{image_src}}/harbor-portal:{{version}}
    container_name: harbor-portal
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
    volumes:
      - type: bind
        source: ./common/config/portal/nginx.conf
        target: /etc/nginx/nginx.conf
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.portal_crt_path}}
        target: /etc/harbor/tls/portal.crt
      - type: bind
        source: {{internal_tls.portal_key_path}}
        target: /etc/harbor/tls/portal.key
{% endif %}
    networks:
      - harbor
{% if use_syslogd %}
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "portal"
{% endif %}
  jobservice:
    image: {{image_src}}/harbor-jobservice:{{version}}
    container_name: harbor-jobservice
    env_file:
      - ./common/config/jobservice/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/job_logs:/var/log/jobs:z
      - type: bind
        source: ./common/config/jobservice/config.yml
        target: /etc/jobservice/config.yml
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.job_service_crt_path}}
        target: /etc/harbor/ssl/job_service.crt
      - type: bind
        source: {{internal_tls.job_service_key_path}}
        target: /etc/harbor/ssl/job_service.key
{% endif %}
    networks:
      - harbor
    depends_on:
      - core
{% if use_syslogd %}
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "jobservice"
{% endif %}
{% if external_redis == False %}
  redis:
    image: {{image_src}}/harbor-redis:{{redis_version}}
    container_name: redis
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - {{data_volume}}/redis:/var/lib/redis
    networks:
      harbor:
{% if use_syslogd %}
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "redis"
{% endif %}
{% endif %}
  proxy:
    image: {{image_src}}/harbor-nginx:{{nginx_version}}
    container_name: nginx
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
    volumes:
      - ./common/config/nginx:/etc/nginx:z
{% if protocol == 'https' %}
      - {{data_volume}}/secret/cert:/etc/cert:z
{% endif %}
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{%if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.proxy_crt_path}}
        target: /etc/harbor/tls/proxy.crt
      - type: bind
        source: {{internal_tls.proxy_key_path}}
        target: /etc/harbor/tls/proxy.key
{% endif %}
    networks:
      - harbor
    ports:
      - {{http_port}}:8080
{% if protocol == 'https' %}
      - {{https_port}}:8443
{% endif %}
{% if metric.enabled %}
      - {{metric.port}}:9090
{% endif %}
    depends_on:
      - registry
      - core
      - portal
{% if use_syslogd %}
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "proxy"
{% endif %}
{% if with_trivy %}
  trivy-adapter:
    container_name: trivy-adapter
    image: {{image_src}}/harbor-trivy-adapter:{{trivy_adapter_version}}
    restart: always
    cap_drop:
      - ALL
    networks:
      - harbor
    volumes:
      - type: bind
        source: {{data_volume}}/trivy-adapter/trivy
        target: /home/scanner/.cache/trivy
      - type: bind
        source: {{data_volume}}/trivy-adapter/reports
        target: /home/scanner/.cache/reports
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{% if internal_tls.enabled %}
      - type: bind
        source: {{internal_tls.trivy_adapter_crt_path}}
        target: /etc/harbor/ssl/trivy_adapter.crt
      - type: bind
        source: {{internal_tls.trivy_adapter_key_path}}
        target: /etc/harbor/ssl/trivy_adapter.key
{% endif %}
    depends_on:
{% if external_redis == False %}
      - redis
{% endif %}
{% if use_syslogd %}
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "trivy-adapter"
{% endif %}
    env_file:
      ./common/config/trivy-adapter/env
{% endif %}
{% if metric.enabled %}
  exporter:
    image: {{image_src}}/harbor-exporter:{{version}}
    container_name: harbor-exporter
    env_file:
      - ./common/config/exporter/env
    restart: always
    networks:
      - harbor
    depends_on:
      - core
  {% if external_database == False %}
      - postgresql
  {% endif %}
    volumes:
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
{% if use_syslogd %}
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "exporter"
{% endif %}
{% endif %}
networks:
  harbor:
    external: false
