Browse code

Add support for extra_hosts in composefile v3

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/11/11 22:19:41
Showing 1 changed files
... ...
@@ -498,6 +498,7 @@ func convertService(
498 498
 				Command:         service.Entrypoint,
499 499
 				Args:            service.Command,
500 500
 				Hostname:        service.Hostname,
501
+				Hosts:           convertExtraHosts(service.ExtraHosts),
501 502
 				Env:             convertEnvironment(service.Environment),
502 503
 				Labels:          getStackLabels(namespace.name, service.Labels),
503 504
 				Dir:             service.WorkingDir,
... ...
@@ -521,6 +522,14 @@ func convertService(
521 521
 	return serviceSpec, nil
522 522
 }
523 523
 
524
+func convertExtraHosts(extraHosts map[string]string) []string {
525
+	hosts := []string{}
526
+	for host, ip := range extraHosts {
527
+		hosts = append(hosts, fmt.Sprintf("%s %s", host, ip))
528
+	}
529
+	return hosts
530
+}
531
+
524 532
 func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*swarm.RestartPolicy, error) {
525 533
 	// TODO: log if restart is being ignored
526 534
 	if source == nil {