func convertToContainerConfig()

in ecs-cli/modules/cli/compose/project/project_parseV3.go [94:221]


func convertToContainerConfig(serviceConfig types.ServiceConfig, serviceVols *adapter.Volumes) (*adapter.ContainerConfig, error) {
	logger.LogUnsupportedV3ServiceConfigFields(serviceConfig)
	logWarningForDeployFields(serviceConfig.Deploy, serviceConfig.Name)

	var stopTimeout *int64
	if serviceConfig.StopGracePeriod != nil {
		st := (int64)(serviceConfig.StopGracePeriod.Seconds())
		stopTimeout = &st
	}

	c := &adapter.ContainerConfig{
		CapAdd:                serviceConfig.CapAdd,
		CapDrop:               serviceConfig.CapDrop,
		Command:               serviceConfig.Command,
		DockerSecurityOptions: serviceConfig.SecurityOpt,
		Entrypoint:            serviceConfig.Entrypoint,
		Hostname:              serviceConfig.Hostname,
		Image:                 serviceConfig.Image,
		Links:                 serviceConfig.Links,
		Name:                  serviceConfig.Name,
		Privileged:            serviceConfig.Privileged,
		PseudoTerminal:        serviceConfig.Tty,
		ReadOnly:              serviceConfig.ReadOnly,
		StopTimeout:           stopTimeout,
		User:                  serviceConfig.User,
		WorkingDirectory:      serviceConfig.WorkingDir,
	}

	devices, err := adapter.ConvertToDevices(serviceConfig.Devices)
	if err != nil {
		return nil, err
	}
	c.Devices = devices

	if serviceConfig.HealthCheck != nil && !serviceConfig.HealthCheck.Disable {
		c.HealthCheck = adapter.ConvertToHealthCheck(serviceConfig.HealthCheck)
	}

	if serviceConfig.DNS != nil {
		c.DNSServers = serviceConfig.DNS
	}
	if serviceConfig.DNSSearch != nil {
		c.DNSSearchDomains = serviceConfig.DNSSearch
	}
	if serviceConfig.Labels != nil {
		labelsMap := aws.StringMap(serviceConfig.Labels)
		c.DockerLabels = labelsMap
	}

	envVars := []*ecs.KeyValuePair{}
	for k, v := range serviceConfig.Environment {
		env := ecs.KeyValuePair{}
		env.SetName(k)
		if v != nil {
			env.SetValue(*v)
		} else {
			env.SetValue("")
		}
		envVars = append(envVars, &env)
	}
	c.Environment = envVars

	extraHosts, err := adapter.ConvertToExtraHosts(serviceConfig.ExtraHosts)
	if err != nil {
		return nil, err
	}
	c.ExtraHosts = extraHosts

	// TODO: refactor adapter.ConvertToLogConfiguration to take in driver (string) and Options (map[string]string)
	if serviceConfig.Logging != nil {
		logConfig := ecs.LogConfiguration{}
		logConfig.SetLogDriver(serviceConfig.Logging.Driver)

		optionsMap := aws.StringMap(serviceConfig.Logging.Options)
		logConfig.SetOptions(optionsMap)
		c.LogConfiguration = &logConfig
	}

	if len(serviceConfig.Ports) > 0 {
		var portMappings []*ecs.PortMapping
		for _, portConfig := range serviceConfig.Ports {
			mapping := convertPortConfigToECSMapping(portConfig)
			portMappings = append(portMappings, mapping)
		}
		c.PortMappings = portMappings
	}
	// TODO: change ConvertToTmpfs to take in []string
	if serviceConfig.Tmpfs != nil {
		tmpfs := yaml.Stringorslice(serviceConfig.Tmpfs)
		ecsTmpfs, err := adapter.ConvertToTmpfs(tmpfs)
		if err != nil {
			return nil, err
		}
		c.Tmpfs = ecsTmpfs
	}

	if len(serviceConfig.Ulimits) > 0 {
		c.Ulimits = convertToECSUlimits(serviceConfig.Ulimits)
	}

	if len(serviceConfig.Volumes) > 0 {
		mountPoints := []*ecs.MountPoint{}

		for _, volConfig := range serviceConfig.Volumes {
			if volConfig.Type == "volume" || volConfig.Type == "bind" {

				sourceVolName, err := adapter.GetSourcePathAndUpdateVolumes(volConfig.Source, serviceVols)
				if err != nil {
					return nil, err
				}
				containerPath := volConfig.Target
				readOnly := volConfig.ReadOnly

				mp := &ecs.MountPoint{
					ContainerPath: &containerPath,
					SourceVolume:  &sourceVolName,
					ReadOnly:      &readOnly,
				}
				mountPoints = append(mountPoints, mp)
			} else {
				log.Warnf("Unsupported mount type found: %s", volConfig.Type)
			}
		}
		c.MountPoints = mountPoints
	}

	return c, nil
}