diff --git a/podman/main.go b/podman/main.go index 8bd07a7..050e894 100644 --- a/podman/main.go +++ b/podman/main.go @@ -4,7 +4,7 @@ import ( "log" "os/exec" - "spud/service_definition" + service_definition "spud/service_definition" ) /* @@ -38,8 +38,15 @@ func CreateVolume(name string, existsOk bool) error { * Creates a Podman pod to keep related containers together. * */ -func CreatePod(name string) error { - args := []string{"pod", "create", "--replace", name} +func CreatePod(name string, ports []service_definition.PortMapping) error { + args := []string{"pod", "create", "--replace"} + + for _, portMapping := range ports { + portArgs := []string{"-p", portMapping.Host + ":" + portMapping.Container} + args = append(args, portArgs...) + } + + args = append(args, name) command := exec.Command("podman", args...) diff --git a/service/service.go b/service/service.go index 2a3100f..708978b 100644 --- a/service/service.go +++ b/service/service.go @@ -10,7 +10,7 @@ import ( func CreateService(definition service_definition.ServiceDefinition) { var err error - err = podman.CreatePod(definition.Name) + err = podman.CreatePod(definition.Name, definition.Ports) if err != nil { log.Fatalf("%s", err) diff --git a/service_definition/main.go b/service_definition/main.go index a3afa1f..f69084b 100644 --- a/service_definition/main.go +++ b/service_definition/main.go @@ -10,6 +10,12 @@ type VolumeDefinition struct { Name string `yaml:"name"` } +type PortMapping struct { + Host string `yaml:"host"` + Container string `yaml:"container"` + Type string `yaml:"type"` +} + type VolumeConfiguration struct { Name string `yaml:"name"` Container string `yaml:"container"` @@ -27,6 +33,7 @@ type ServiceDefinition struct { Name string `yaml:"name"` Volumes []VolumeDefinition `yaml:"volumes"` Containers []ContainerDefinition `yaml:"containers"` + Ports []PortMapping `yaml:"ports"` } func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) {