kind: ConfigMap
apiVersion: v1
metadata:
    name: gitlab-registry
    namespace: gitlab
    selfLink: /api/v1/namespaces/gitlab/configmaps/gitlab-registry
    uid: 9805c5ad-398b-11ea-b115-42010a8001d6
    resourceVersion: '2016120'
    creationTimestamp: '2020-01-18T00:43:50Z'
    labels:
        app: registry
        chart: registry-0.3.0
        heritage: Helm
        release: gitlab
data:
    config.yml: |
        version: 0.1
        log:
          fields:
            service: registry
          level: warn
        http:
          debug:
            addr: ':5001'
            prometheus:
              enabled: false
              path: /metrics
          draintimeout: 0
          headers:
            X-Content-Type-Options: [nosniff]
          addr: :5000
          secret: "HTTP_SECRET"
          relativeurls: false
        health:
          storagedriver:
            enabled: false
            interval: 10s
            threshold: 3
        auth:
          token:
            realm: https://gitlab.example.com/jwt/auth
            service: container_registry
            issuer: "gitlab-issuer"
            # This is provided from the initContainer execution, at a known path.
            rootcertbundle: /etc/docker/registry/certificate.crt
            autoredirect: false
        compatibility:
          schema1:
            enabled: false
        validation:
          disabled: true
        storage:
          maintenance:
            readonly:
              enabled: false
          s3:
            accesskey: "ACCESS_KEY"
            secretkey: "SECRET_KEY"
            region: us-east-1
            regionendpoint: http://gitlab-minio-svc:9000
            bucket: registry
            secure: true
            v4auth: true
            rootdirectory: /
          cache:
            blobdescriptor: 'inmemory'
          delete:
            enabled: true
          redirect:
            disable: true
    configure: >-
        if [ -e /config/accesskey ] ; then
          sed -e 's@ACCESS_KEY@'"$(cat /config/accesskey)"'@' -e 's@SECRET_KEY@'"$(cat /config/secretkey)"'@' /config/config.yml > /registry/config.yml
        else
          cp -v -r -L /config/config.yml  /registry/config.yml
        fi

        # Place the `http.secret` value from the kubernetes secret

        sed -i -e 's@HTTP_SECRET@'"$(cat /config/httpSecret)"'@'
        /registry/config.yml

        # Insert any provided `storage` block from kubernetes secret

        if [ -d /config/storage ]; then
          # Copy contents of storage secret(s)
          mkdir -p /registry/storage
          cp -v -r -L /config/storage/* /registry/storage/
          # Ensure there is a new line in the end
          echo '' >> /registry/storage/config
          # Default `delete.enabled: true` if not present.
          ## Note: busybox grep doesn't support multiline, so we chain `egrep`.
          if ! $(egrep -A1 '^delete:\s*$' /registry/storage/config | egrep -q '\s{2,4}enabled:') ; then
            echo 'delete:' >> /registry/storage/config
            echo '  enabled: true' >> /registry/storage/config
          fi
          # Indent /registry/storage/config 2 spaces before inserting into config.yml
          sed -i 's/^/  /' /registry/storage/config
          # Insert into /registry/config.yml after `storage:`
          sed -i '/storage:/ r /registry/storage/config' /registry/config.yml
          # Remove the now extraneous `config` file
          rm /registry/storage/config
        fi

        # Set to known path, to used ConfigMap

        cat /config/certificate.crt > /registry/certificate.crt

