package service import ( podman "spud/podman" service_definition "spud/service_definition" ) type ServiceManager interface { Create(definition service_definition.ServiceDefinition) Stop(name string) } type PodmanServiceManager struct{} func NewPodmanServiceManager() *PodmanServiceManager { return &PodmanServiceManager{} } func (c PodmanServiceManager) Create(definition service_definition.ServiceDefinition) error { var err error err = podman.CreatePod(definition.Name, definition.Ports) if err != nil { return err } knownVolumes := map[string]string{} for _, volume := range definition.Volumes { namespacedName := definition.Name + "_" + volume.Name podman.CreateVolume(namespacedName, true) knownVolumes[volume.Name] = namespacedName } for _, container := range definition.Containers { if err = podman.CreateContainer(container, knownVolumes, definition.Name); err != nil { return err } } return nil } /* * Stops a running service. * * The service and all its containers are stopped but not deleted. */ func (c PodmanServiceManager) Stop(name string) error { return podman.StopPod(name) }