# All other flavors inherit the `common' config snippet
common: &common
    # Default log level is info
    loglevel: _env:LOGLEVEL:info
    # Enable the debugging /_versions endpoint
    debug_versions: _env:DEBUG_VERSIONS:false
    # By default, the registry acts standalone (eg: doesn't query the index)
    standalone: _env:STANDALONE:true
    # The default endpoint to use (if NOT standalone) is index.docker.io
    index_endpoint: _env:INDEX_ENDPOINT:https://index.docker.io
    # Storage redirect is disabled
    storage_redirect: _env:STORAGE_REDIRECT
    # Token auth is enabled (if NOT standalone)
    disable_token_auth: _env:DISABLE_TOKEN_AUTH
    # No priv key
    privileged_key: _env:PRIVILEGED_KEY
    # No search backend
    search_backend: _env:SEARCH_BACKEND
    # SQLite search backend
    sqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db

    # Mirroring is not enabled
    mirroring:
        source: _env:MIRROR_SOURCE # https://registry-1.docker.io
        source_index: _env:MIRROR_SOURCE_INDEX # https://index.docker.io
        tags_cache_ttl: _env:MIRROR_TAGS_CACHE_TTL:172800 # seconds

    cache:
        host: {{ if exists "/deis/cache/host" }}{{ getv "/deis/cache/host" }}{{ else }}""{{ end }}
        port: {{ if exists "/deis/cache/port" }}{{ getv "/deis/cache/port" }}{{ else }}""{{ end }}
        password: _env:CACHE_REDIS_PASSWORD
        db: 1

    # Enabling LRU cache for small files
    # This speeds up read/write on small files
    # when using a remote storage backend (like S3).
    cache_lru:
        host: {{ if exists "/deis/cache/host" }}{{ getv "/deis/cache/host" }}{{ else }}""{{ end }}
        port: {{ if exists "/deis/cache/port" }}{{ getv "/deis/cache/port" }}{{ else }}""{{ end }}
        password: _env:CACHE_LRU_REDIS_PASSWORD
        db: 2

    # Enabling these options makes the Registry send an email on each code Exception
    {{ if exists "/deis/registry/smtpHost" }}
    email_exceptions:
        smtp_host: {{ if exists "/deis/registry/smtpHost" }}{{ getv "/deis/registry/smtpHost" }}{{ else }}""{{ end }}
        smtp_port: {{ if exists "/deis/registry/smtpPort" }}{{ getv "/deis/registry/smtpPort" }}{{ else }}"25"{{ end }}
        smtp_login: {{ if exists "/deis/registry/smtpLogin" }}{{ getv "/deis/registry/smtpLogin" }}{{ else }}""{{ end }}
        smtp_password: {{ if exists "/deis/registry/smtpPassword" }}{{ getv "/deis/registry/smtpPassword" }}{{ else }}""{{ end }}
        smtp_secure: bool({{ if exists "/deis/registry/smtpSecure" }}{{ getv "/deis/registry/smtpSecure" }}{{ else }}"false"{{ end }})
        from_addr: {{ if exists "/deis/registry/smtpFrom" }}{{ getv "/deis/registry/smtpFrom" }}{{ else }}"docker-registry@localdomain.local"{{ end }}
        to_addr: {{ if exists "/deis/registry/smtpTo" }}{{ getv "/deis/registry/smtpTo" }}{{ else }}"noise+dockerregistry@localdomain.local"{{ end }}
    {{ end }}

    # Enable bugsnag (set the API key)
    bugsnag: _env:BUGSNAG

    # CORS support is not enabled by default
    cors:
        origins: _env:CORS_ORIGINS:["null"]
        methods: _env:CORS_METHODS
        headers: _env:CORS_HEADERS:[Content-Type]
        expose_headers: _env:CORS_EXPOSE_HEADERS
        supports_credentials: _env:CORS_SUPPORTS_CREDENTIALS
        max_age: _env:CORS_MAX_AGE
        send_wildcard: _env:CORS_SEND_WILDCARD
        always_send: _env:CORS_ALWAYS_SEND
        automatic_options: _env:CORS_AUTOMATIC_OPTIONS
        vary_header: _env:CORS_VARY_HEADER
        resources: _env:CORS_RESOURCES

