func generatePreparerPod(workdir string, userHookManifest manifest.Manifest) (string, error) { // build the artifact from HEAD output, err := exec.Command("go", "build", "github.com/square/p2/bin/p2-preparer").CombinedOutput() if err != nil { return "", util.Errorf("Couldn't build preparer: %s\nOutput:\n%s", err, string(output)) } wd, _ := os.Getwd() hostname, err := os.Hostname() if err != nil { return "", util.Errorf("Couldn't get hostname: %s", err) } // the test number forces the pod manifest to change every test run. testNumber := fmt.Sprintf("test=%d", rand.Intn(2000000000)) cmd := exec.Command("p2-bin2pod", "--work-dir", workdir, "--id", "p2-preparer", "--config", fmt.Sprintf("node_name=%s", hostname), "--config", testNumber, wd+"/p2-preparer") prepBin2Pod, err := executeBin2Pod(cmd) if err != nil { return "", err } if err = signBuild(prepBin2Pod.TarPath); err != nil { return "", err } manifest, err := manifest.FromPath(prepBin2Pod.ManifestPath) if err != nil { return "", err } builder := manifest.GetBuilder() builder.SetID("p2-preparer") envExtractorPath, err := exec.Command("which", "p2-finish-env-extractor").CombinedOutput() if err != nil { return "", fmt.Errorf("Could not find p2-finish-env-extractor on PATH") } userCreationHookBytes, err := userHookManifest.Marshal() if err != nil { return "", util.Errorf("Couldn't marshal user hook manifest: %s", err) } err = builder.SetConfig(map[interface{}]interface{}{ "preparer": map[interface{}]interface{}{ "auth": map[string]string{ "type": "keyring", "keyring": util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"), }, "artifact_auth": map[interface{}]interface{}{ "type": "build", "keyring": util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"), }, "ca_file": filepath.Join(certpath, "cert.pem"), "cert_file": filepath.Join(certpath, "cert.pem"), "key_file": filepath.Join(certpath, "key.pem"), "status_port": preparerStatusPort, "process_result_reporter_config": map[string]string{ "sqlite_database_path": sqliteFinishDatabasePath, "environment_extractor_path": strings.TrimSpace(string(envExtractorPath)), "workspace_dir_path": "/data/pods/p2-preparer/tmp", }, "hooks_manifest": string(userCreationHookBytes), }, }) if err != nil { return "", err } builder.SetRunAsUser("root") builder.SetStatusPort(preparerStatusPort) builder.SetStatusHTTP(true) manifest = builder.GetManifest() manifestBytes, err := manifest.Marshal() if err != nil { return "", err } err = ioutil.WriteFile(prepBin2Pod.ManifestPath, manifestBytes, 0644) if err != nil { return "", err } return prepBin2Pod.ManifestPath, err }
func generatePreparerPod(workdir string) (string, error) { // build the artifact from HEAD err := exec.Command("go", "build", "github.com/square/p2/bin/p2-preparer").Run() if err != nil { return "", util.Errorf("Couldn't build preparer: %s", err) } wd, _ := os.Getwd() hostname, err := os.Hostname() if err != nil { return "", util.Errorf("Couldn't get hostname: %s", err) } // the test number forces the pod manifest to change every test run. testNumber := fmt.Sprintf("test=%d", rand.Intn(2000000000)) cmd := exec.Command("p2-bin2pod", "--work-dir", workdir, "--id", "p2-preparer", "--config", fmt.Sprintf("node_name=%s", hostname), "--config", testNumber, wd+"/p2-preparer") prepBin2Pod, err := executeBin2Pod(cmd) if err != nil { return "", err } if err = signBuild(prepBin2Pod.TarPath); err != nil { return "", err } manifest, err := manifest.FromPath(prepBin2Pod.ManifestPath) if err != nil { return "", err } builder := manifest.GetBuilder() builder.SetID("p2-preparer") err = builder.SetConfig(map[interface{}]interface{}{ "preparer": map[interface{}]interface{}{ "auth": map[string]string{ "type": "keyring", "keyring": util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"), }, "artifact_auth": map[interface{}]interface{}{ "type": "build", "keyring": util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"), }, "ca_file": filepath.Join(certpath, "cert.pem"), "cert_file": filepath.Join(certpath, "cert.pem"), "key_file": filepath.Join(certpath, "key.pem"), "status_port": preparerStatusPort, }, }) if err != nil { return "", err } builder.SetRunAsUser("root") builder.SetStatusPort(preparerStatusPort) builder.SetStatusHTTP(true) manifest = builder.GetManifest() manifestBytes, err := manifest.Marshal() if err != nil { return "", err } err = ioutil.WriteFile(prepBin2Pod.ManifestPath, manifestBytes, 0644) if err != nil { return "", err } return prepBin2Pod.ManifestPath, err }