- if cmpt.goProg != "" {
- return boot.RunProgram(ctx, cmpt.goProg, nil, nil, "go", "run", ".")
- }
- if cmpt.runFunc != nil {
- return cmpt.runFunc(ctx, boot, stdout, stderr)
- }
- if cmpt.railsApp != "" {
- port, err := internalPort(cmpt.svc)
- if err != nil {
- return fmt.Errorf("bug: no InternalURLs for component %q: %v", cmpt.name, cmpt.svc.InternalURLs)
- }
- err = boot.setupRubyEnv()
- if err != nil {
- return err
- }
- var buf bytes.Buffer
- err = boot.RunProgram(ctx, cmpt.railsApp, &buf, nil, "gem", "list", "--details", "bundler")
- if err != nil {
- return err
- }
- for _, version := range []string{"1.11.0", "1.17.3", "2.0.2"} {
- if !strings.Contains(buf.String(), "("+version+")") {
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "gem", "install", "--user", "bundler:1.11", "bundler:1.17.3", "bundler:2.0.2")
- if err != nil {
- return err
- }
- break
- }
- }
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "bundle", "install", "--jobs", "4", "--path", filepath.Join(os.Getenv("HOME"), ".gem"))
- if err != nil {
- return err
- }
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "bundle", "exec", "passenger-config", "build-native-support")
- if err != nil {
- return err
- }
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "bundle", "exec", "passenger-config", "install-standalone-runtime")
- if err != nil {
- return err
- }
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "bundle", "exec", "passenger-config", "validate-install")
- if err != nil {
- return err
- }
- err = boot.RunProgram(ctx, cmpt.railsApp, nil, nil, "bundle", "exec", "passenger", "start", "-p", port)
- if err != nil {
- return err
- }
- }
- return fmt.Errorf("bug: component %q has nothing to run", cmpt.name)
-}
-
-func (boot *bootCommand) autofillConfig(cfg *arvados.Config, log logrus.FieldLogger) error {
- cluster, err := cfg.GetCluster("")
- if err != nil {
- return err
- }
- port := 9000
- for _, svc := range []*arvados.Service{
- &cluster.Services.Controller,
- &cluster.Services.DispatchCloud,
- &cluster.Services.GitHTTP,
- &cluster.Services.Health,
- &cluster.Services.Keepproxy,
- &cluster.Services.Keepstore,
- &cluster.Services.RailsAPI,
- &cluster.Services.WebDAV,
- &cluster.Services.WebDAVDownload,
- &cluster.Services.Websocket,
- } {
- if svc == &cluster.Services.DispatchCloud && boot.clusterType == "test" {
- continue
- }
- if len(svc.InternalURLs) == 0 {
- port++
- svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{
- arvados.URL{Scheme: "http", Host: fmt.Sprintf("localhost:%d", port)}: arvados.ServiceInstance{},
- }
- }
- if svc.ExternalURL.Host == "" && (svc == &cluster.Services.Controller ||
- svc == &cluster.Services.GitHTTP ||
- svc == &cluster.Services.Keepproxy ||
- svc == &cluster.Services.WebDAV ||
- svc == &cluster.Services.WebDAVDownload ||
- svc == &cluster.Services.Websocket) {
- port++
- svc.ExternalURL = arvados.URL{Scheme: "https", Host: fmt.Sprintf("localhost:%d", port)}
- }
- }
- if cluster.SystemRootToken == "" {
- cluster.SystemRootToken = randomHexString(64)
- }
- if cluster.ManagementToken == "" {
- cluster.ManagementToken = randomHexString(64)
- }
- if cluster.API.RailsSessionSecretToken == "" {
- cluster.API.RailsSessionSecretToken = randomHexString(64)
- }
- if cluster.Collections.BlobSigningKey == "" {
- cluster.Collections.BlobSigningKey = randomHexString(64)
- }
- if boot.clusterType != "production" && cluster.Containers.DispatchPrivateKey == "" {
- buf, err := ioutil.ReadFile(filepath.Join(boot.sourcePath, "lib", "dispatchcloud", "test", "sshkey_dispatch"))
- if err != nil {
- return err
- }
- cluster.Containers.DispatchPrivateKey = string(buf)
- }
- if boot.clusterType != "production" {
- cluster.TLS.Insecure = true
- }
- if boot.clusterType == "test" && len(cluster.Volumes) == 0 {
- cluster.Volumes = map[string]arvados.Volume{
- "zzzzz-nyw5e-000000000000000": arvados.Volume{
- Driver: "Directory",
- DriverParameters: json.RawMessage(fmt.Sprintf(`{"Root":%q}`, boot.tempdir+"/keep0")),
- },
- }
- }
- cfg.Clusters[cluster.ClusterID] = *cluster
- return nil
-}
-
-func randomHexString(chars int) string {
- b := make([]byte, chars/2)
- _, err := rand.Read(b)
- if err != nil {
- panic(err)
- }
- return fmt.Sprintf("%x", b)
-}
-
-func internalPort(svc arvados.Service) (string, error) {
- for u := range svc.InternalURLs {
- if _, p, err := net.SplitHostPort(u.Host); err != nil {
- return "", err
- } else if p != "" {
- return p, nil
- } else if u.Scheme == "https" {
- return "443", nil
- } else {
- return "80", nil
- }
- }
- return "", fmt.Errorf("service has no InternalURLs")
-}
-
-func externalPort(svc arvados.Service) (string, error) {
- if _, p, err := net.SplitHostPort(svc.ExternalURL.Host); err != nil {
- return "", err
- } else if p != "" {
- return p, nil
- } else if svc.ExternalURL.Scheme == "https" {
- return "443", nil
- } else {
- return "80", nil
- }