local: &local
    <<: *common
    storage: local
    storage_path: /data


s3: &s3
    <<: *common
    storage: s3
    s3_region: {{ if exists "/deis/registry/s3region" }}{{ getv "/deis/registry/s3region" }}{{ else }}~{{ end }}
    s3_bucket: {{ if exists "/deis/registry/s3bucket" }}{{ getv "/deis/registry/s3bucket" }}{{ else }}~{{ end }}
    boto_bucket: {{ if exists "/deis/registry/s3bucket" }}{{ getv "/deis/registry/s3bucket" }}{{ else }}~{{ end }}
    storage_path: {{ if exists "/deis/registry/s3path" }}{{ getv "/deis/registry/s3path" }}{{ else }}"/registry"{{ end }}
    s3_encrypt: bool({{ if exists "/deis/registry/s3encrypt" }}{{ getv "/deis/registry/s3encrypt" }}{{ else }}"true"{{ end }})
    s3_secure: bool({{ if exists "/deis/registry/s3secure" }}{{ getv "/deis/registry/s3secure" }}{{ else }}"true"{{ end }})
    s3_access_key: {{ if exists "/deis/registry/s3accessKey" }}{{ getv "/deis/registry/s3accessKey" }}{{ else }}~{{ end }}
    s3_secret_key: {{ if exists "/deis/registry/s3secretKey" }}{{ getv "/deis/registry/s3secretKey" }}{{ else }}~{{ end }}

# Ceph Object Gateway Configuration
# See http://ceph.com/docs/master/radosgw/ for details on installing this service.
ceph-s3: &ceph-s3
    <<: *common
    storage: s3
    s3_region: ~
    s3_bucket: {{if exists "/deis/registry/bucketName"}}{{ getv "/deis/registry/bucketName" }}{{ else }}""{{ end }}
    s3_encrypt: false
    s3_secure: false
    storage_path: /registry
    s3_access_key: {{if exists "/deis/store/gateway/accessKey"}}{{ getv "/deis/store/gateway/accessKey" }}{{ else }}""{{ end }}
    s3_secret_key: {{if exists "/deis/store/gateway/secretKey"}}{{ getv "/deis/store/gateway/secretKey" }}{{ else }}""{{ end }}
    boto_bucket: {{if exists "/deis/registry/bucketName"}}{{ getv "/deis/registry/bucketName" }}{{ else }}""{{ end }}
    boto_host: {{if exists "/deis/store/gateway/host"}}{{ getv "/deis/store/gateway/host" }}{{ else }}""{{ end }}
    boto_port: {{if exists "/deis/store/gateway/port"}}{{ getv "/deis/store/gateway/port" }}{{ else }}""{{ end }}
    boto_debug: 0
    boto_calling_format: boto.s3.connection.OrdinaryCallingFormat

# Google Cloud Storage Configuration
# See:
# https://developers.google.com/storage/docs/reference/v1/getting-startedv1#keys
# for details on access and secret keys.
gcs:
    <<: *common
    storage: gcs
    boto_bucket: _env:GCS_BUCKET
    storage_path: _env:STORAGE_PATH:/registry
    gs_secure: _env:GCS_SECURE:true
    gs_access_key: _env:GCS_KEY
    gs_secret_key: _env:GCS_SECRET
    # OAuth 2.0 authentication with the storage.
    # oauth2 can be set to true or false. If it is set to true, gs_access_key,
    # gs_secret_key and gs_secure are not needed.
    # Client ID and Client Secret must be set into OAUTH2_CLIENT_ID and
    # OAUTH2_CLIENT_SECRET environment variables.
    # See: https://developers.google.com/accounts/docs/OAuth2.
    oauth2: _env:GCS_OAUTH2:false

