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

improve: support multiple registry mirrors #463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cmd/drone-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {
},
cli.StringFlag{
Name: "daemon.mirror",
Usage: "docker daemon registry mirror",
Usage: "docker daemon registry mirror. Multiple mirrors are separated by commas ','",
EnvVar: "PLUGIN_MIRROR,DOCKER_PLUGIN_MIRROR",
},
cli.StringFlag{
Expand Down
74 changes: 74 additions & 0 deletions daemon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package docker

import (
"os/exec"
"reflect"
"testing"
)

func TestCommandStartDaemon(t *testing.T) {
tcs := []struct {
name string
daemon Daemon
want *exec.Cmd
}{
{
name: "multi mirrors",
daemon: Daemon{
StoragePath: "/var/lib/docker",
Mirror: "https://a.com,https://b.com,https://c.com",
},
want: exec.Command(
dockerdExe,
"--data-root",
"/var/lib/docker",
"--host=unix:///var/run/docker.sock",
"--registry-mirror",
"https://a.com",
"--registry-mirror",
"https://b.com",
"--registry-mirror",
"https://c.com",
),
},
{
name: "single mirrors",
daemon: Daemon{
StoragePath: "/var/lib/docker",
Mirror: "https://a.com",
},
want: exec.Command(
dockerdExe,
"--data-root",
"/var/lib/docker",
"--host=unix:///var/run/docker.sock",
"--registry-mirror",
"https://a.com",
),
},
{
name: "zero mirrors",
daemon: Daemon{
StoragePath: "/var/lib/docker",
},
want: exec.Command(
dockerdExe,
"--data-root",
"/var/lib/docker",
"--host=unix:///var/run/docker.sock",
),
},
}

for _, tc := range tcs {
tc := tc

t.Run(tc.name, func(t *testing.T) {
cmd := commandDaemon(tc.daemon)

if !reflect.DeepEqual(cmd.String(), tc.want.String()) {
t.Errorf("Got cmd %v, want %v", cmd, tc.want)
}
})
}
}
5 changes: 4 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ func commandDaemon(daemon Daemon) *exec.Cmd {
args = append(args, "--ipv6")
}
if len(daemon.Mirror) != 0 {
args = append(args, "--registry-mirror", daemon.Mirror)
mirrors := strings.Split(daemon.Mirror, ",")
for _, mirror := range mirrors {
args = append(args, "--registry-mirror", mirror)
}
}
if len(daemon.Bip) != 0 {
args = append(args, "--bip", daemon.Bip)
Expand Down