Ejemplo n.º 1
0
func getControllerURL() string {
	// if DEIS_CONTROLLER_URL exists in the environment, use that
	controllerURL := os.Getenv("DEIS_CONTROLLER_URL")
	if controllerURL != "" {
		return controllerURL
	}

	// otherwise, rely on kubernetes and some DNS magic
	host := "deis." + DeisRootHostname
	if err := util.AddToEtcHosts(host); err != nil {
		log.Fatalf("Could not write %s to /etc/hosts (%s)", host, err)
	}
	// also gotta write a route for the builder
	builderHost := "deis-builder." + DeisRootHostname
	if err := util.AddToEtcHosts(builderHost); err != nil {
		log.Fatalf("Could not write %s to /etc/hosts (%s)", builderHost, err)
	}

	port := os.Getenv("DEIS_ROUTER_SERVICE_PORT")
	switch port {
	case "443":
		return "https://" + host
	case "80", "":
		return "http://" + host
	default:
		return fmt.Sprintf("http://%s:%s", host, port)
	}
}
Ejemplo n.º 2
0
func NewApp() App {
	name := fmt.Sprintf("test-%d", rand.Intn(999999999))
	app := App{
		Name: name,
		URL:  strings.Replace(settings.DeisControllerURL, "deis", name, 1),
	}
	// try adding the URL to /etc/hosts but don't cry if it's not in there because the user may
	// have other plans in store for DNS
	if err := util.AddToEtcHosts(fmt.Sprintf("%s.%s", name, settings.DeisRootHostname)); err != nil {
		fmt.Printf("WARNING: could not write %s to /etc/hosts (%s), continuing anyways\n",
			app.URL,
			err)
	}
	return app
}