forked from bsteciuk/kismatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisconnected_install.go
74 lines (68 loc) · 2.67 KB
/
disconnected_install.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
package integration
import (
"fmt"
"path/filepath"
"time"
. "github.com/onsi/ginkgo"
)
// creates a package repository mirror on the given node.
func createPackageRepositoryMirror(repoNode NodeDeets, distro linuxDistro, sshKey string) error {
var mirrorScript string
switch distro {
case CentOS7:
mirrorScript = "mirror-rpms.sh"
case Ubuntu1604LTS:
mirrorScript = "mirror-debs.sh"
default:
return fmt.Errorf("unable to create repo mirror for distro %q", distro)
}
start := time.Now()
err := copyFileToRemote("test-resources/disconnected-installation/"+mirrorScript, "/tmp/"+mirrorScript, repoNode, sshKey, 10*time.Second)
if err != nil {
return fmt.Errorf("failed to copy script to remote node: %v", err)
}
cmds := []string{"chmod +x /tmp/" + mirrorScript, "sudo /tmp/" + mirrorScript}
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 45*time.Minute)
if err != nil {
return fmt.Errorf("error running mirroring script: %v", err)
}
elapsed := time.Since(start)
fmt.Println("Creating a package repository took", elapsed)
return nil
}
// seeds a container image registry using the kismatic seed-registry command
func seedRegistry(repoNode NodeDeets, registryCAFile string, registryPort int, sshKey string) error {
By("Adding the docker registry self-signed cert to the registry node")
registry := fmt.Sprintf("%s:%d", repoNode.PublicIP, registryPort)
err := copyFileToRemote(registryCAFile, "/tmp/docker-registry-ca.crt", repoNode, sshKey, 30*time.Second)
if err != nil {
return fmt.Errorf("Failed to copy registry cert to registry node: %v", err)
}
cmds := []string{
fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", registry),
fmt.Sprintf("sudo mv /tmp/docker-registry-ca.crt /etc/docker/certs.d/%s/ca.crt", registry),
}
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 10*time.Minute)
if err != nil {
return fmt.Errorf("Error adding self-signed cert to registry node: %v", err)
}
By("Copying KET to the registry node for seeding")
err = copyFileToRemote(filepath.Join(currentKismaticDir, "kismatic.tar.gz"), "/tmp/kismatic.tar.gz", repoNode, sshKey, 5*time.Minute)
if err != nil {
return fmt.Errorf("Error copying KET to the registry node: %v", err)
}
By("Seeding the registry")
start := time.Now()
cmds = []string{
fmt.Sprintf("sudo docker login -u kismaticuser -p kismaticpassword %s", registry),
"sudo tar -xf /tmp/kismatic.tar.gz",
fmt.Sprintf("sudo ./kismatic seed-registry --server %s", registry),
}
err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 30*time.Minute)
if err != nil {
return fmt.Errorf("failed to seed the registry: %v", err)
}
elapsed := time.Since(start)
fmt.Println("Seeding the registry took", elapsed)
return nil
}