2024-06-02 06:03:47 +00:00
|
|
|
package service_definition
|
2024-06-02 05:21:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-06-02 06:03:47 +00:00
|
|
|
|
|
|
|
"github.com/goccy/go-yaml"
|
2024-06-02 05:21:25 +00:00
|
|
|
)
|
|
|
|
|
2024-09-27 03:29:52 +00:00
|
|
|
type BuildImage struct {
|
|
|
|
Path string `yaml:"path"`
|
|
|
|
TagPrefix string `yaml:"tag"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type BuildConfiguration struct {
|
|
|
|
Images []BuildImage
|
|
|
|
}
|
|
|
|
|
2024-06-02 05:21:25 +00:00
|
|
|
type VolumeDefinition struct {
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
}
|
|
|
|
|
2024-06-03 03:49:37 +00:00
|
|
|
type PortMapping struct {
|
|
|
|
Host string `yaml:"host"`
|
|
|
|
Container string `yaml:"container"`
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
}
|
|
|
|
|
2024-06-02 05:21:25 +00:00
|
|
|
type VolumeConfiguration struct {
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Container string `yaml:"container"`
|
|
|
|
Host string `yaml:"host"`
|
2024-06-09 04:23:53 +00:00
|
|
|
ReadOnly bool `yaml:"readonly"`
|
2024-06-02 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerDefinition struct {
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Image string `yaml:"image"`
|
|
|
|
Volumes []VolumeConfiguration `yaml:"volumes"`
|
2024-07-07 01:15:02 +00:00
|
|
|
EnvFile string `yaml:"env-file"`
|
2024-06-02 05:21:25 +00:00
|
|
|
ExtraArgs []string `yaml:"extra-args"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServiceDefinition struct {
|
|
|
|
Name string `yaml:"name"`
|
2024-09-27 03:29:52 +00:00
|
|
|
Build BuildConfiguration `yaml:"build"`
|
2024-06-02 05:21:25 +00:00
|
|
|
Volumes []VolumeDefinition `yaml:"volumes"`
|
|
|
|
Containers []ContainerDefinition `yaml:"containers"`
|
2024-06-03 03:49:37 +00:00
|
|
|
Ports []PortMapping `yaml:"ports"`
|
2024-06-02 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2024-06-02 06:03:47 +00:00
|
|
|
func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) {
|
2024-06-02 05:21:25 +00:00
|
|
|
var definition ServiceDefinition
|
|
|
|
|
|
|
|
defData, err := os.ReadFile(path)
|
|
|
|
|
|
|
|
if err != nil {
|
2024-06-02 06:03:47 +00:00
|
|
|
return ServiceDefinition{}, &FileDoesNotExistError{Message: "Could not find service configuration file", ExpectedPath: path}
|
2024-06-02 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = yaml.Unmarshal(defData, &definition); err != nil {
|
2024-06-02 06:03:47 +00:00
|
|
|
return ServiceDefinition{}, &InvalidServiceDefinitionError{Path: path}
|
2024-06-02 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2024-06-02 06:03:47 +00:00
|
|
|
return definition, nil
|
2024-06-02 05:21:25 +00:00
|
|
|
}
|