func registryCerts(testAgent test_with_docker.Agent, composeDir string, desc desc.EnvDesc) error { registryCertName := "testing.crt" certPath := filepath.Join(composeDir, registryCertName) caPath := fmt.Sprintf("/etc/docker/certs.d/%s/ca.crt", desc.RegistryName) certIPs, err := getCertIPSans(filepath.Join(composeDir, registryCertName)) if err != nil { return err } haveIP := false for _, certIP := range certIPs { if certIP.Equal(desc.AgentIP) { haveIP = true break } } if !haveIP { log.Printf("Rebuilding the registry certificate to add %v", desc.AgentIP) certIPs = append(certIPs, desc.AgentIP) err = buildTestingKeypair(composeDir, certIPs) if err != nil { return fmt.Errorf("While building testing keypair: %s", err) } err = testAgent.RebuildService(composeDir, "registry") if err != nil { return fmt.Errorf("While rebuilding the registry service: %s", err) } } differs, err := testAgent.DifferingFiles([]string{certPath, caPath}) if err != nil { return fmt.Errorf("While checking for differing certs: %s", err) } for _, diff := range differs { local, remote := diff[0], diff[1] log.Printf("Copying %q to %q\n", local, remote) err = testAgent.InstallFile(local, remote) if err != nil { return fmt.Errorf("installFile failed: %s", err) } } if len(differs) > 0 { err = testAgent.RestartDaemon() if err != nil { return fmt.Errorf("restarting docker machine's daemon failed: %s", err) } } return nil }
func setupServices(testAgent test_with_docker.Agent, opts *options) *desc.EnvDesc { desc := desc.EnvDesc{} var err error if desc.AgentIP, err = testAgent.IP(); err != nil { log.Fatal(err) } if desc.AgentIP == nil { log.Fatal(fmt.Errorf("Test agent returned nil IP")) } desc.RegistryName = fmt.Sprintf("%s:%d", desc.AgentIP, 5000) desc.SingularityURL = fmt.Sprintf("http://%s:%d/singularity", desc.AgentIP, 7099) if err := registryCerts(testAgent, opts.composeDir, desc); err != nil { log.Fatal(err) } if _, err := testAgent.ComposeServices(opts.composeDir, map[string]uint{"Singularity": 7099, "Registry": 5000}); err != nil { log.Fatal(err) } return &desc }
func teardownServices(testAgent test_with_docker.Agent, opts *options) { testAgent.ShutdownNow() }