feat: add port mappings to service definition

This commit is contained in:
Marc 2024-06-02 23:49:37 -04:00
parent e51648801f
commit c843d35ae5
Signed by: marc
GPG key ID: 048E042F22B5DC79
3 changed files with 18 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import (
"log" "log"
"os/exec" "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. * Creates a Podman pod to keep related containers together.
* *
*/ */
func CreatePod(name string) error { func CreatePod(name string, ports []service_definition.PortMapping) error {
args := []string{"pod", "create", "--replace", name} 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...) command := exec.Command("podman", args...)

View file

@ -10,7 +10,7 @@ import (
func CreateService(definition service_definition.ServiceDefinition) { func CreateService(definition service_definition.ServiceDefinition) {
var err error var err error
err = podman.CreatePod(definition.Name) err = podman.CreatePod(definition.Name, definition.Ports)
if err != nil { if err != nil {
log.Fatalf("%s", err) log.Fatalf("%s", err)

View file

@ -10,6 +10,12 @@ type VolumeDefinition struct {
Name string `yaml:"name"` Name string `yaml:"name"`
} }
type PortMapping struct {
Host string `yaml:"host"`
Container string `yaml:"container"`
Type string `yaml:"type"`
}
type VolumeConfiguration struct { type VolumeConfiguration struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Container string `yaml:"container"` Container string `yaml:"container"`
@ -27,6 +33,7 @@ type ServiceDefinition struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Volumes []VolumeDefinition `yaml:"volumes"` Volumes []VolumeDefinition `yaml:"volumes"`
Containers []ContainerDefinition `yaml:"containers"` Containers []ContainerDefinition `yaml:"containers"`
Ports []PortMapping `yaml:"ports"`
} }
func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) { func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) {