Fix envfile detection
+ The envfiles were not added! see #8 TODO: what are the others properties to fix this way?
This commit is contained in:
@@ -59,6 +59,7 @@ func (p *Parser) Parse(appname string) {
|
||||
for _, s := range p.Data.Services {
|
||||
parseEnv(s)
|
||||
parseCommand(s)
|
||||
parseEnvFiles(s)
|
||||
}
|
||||
|
||||
c := p.Data
|
||||
@@ -143,7 +144,8 @@ func parseEnv(s *Service) {
|
||||
env = s.RawEnvironment.(map[string]string)
|
||||
case map[string]interface{}:
|
||||
for k, v := range s.RawEnvironment.(map[string]interface{}) {
|
||||
env[k] = v.(string)
|
||||
// force to string
|
||||
env[k] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
case []interface{}:
|
||||
for _, v := range s.RawEnvironment.([]interface{}) {
|
||||
@@ -156,7 +158,6 @@ func parseEnv(s *Service) {
|
||||
env[parts[0]] = parts[1]
|
||||
default:
|
||||
log.Printf("%+v, %T", s.RawEnvironment, s.RawEnvironment)
|
||||
log.Printf("%+v", s)
|
||||
log.Fatal("Environment type not supported")
|
||||
}
|
||||
s.Environment = env
|
||||
@@ -188,3 +189,23 @@ func parseCommand(s *Service) {
|
||||
log.Fatal("Command type not supported")
|
||||
}
|
||||
}
|
||||
|
||||
func parseEnvFiles(s *Service) {
|
||||
// Same than parseEnv, but for env files
|
||||
if s.RawEnvFiles == nil {
|
||||
return
|
||||
}
|
||||
envfiles := make([]string, 0)
|
||||
switch s.RawEnvFiles.(type) {
|
||||
case []string:
|
||||
envfiles = s.RawEnvFiles.([]string)
|
||||
case []interface{}:
|
||||
for _, v := range s.RawEnvFiles.([]interface{}) {
|
||||
envfiles = append(envfiles, v.(string))
|
||||
}
|
||||
default:
|
||||
log.Printf("%+v %T", s.RawEnvFiles, s.RawEnvFiles)
|
||||
log.Fatal("EnvFile type not supported")
|
||||
}
|
||||
s.EnvFiles = envfiles
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package compose
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"katenary/logger"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const DOCKER_COMPOSE_YML1 = `
|
||||
version: "3"
|
||||
@@ -29,8 +32,20 @@ services:
|
||||
labels:
|
||||
katenary.io/ports: "5432"
|
||||
|
||||
commander1:
|
||||
image: foo
|
||||
command: ["/bin/sh", "-c", "echo 'hello world'"]
|
||||
|
||||
commander2:
|
||||
image: foo
|
||||
command: echo "hello world"
|
||||
|
||||
`
|
||||
|
||||
func init() {
|
||||
logger.NOLOG = true
|
||||
}
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
p := NewParser("", DOCKER_COMPOSE_YML1)
|
||||
p.Parse("test")
|
||||
@@ -85,5 +100,39 @@ func TestParser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestParseCommand(t *testing.T) {
|
||||
p := NewParser("", DOCKER_COMPOSE_YML1)
|
||||
p.Parse("test")
|
||||
|
||||
for name, s := range p.Data.Services {
|
||||
if name == "commander1" {
|
||||
t.Log(s.Command)
|
||||
if len(s.Command) != 3 {
|
||||
t.Errorf("Expected 3 command, got %d", len(s.Command))
|
||||
}
|
||||
if s.Command[0] != "/bin/sh" {
|
||||
t.Errorf("Expected /bin/sh, got %s", s.Command[0])
|
||||
}
|
||||
if s.Command[1] != "-c" {
|
||||
t.Errorf("Expected -c, got %s", s.Command[1])
|
||||
}
|
||||
if s.Command[2] != "echo 'hello world'" {
|
||||
t.Errorf("Expected echo 'hello world', got %s", s.Command[2])
|
||||
}
|
||||
}
|
||||
if name == "commander2" {
|
||||
t.Log(s.Command)
|
||||
if len(s.Command) != 2 {
|
||||
t.Errorf("Expected 1 command, got %d", len(s.Command))
|
||||
}
|
||||
if s.Command[0] != "echo" {
|
||||
t.Errorf("Expected echo, got %s", s.Command[0])
|
||||
}
|
||||
if s.Command[1] != "hello world" {
|
||||
t.Errorf("Expected hello world, got %s", s.Command[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,8 +34,10 @@ type Service struct {
|
||||
DependsOn []string `yaml:"depends_on"`
|
||||
Volumes []string `yaml:"volumes"`
|
||||
Expose []int `yaml:"expose"`
|
||||
EnvFiles []string `yaml:"env_file"`
|
||||
EnvFiles []string `yaml:"-"`
|
||||
RawEnvFiles interface{} `yaml:"env_file"`
|
||||
RawBuild interface{} `yaml:"build"`
|
||||
HealthCheck *HealthCheck `yaml:"healthcheck"`
|
||||
Command []string `yaml:"command"`
|
||||
Command []string `yaml:"-"`
|
||||
RawCommand interface{} `yaml:"command"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user