Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] add mirror registry list to support private(insecure) registry #241

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": []
}