in executors/kubernetes/kubernetes.go [1322:1382]
func (s *executor) buildContainer(opts containerBuildOpts) (api.Container, error) {
var envVars []common.JobVariable
if opts.isServiceContainer {
envVars = s.getServiceVariables(opts.imageDefinition)
} else if opts.name == buildContainerName {
envVars = s.Build.GetAllVariables().PublicOrInternal()
}
err := s.verifyAllowedImages(opts)
if err != nil {
return api.Container{}, err
}
containerPorts := make([]api.ContainerPort, len(opts.imageDefinition.Ports))
proxyPorts := make([]proxy.Port, len(opts.imageDefinition.Ports))
for i, port := range opts.imageDefinition.Ports {
proxyPorts[i] = proxy.Port{Name: port.Name, Number: port.Number, Protocol: port.Protocol}
containerPorts[i] = api.ContainerPort{ContainerPort: int32(port.Number)}
}
if len(proxyPorts) > 0 {
aliases := opts.imageDefinition.Aliases()
if len(aliases) == 0 {
if opts.name != buildContainerName {
aliases = []string{fmt.Sprintf("proxy-%s", opts.name)}
} else {
aliases = []string{opts.name}
}
}
for _, serviceName := range aliases {
s.ProxyPool[serviceName] = s.newProxy(serviceName, proxyPorts)
}
}
pullPolicy, err := s.pullManager.GetPullPolicyFor(opts.name)
if err != nil {
return api.Container{}, err
}
command, args := s.getCommandAndArgs(opts.imageDefinition, opts.command...)
container := api.Container{
Name: opts.name,
Image: opts.image,
ImagePullPolicy: pullPolicy,
Command: command,
Args: args,
Env: buildVariables(envVars),
Resources: api.ResourceRequirements{Limits: opts.limits, Requests: opts.requests},
Ports: containerPorts,
VolumeMounts: s.getVolumeMounts(),
SecurityContext: opts.securityContext,
Lifecycle: s.prepareLifecycleHooks(),
Stdin: true,
}
return container, nil
}