diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index ba88c79b..b3d127ba 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -67,7 +67,17 @@ The config file is `/etc/overlaybd-snapshotter/config.json`. Please create the f "enable": false, "uriPrefix": "/metrics", "port": 9863 - } + }, + "mirrorRegistry": [ + { + "host": "localhost:5000", + "insecure": true + }, + { + "host": "registry-1.docker.io", + "insecure": false + } + ] } ``` | Field | Description | @@ -81,6 +91,9 @@ The config file is `/etc/overlaybd-snapshotter/config.json`. Please create the f | `exporterConfig.enable` | whether or not create a server to show Prometheus metrics | | `exporterConfig.uriPrefix` | URI prefix for export metrics, default `/metrics` | | `exporterConfig.port` | port for http server to show metrics, default `9863` | +| `mirrorRegistry` | an arrary of mirror registries | +| `mirrorRegistry.host` | host address, eg. `registry-1.docker.io`` | +| `mirrorRegistry.insecure` | `true` or `false` | #### Start service diff --git a/pkg/snapshot/overlay.go b/pkg/snapshot/overlay.go index 1e5f05bd..721483df 100644 --- a/pkg/snapshot/overlay.go +++ b/pkg/snapshot/overlay.go @@ -28,6 +28,7 @@ import ( "github.com/containerd/accelerated-container-image/pkg/label" "github.com/containerd/accelerated-container-image/pkg/metrics" + "github.com/sirupsen/logrus" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" @@ -66,6 +67,11 @@ const ( RwDev = "dev" // use overlaybd directly ) +type Registry struct { + Host string `json:"host"` + Insecure bool `json:"insecure"` +} + type BootConfig struct { Address string `json:"address"` Root string `json:"root"` @@ -75,6 +81,7 @@ type BootConfig struct { AutoRemoveDev bool `json:"autoRemoveDev"` ExporterConfig metrics.ExporterConfig `json:"exporterConfig"` WritableLayerType string `json:"writableLayerType"` // append or sparse + MirrorRegistry []Registry `json:"mirrorRegistry"` } func DefaultBootConfig() *BootConfig { @@ -88,6 +95,7 @@ func DefaultBootConfig() *BootConfig { UriPrefix: "/metrics", Port: 9863, }, + MirrorRegistry: nil, WritableLayerType: "append", } } @@ -153,6 +161,7 @@ type snapshotter struct { indexOff bool autoRemoveDev bool writableLayerType string + mirrorRegistry []Registry locker *locker.Locker } @@ -190,6 +199,10 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter, indexOff = true } + if bootConfig.MirrorRegistry != nil { + logrus.Infof("mirror Registry: %+v", bootConfig.MirrorRegistry) + } + return &snapshotter{ root: bootConfig.Root, rwMode: bootConfig.RwMode, @@ -199,6 +212,7 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter, metacopyOption: metacopyOption, autoRemoveDev: bootConfig.AutoRemoveDev, writableLayerType: bootConfig.WritableLayerType, + mirrorRegistry: bootConfig.MirrorRegistry, locker: locker.New(), }, nil } diff --git a/pkg/snapshot/storage.go b/pkg/snapshot/storage.go index d4c3ff35..21c9eec3 100644 --- a/pkg/snapshot/storage.go +++ b/pkg/snapshot/storage.go @@ -634,7 +634,13 @@ func (o *snapshotter) constructImageBlobURL(ref string) (string, error) { if host == "docker.io" { host = "registry-1.docker.io" } - return "https://" + path.Join(host, "v2", repo) + "/blobs", nil + scheme := "https://" + for _, reg := range o.mirrorRegistry { + if host == reg.Host && reg.Insecure { + scheme = "http://" + } + } + return scheme + path.Join(host, "v2", repo) + "/blobs", nil } // atomicWriteOverlaybdTargetConfig diff --git a/script/config.json b/script/config.json index 3de6c0dd..0a558eaa 100644 --- a/script/config.json +++ b/script/config.json @@ -4,5 +4,6 @@ "verbose": "info", "rwMode": "overlayfs", "logReportCaller": false, - "autoRemoveDev": false -} \ No newline at end of file + "autoRemoveDev": false, + "mirrorRegistry": [] +}