x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  registry:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}registry:${REGISTRY_VERSION:-3.0.0}
    volumes:
      - ./certs:/certs:ro
      - ./config.yml:/etc/distribution/config.yml:ro
      - registry:/var/lib/registry
    environment:
      TZ: ${TZ:-UTC}
      REGISTRY_AUTH: ${REGISTRY_AUTH:-}
      REGISTRY_AUTH_HTPASSWD_REALM: ${REGISTRY_AUTH_HTPASSWD_REALM:-}
      REGISTRY_AUTH_HTPASSWD_PATH: ${REGISTRY_AUTH_HTPASSWD_PATH:-}
      REGISTRY_HTTP_TLS_CERTIFICATE: ${REGISTRY_HTTP_TLS_CERTIFICATE:-}
      REGISTRY_HTTP_TLS_KEY: ${REGISTRY_HTTP_TLS_KEY:-}
      OTEL_TRACES_EXPORTER: ${OTEL_TRACES_EXPORTER:-none}
    ports:
      - ${REGISTRY_PORT:-5000}:5000
    deploy:
      resources:
        limits:
          cpus: ${REGISTRY_CPU_LIMIT:-1.0}
          memory: ${REGISTRY_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${REGISTRY_CPU_RESERVATION:-0.1}
          memory: ${REGISTRY_MEMORY_RESERVATION:-128M}
    healthcheck:
      test: [CMD, wget, --no-verbose, --tries=1, --spider, 'http://localhost:5000/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

volumes:
  registry:
