Exemplo n.º 1
0
func (c *Client) getContainerConfig() *godocker.Config {

	// default environment variables
	envVariables := map[string]string{
		"ECS_LOGFILE":                   logDir + "/" + config.AgentLogFile,
		"ECS_DATADIR":                   dataDir,
		"ECS_AGENT_CONFIG_FILE_PATH":    config.AgentJSONConfigFile(),
		"ECS_UPDATE_DOWNLOAD_DIR":       config.CacheDirectory(),
		"ECS_UPDATES_ENABLED":           "true",
		"ECS_AVAILABLE_LOGGING_DRIVERS": "[\"json-file\",\"syslog\"]",
	}

	// merge in user-supplied environment variables
	for envKey, envValue := range c.loadEnvVariables() {
		envVariables[envKey] = envValue
	}

	var env []string
	for envKey, envValue := range envVariables {
		env = append(env, envKey+"="+envValue)
	}

	exposedPorts := map[godocker.Port]struct{}{
		agentIntrospectionPort + "/tcp": struct{}{},
	}

	return &godocker.Config{
		Env:          env,
		ExposedPorts: exposedPorts,
		Image:        config.AgentImageName,
	}
}
Exemplo n.º 2
0
func (c *Client) getContainerConfig() *godocker.Config {
	env := append(c.loadEnvVariables(),
		"ECS_LOGFILE="+logDir+"/"+config.AgentLogFile,
		"ECS_DATADIR="+dataDir,
		"ECS_AGENT_CONFIG_FILE_PATH="+config.AgentJSONConfigFile(),
		"ECS_UPDATE_DOWNLOAD_DIR="+config.CacheDirectory(),
		"ECS_UPDATES_ENABLED=true",
	)

	exposedPorts := map[godocker.Port]struct{}{
		agentIntrospectionPort + "/tcp": struct{}{},
	}

	return &godocker.Config{
		Env:          env,
		ExposedPorts: exposedPorts,
		Image:        config.AgentImageName,
	}
}
Exemplo n.º 3
0
func validateCommonCreateContainerOptions(opts godocker.CreateContainerOptions, t *testing.T) {
	if opts.Name != "ecs-agent" {
		t.Errorf("Expected container Name to be %s but was %s", "ecs-agent", opts.Name)
	}
	cfg := opts.Config

	if len(cfg.Env) < 3 {
		t.Errorf("Expected at least 3 elements to be in Env, but was %d", len(cfg.Env))
	}
	envVariables := make(map[string]struct{})
	for _, envVar := range cfg.Env {
		envVariables[envVar] = struct{}{}
	}
	expectKey("ECS_DATADIR=/data", envVariables, t)
	expectKey("ECS_LOGFILE=/log/"+config.AgentLogFile, envVariables, t)
	expectKey("ECS_AGENT_CONFIG_FILE_PATH="+config.AgentJSONConfigFile(), envVariables, t)
	expectKey("ECS_UPDATE_DOWNLOAD_DIR="+config.CacheDirectory(), envVariables, t)
	expectKey("ECS_UPDATES_ENABLED=true", envVariables, t)
	expectKey(`ECS_AVAILABLE_LOGGING_DRIVERS=["json-file","syslog","awslogs"]`, envVariables, t)

	if len(cfg.ExposedPorts) != 1 {
		t.Errorf("Expected exactly 1 element to be in ExposedPorts, but was %d", len(cfg.ExposedPorts))
	}
	expectPort("51678/tcp", cfg.ExposedPorts, t)

	if cfg.Image != config.AgentImageName {
		t.Errorf("Expected image to be %s", config.AgentImageName)
	}

	hostCfg := opts.HostConfig

	if len(hostCfg.Binds) != 5 {
		t.Errorf("Expected exactly 5 elements to be in Binds, but was %d", len(hostCfg.Binds))
	}
	binds := make(map[string]struct{})
	for _, binding := range hostCfg.Binds {
		binds[binding] = struct{}{}
	}
	defaultDockerSocket, _ := config.DockerUnixSocket()
	expectKey(defaultDockerSocket+":"+defaultDockerSocket, binds, t)
	expectKey(config.LogDirectory()+":/log", binds, t)
	expectKey(config.AgentDataDirectory()+":/data", binds, t)
	expectKey(config.AgentConfigDirectory()+":"+config.AgentConfigDirectory(), binds, t)
	expectKey(config.CacheDirectory()+":"+config.CacheDirectory(), binds, t)

	if len(hostCfg.PortBindings) != 1 {
		t.Errorf("Expected exactly 1 element to be in PortBindings, but was %d", len(hostCfg.PortBindings))
	}
	if portBindings, ok := hostCfg.PortBindings["51678/tcp"]; ok {
		if len(portBindings) != 1 {
			t.Errorf("Expected exactly 1 element to be in portBindings, but was %d", len(portBindings))
		} else {
			portBinding := portBindings[0]
			if portBinding.HostIP != "127.0.0.1" {
				t.Errorf("Expected HostIP to be 127.0.0.1, but was %s", portBinding.HostIP)
			}
			if portBinding.HostPort != "51678" {
				t.Errorf("Expected HostPort to be 51678, but was %s", portBinding.HostPort)
			}
		}
	} else {
		t.Error("Expected 51678/tcp to be defined")
	}
}