This repository has been archived by the owner on Jan 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry_mirrors.go
75 lines (63 loc) · 1.8 KB
/
registry_mirrors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package runs
import (
"io/ioutil"
. "github.com/saschagrunert/crio-demos/pkg/demo"
"github.com/urfave/cli"
)
const r2 = `unqualified-search-registries = ["docker.io"]
[[registry]]
location = "docker.io/library"
mirror = [
{ location = "localhost/mirror-path" }, # doesnt work
{ location = "localhost:5000", insecure = true }, # should work
]
`
func RegistryMirrors(ctx *cli.Context) error {
if err := ioutil.WriteFile(f, []byte(r2), 0o644); err != nil {
return err
}
Ensure(
"[ ! -f "+r+".bak ] && sudo mv "+r+" "+r+".bak",
"sudo cp "+f+" "+r,
"rm "+f,
"sudo systemctl reload crio",
)
d := New(
"Registry Mirrors",
"This demo shows how to configure registries mirrors in CRI-O",
)
d.Step(S(
"Registry mirrors are especially useful in air-gapped scenarios,",
"where access to the internet is limited.",
"A registry mirror can be configured like this",
), S(
`grep -A5 '^\[\[registry\]\]' `+r,
))
d.Step(S(
"To let the mirror work, we would have to setup one",
"For this we use podman to setup a local registry",
), S(
"podman run --rm --name=registry -p 5000:5000 -d registry",
))
d.Step(S(
"Podman uses the same registry configuration as CRI-O",
"So we can transfer our target image into the local registry",
), S(
"podman pull hello-world &&",
"podman tag hello-world localhost:5000/hello-world &&",
"podman push --tls-verify=false localhost:5000/hello-world",
))
d.Step(S(
"If we now pull an image from docker.io, then we first lookup our",
"configured mirrors.",
), S(
"sudo crictl pull hello-world",
))
d.Step(S(
"The logs show us that the image got pulled successfully from the mirror",
), S(
"sudo journalctl -u crio --since '1 minute ago' |",
`grep -Po "(reference rewritten from|Trying to pull|Downloading|GET).*"`,
))
return d.Run(ctx)
}