feat/fetch-definition-from-remote #6
3 changed files with 26 additions and 22 deletions
|
@ -49,10 +49,10 @@ func getStartCommand() *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
flags := ctx.Value("flags").(ParsedFlags)
|
flags := ctx.Value("flags").(ParsedFlags)
|
||||||
def, err := service_definition.GetServiceDefinitionFromFile(flags.definitionPath)
|
def, err := service_definition.GetServiceDefinition(flags.definitionPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to read service definition from file: %+v", err)
|
return fmt.Errorf("Failed to read service definition: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.daemonHost != "" && flags.daemonPort != 0 {
|
if flags.daemonHost != "" && flags.daemonPort != 0 {
|
||||||
|
|
22
service_definition/fetcher.go
Normal file
22
service_definition/fetcher.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package service_definition
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/goccy/go-yaml"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) {
|
||||||
|
var definition ServiceDefinition
|
||||||
|
|
||||||
|
defData, err := os.ReadFile(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ServiceDefinition{}, &FileDoesNotExistError{Message: "Could not find service configuration file", ExpectedPath: path}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = yaml.Unmarshal(defData, &definition); err != nil {
|
||||||
|
return ServiceDefinition{}, &InvalidServiceDefinitionError{Path: path}
|
||||||
|
}
|
||||||
|
|
||||||
|
return definition, nil
|
||||||
|
}
|
|
@ -1,11 +1,5 @@
|
||||||
package service_definition
|
package service_definition
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/goccy/go-yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BuildImage struct {
|
type BuildImage struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
TagPrefix string `yaml:"tag"`
|
TagPrefix string `yaml:"tag"`
|
||||||
|
@ -50,18 +44,6 @@ type ServiceDefinition struct {
|
||||||
Ports []PortMapping `yaml:"ports"`
|
Ports []PortMapping `yaml:"ports"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetServiceDefinitionFromFile(path string) (ServiceDefinition, error) {
|
func GetServiceDefinition(path string) (ServiceDefinition, error) {
|
||||||
var definition ServiceDefinition
|
return GetServiceDefinitionFromFile(path)
|
||||||
|
|
||||||
defData, err := os.ReadFile(path)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ServiceDefinition{}, &FileDoesNotExistError{Message: "Could not find service configuration file", ExpectedPath: path}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = yaml.Unmarshal(defData, &definition); err != nil {
|
|
||||||
return ServiceDefinition{}, &InvalidServiceDefinitionError{Path: path}
|
|
||||||
}
|
|
||||||
|
|
||||||
return definition, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue