feat: add port mappings to service definition
This commit is contained in:
parent
e51648801f
commit
c843d35ae5
3 changed files with 18 additions and 4 deletions
|
@ -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...)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue