github.com/uber/kraken@v0.1.4/lib/dockerregistry/config.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package dockerregistry
    15  
    16  import (
    17  	"github.com/uber/kraken/lib/dockerregistry/transfer"
    18  	"github.com/uber/kraken/lib/store"
    19  	"github.com/docker/distribution/configuration"
    20  	"github.com/docker/distribution/context"
    21  	"github.com/docker/distribution/registry"
    22  	"github.com/uber-go/tally"
    23  )
    24  
    25  const (
    26  	_rw = "rw"
    27  	_ro = "ro"
    28  )
    29  
    30  // Config defines registry configuration.
    31  type Config struct {
    32  	Docker configuration.Configuration `yaml:"docker"`
    33  }
    34  
    35  // ReadWriteParameters builds parameters for a read-write driver.
    36  func (c Config) ReadWriteParameters(
    37  	transferer transfer.ImageTransferer,
    38  	cas *store.CAStore,
    39  	metrics tally.Scope) configuration.Parameters {
    40  
    41  	return configuration.Parameters{
    42  		"constructor": _rw,
    43  		"config":      c,
    44  		"transferer":  transferer,
    45  		"castore":     cas,
    46  		"metrics":     metrics,
    47  	}
    48  }
    49  
    50  // ReadOnlyParameters builds parameters for a read-only driver.
    51  func (c Config) ReadOnlyParameters(
    52  	transferer transfer.ImageTransferer,
    53  	bs BlobStore,
    54  	metrics tally.Scope) configuration.Parameters {
    55  
    56  	return configuration.Parameters{
    57  		"constructor": _ro,
    58  		"config":      c,
    59  		"transferer":  transferer,
    60  		"blobstore":   bs,
    61  		"metrics":     metrics,
    62  	}
    63  }
    64  
    65  // Build builds a new docker registry.
    66  func (c Config) Build(parameters configuration.Parameters) (*registry.Registry, error) {
    67  	c.Docker.Storage = configuration.Storage{
    68  		Name: parameters,
    69  		// Redirect is enabled by default in docker registry.
    70  		// We implement redirect on proxy level so we do not need this in storage driver for now.
    71  		"redirect": configuration.Parameters{
    72  			"disable": true,
    73  		},
    74  	}
    75  	return registry.NewRegistry(context.Background(), &c.Docker)
    76  }