# This flavor is for storing images in Openstack Swift
swift: &swift
    <<: *common
    storage: swift
    storage_path: _env:STORAGE_PATH:/registry
    # keystone authorization
    swift_authurl: {{ if exists "/deis/registry/swiftAuthURL" }}{{ getv "/deis/registry/swiftAuthURL" }}{{ else }}""{{ end }}
    swift_container: {{ if exists "/deis/registry/swiftContainer" }}{{ getv "/deis/registry/swiftContainer" }}{{ else }}""{{ end }}
    swift_user: {{ if exists "/deis/registry/swiftUser" }}{{ getv "/deis/registry/swiftUser" }}{{ else }}""{{ end }}
    swift_password: {{ if exists "/deis/registry/swiftPassword" }}{{ getv "/deis/registry/swiftPassword" }}{{ else }}""{{ end }}
    swift_tenant_name: {{ if exists "/deis/registry/swiftTenantName" }}{{ getv "/deis/registry/swiftTenantName" }}{{ else }}""{{ end }}
    swift_region_name: {{ if exists "/deis/registry/swiftRegionName" }}{{ getv "/deis/registry/swiftRegionName" }}{{ else }}""{{ end }}

# This flavor stores the images in Glance (to integrate with openstack)
# See also: https://github.com/dotcloud/openstack-docker
glance: &glance
    <<: *common
    storage: glance
    storage_alternate: _env:GLANCE_STORAGE_ALTERNATE:file
    storage_path: _env:STORAGE_PATH:/tmp/registry

openstack:
    <<: *glance

# This flavor stores the images in Glance (to integrate with openstack)
# and tags in Swift.
glance-swift: &glance-swift
    <<: *swift
    storage: glance
    storage_alternate: swift

openstack-swift:
    <<: *glance-swift

elliptics:
    <<: *common
    storage: elliptics
    elliptics_nodes: _env:ELLIPTICS_NODES
    elliptics_wait_timeout: _env:ELLIPTICS_WAIT_TIMEOUT:60
    elliptics_check_timeout: _env:ELLIPTICS_CHECK_TIMEOUT:60
    elliptics_io_thread_num: _env:ELLIPTICS_IO_THREAD_NUM:2
    elliptics_net_thread_num: _env:ELLIPTICS_NET_THREAD_NUM:2
    elliptics_nonblocking_io_thread_num: _env:ELLIPTICS_NONBLOCKING_IO_THREAD_NUM:2
    elliptics_groups: _env:ELLIPTICS_GROUPS
    elliptics_verbosity: _env:ELLIPTICS_VERBOSITY:4
    elliptics_logfile: _env:ELLIPTICS_LOGFILE:/dev/stderr
    elliptics_addr_family: _env:ELLIPTICS_ADDR_FAMILY:2

# This is the default configuration when no flavor is specified
dev: &dev
    <<: *local
    loglevel: _env:LOGLEVEL:debug
    search_backend: _env:SEARCH_BACKEND:sqlalchemy

# This flavor is used by unit tests
test:
    <<: *dev
    index_endpoint: https://indexstaging-docker.dotcloud.com
    standalone: true
    storage_path: _env:STORAGE_PATH:./tmp/test

# To specify another flavor, set the environment variable SETTINGS_FLAVOR
# $ export SETTINGS_FLAVOR=prod
prod:
    <<: *s3
    storage_path: _env:STORAGE_PATH:/prod

# Flavor used by deis
deis:
    {{ if exists "/deis/registry/s3bucket" }}<<: *s3
    {{ else if exists "/deis/registry/swiftAuthURL" }} <<: *openstack-swift
    {{ else }} <<: *ceph-s3
    {{ end }}
