Skip to content

Commit

Permalink
[feat] add mirror registry list to support private(insecure) registry
Browse files Browse the repository at this point in the history
Signed-off-by: Yifan Yuan <tuji.yyf@alibaba-inc.com>
  • Loading branch information
BigVan committed Nov 10, 2023
1 parent a13f493 commit 2bbda3f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
15 changes: 14 additions & 1 deletion docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -88,6 +95,7 @@ func DefaultBootConfig() *BootConfig {
UriPrefix: "/metrics",
Port: 9863,
},
MirrorRegistry: nil,
WritableLayerType: "append",
}
}
Expand Down Expand Up @@ -153,6 +161,7 @@ type snapshotter struct {
indexOff bool
autoRemoveDev bool
writableLayerType string
mirrorRegistry []Registry

locker *locker.Locker
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions script/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"verbose": "info",
"rwMode": "overlayfs",
"logReportCaller": false,
"autoRemoveDev": false
}
"autoRemoveDev": false,
"mirrorRegistry": []
}

0 comments on commit 2bbda3f

Please sign in to comment.