github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/registry/driver.go (about)

     1  // Copyright © 2022 Alibaba Group Holding Ltd.
     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  
    15  package registry
    16  
    17  import (
    18  	"net"
    19  
    20  	"github.com/sealerio/sealer/pkg/imagedistributor"
    21  )
    22  
    23  type Info struct {
    24  	URL string
    25  }
    26  
    27  // Driver provide external interaction to work with registry.
    28  type Driver interface {
    29  	// UploadContainerImages2Registry :upload src registry filesystem to registry data directory.
    30  	UploadContainerImages2Registry() error
    31  	GetInfo() Info
    32  }
    33  
    34  type localRegistryDriver struct {
    35  	dataDir     string
    36  	endpoint    string
    37  	distributor imagedistributor.Distributor
    38  	deployHosts []net.IP
    39  }
    40  
    41  func (l localRegistryDriver) UploadContainerImages2Registry() error {
    42  	return l.distributor.DistributeRegistry(l.deployHosts, l.dataDir)
    43  }
    44  
    45  func (l localRegistryDriver) GetInfo() Info {
    46  	return Info{URL: l.endpoint}
    47  }
    48  
    49  func newLocalRegistryDriver(endpoint string, dataDir string, deployHosts []net.IP, distributor imagedistributor.Distributor) Driver {
    50  	return localRegistryDriver{
    51  		endpoint:    endpoint,
    52  		distributor: distributor,
    53  		dataDir:     dataDir,
    54  		deployHosts: deployHosts,
    55  	}
    56  }
    57  
    58  type externalRegistryDriver struct {
    59  	endpoint string
    60  }
    61  
    62  func (l externalRegistryDriver) UploadContainerImages2Registry() error {
    63  	//not implement currently
    64  	return nil
    65  }
    66  
    67  func (l externalRegistryDriver) GetInfo() Info {
    68  	return Info{URL: l.endpoint}
    69  }
    70  
    71  func newExternalRegistryDriver(endpoint string) Driver {
    72  	return externalRegistryDriver{
    73  		endpoint: endpoint,
    74  	}
    75  }