func (conf *Config) EnvListForEndpoint(dockerEndpoint, poolName string) ([]string, error) { tsuruEndpoint, _ := config.GetString("host") if !strings.HasPrefix(tsuruEndpoint, "http://") && !strings.HasPrefix(tsuruEndpoint, "https://") { tsuruEndpoint = "http://" + tsuruEndpoint } tsuruEndpoint = strings.TrimRight(tsuruEndpoint, "/") + "/" endpoint := dockerEndpoint socket, _ := config.GetString("docker:bs:socket") if socket != "" { endpoint = "unix:///var/run/docker.sock" } token, err := conf.getToken() if err != nil { return nil, err } envList := []string{ "DOCKER_ENDPOINT=" + endpoint, "TSURU_ENDPOINT=" + tsuruEndpoint, "TSURU_TOKEN=" + token, "SYSLOG_LISTEN_ADDRESS=udp://0.0.0.0:" + strconv.Itoa(container.BsSysLogPort()), } envMap := EnvMap{} poolEnvMap := PoolEnvMap{} err = conf.UpdateEnvMaps(envMap, poolEnvMap) if err != nil { return nil, err } for envName, envValue := range envMap { envList = append(envList, fmt.Sprintf("%s=%s", envName, envValue)) } for envName, envValue := range poolEnvMap[poolName] { envList = append(envList, fmt.Sprintf("%s=%s", envName, envValue)) } return envList, nil }
func InitializeBS() (bool, error) { bsNodeContainer, err := LoadNodeContainer("", BsDefaultName) if err != nil { return false, err } if len(bsNodeContainer.Config.Env) > 0 { return false, nil } tokenData, err := app.AuthScheme.AppLogin(app.InternalAppName) if err != nil { return false, err } token := tokenData.GetValue() conf := configFor(BsDefaultName) isSet, err := conf.SetFieldAtomic("", "Config.Env", []string{ "TSURU_TOKEN=" + token, }) if !isSet { // Already set by someone else, just bail out. app.AuthScheme.Logout(token) return false, nil } bsNodeContainer, err = LoadNodeContainer("", BsDefaultName) if err != nil { return true, err } tsuruEndpoint, _ := config.GetString("host") if !strings.HasPrefix(tsuruEndpoint, "http://") && !strings.HasPrefix(tsuruEndpoint, "https://") { tsuruEndpoint = "http://" + tsuruEndpoint } tsuruEndpoint = strings.TrimRight(tsuruEndpoint, "/") + "/" socket, _ := config.GetString("docker:bs:socket") image, _ := config.GetString("docker:bs:image") if image == "" { image = bsDefaultImageName } bsNodeContainer.Name = BsDefaultName bsNodeContainer.Config.Env = append(bsNodeContainer.Config.Env, []string{ "TSURU_ENDPOINT=" + tsuruEndpoint, "HOST_PROC=" + bsHostProc, "SYSLOG_LISTEN_ADDRESS=" + fmt.Sprintf("udp://0.0.0.0:%d", container.BsSysLogPort()), }...) bsNodeContainer.Config.Image = image bsNodeContainer.HostConfig.RestartPolicy = docker.AlwaysRestart() bsNodeContainer.HostConfig.Privileged = true bsNodeContainer.HostConfig.NetworkMode = "host" bsNodeContainer.HostConfig.Binds = []string{fmt.Sprintf("/proc:%s:ro", bsHostProc)} if socket != "" { bsNodeContainer.Config.Env = append(bsNodeContainer.Config.Env, "DOCKER_ENDPOINT=unix:///var/run/docker.sock") bsNodeContainer.HostConfig.Binds = append(bsNodeContainer.HostConfig.Binds, fmt.Sprintf("%s:/var/run/docker.sock:rw", socket)) } return true, conf.Save("", bsNodeContainer) }
func EnvListForEndpoint(dockerEndpoint, poolName string) ([]string, error) { bsConf, err := provision.FindScopedConfig(bsUniqueID) if err != nil { return nil, err } tsuruEndpoint, _ := config.GetString("host") if !strings.HasPrefix(tsuruEndpoint, "http://") && !strings.HasPrefix(tsuruEndpoint, "https://") { tsuruEndpoint = "http://" + tsuruEndpoint } tsuruEndpoint = strings.TrimRight(tsuruEndpoint, "/") + "/" endpoint := dockerEndpoint socket, _ := config.GetString("docker:bs:socket") if socket != "" { endpoint = "unix:///var/run/docker.sock" } token, err := getToken(bsConf) if err != nil { return nil, err } baseEnvMap := map[string]string{ "DOCKER_ENDPOINT": endpoint, "TSURU_ENDPOINT": tsuruEndpoint, "TSURU_TOKEN": token, "SYSLOG_LISTEN_ADDRESS": fmt.Sprintf("udp://0.0.0.0:%d", container.BsSysLogPort()), } var envList []string for envName, envValue := range bsConf.PoolEntries(poolName) { if _, isBase := baseEnvMap[envName]; isBase { continue } envList = append(envList, fmt.Sprintf("%s=%s", envName, envValue.Value)) } for name, value := range baseEnvMap { envList = append(envList, fmt.Sprintf("%s=%s", name, value)) } return envList, nil }