github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/integration-tests/disconnected_install.go (about)

     1  package integration_tests
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"runtime"
     7  	"time"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  )
    11  
    12  // creates a package repository mirror on the given node.
    13  func createPackageRepositoryMirror(repoNode NodeDeets, distro linuxDistro, sshKey string) error {
    14  	var mirrorScript string
    15  	switch distro {
    16  	case CentOS7:
    17  		mirrorScript = "mirror-rpms.sh"
    18  	case Ubuntu1604LTS:
    19  		mirrorScript = "mirror-debs.sh"
    20  	default:
    21  		return fmt.Errorf("unable to create repo mirror for distro %q", distro)
    22  	}
    23  	start := time.Now()
    24  	err := copyFileToRemote("test-resources/disconnected-installation/"+mirrorScript, "/tmp/"+mirrorScript, repoNode, sshKey, 10*time.Second)
    25  	if err != nil {
    26  		return fmt.Errorf("failed to copy script to remote node: %v", err)
    27  	}
    28  	cmds := []string{"chmod +x /tmp/" + mirrorScript, "sudo /tmp/" + mirrorScript}
    29  	err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 120*time.Minute)
    30  	if err != nil {
    31  		return fmt.Errorf("error running mirroring script: %v", err)
    32  	}
    33  	elapsed := time.Since(start)
    34  	fmt.Println("Creating a package repository took", elapsed)
    35  	return nil
    36  }
    37  
    38  // seeds a container image registry using the kismatic seed-registry command
    39  func seedRegistry(repoNode NodeDeets, registryCAFile string, registryPort int, sshKey string) error {
    40  	By("Adding the docker registry self-signed cert to the registry node")
    41  	registry := fmt.Sprintf("%s:%d", repoNode.PublicIP, registryPort)
    42  	err := copyFileToRemote(registryCAFile, "/tmp/docker-registry-ca.crt", repoNode, sshKey, 30*time.Second)
    43  	if err != nil {
    44  		return fmt.Errorf("Failed to copy registry cert to registry node: %v", err)
    45  	}
    46  	cmds := []string{
    47  		fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", registry),
    48  		fmt.Sprintf("sudo mv /tmp/docker-registry-ca.crt /etc/docker/certs.d/%s/ca.crt", registry),
    49  	}
    50  	err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 10*time.Minute)
    51  	if err != nil {
    52  		return fmt.Errorf("Error adding self-signed cert to registry node: %v", err)
    53  	}
    54  
    55  	By("Copying KET to the registry node for seeding")
    56  	err = copyFileToRemote(filepath.Join(currentKismaticDir, "kismatic-"+runtime.GOOS+".tar.gz"), "/tmp/kismatic-"+runtime.GOOS+".tar.gz", repoNode, sshKey, 5*time.Minute)
    57  	if err != nil {
    58  		return fmt.Errorf("Error copying KET to the registry node: %v", err)
    59  	}
    60  
    61  	By("Seeding the registry")
    62  	start := time.Now()
    63  	cmds = []string{
    64  		fmt.Sprintf("echo 'y' | sudo docker login -u kismaticuser -p kismaticpassword %s", registry),
    65  		"sudo mkdir kismatic",
    66  		"sudo tar -xf /tmp/kismatic-" + runtime.GOOS + ".tar.gz -C kismatic",
    67  		fmt.Sprintf("sudo ./kismatic/kismatic seed-registry --server %s", registry),
    68  	}
    69  	err = runViaSSH(cmds, []NodeDeets{repoNode}, sshKey, 30*time.Minute)
    70  	if err != nil {
    71  		return fmt.Errorf("failed to seed the registry: %v", err)
    72  	}
    73  	elapsed := time.Since(start)
    74  	fmt.Println("Seeding the registry took", elapsed)
    75  	return nil
    76  }